Zip-a-dee-doo-dah
rtcp{z1pPeD_4_c0uPl3_t00_M4Ny_t1m3s_a1b8c687}
import os, zipfile
wordlist = []
with open("/home/isaac/CTFs/houseplant/wordlist.txt", 'r') as f:
data = f.read()
wordlist = data.split('\n')
def gunzip(filename):
if "gz" not in filename:
os.system(f"mv {filename} {filename}.gz")
filename = filename + ".gz"
os.system(f"gunzip {filename}")
def tar(filename):
os.system(f"tar -xvf {filename}")
if len(os.listdir('.')) > 1:
os.system(f"rm {filename}")
def zipcrack(filename):
# More complicated. Must brute force password via the wordlist.
tocrack = zipfile.ZipFile(filename)
cracked = False
for password in wordlist:
pwd = password.encode()
try:
tocrack.extractall(pwd = pwd)
cracked = True
break
except:
pass
if cracked:
os.system(f"rm {filename}")
else:
raise Exception("Was not able to crack zip.")
zipheader = bytes([0x50, 0x4b, 0x03, 0x04])
gzipheader = bytes([0x1f,0x8b])
# Tar headers vary, but we know it's tar if it's not zip or gzip.
for _ in range(1816):
ourfile = os.listdir('.')[0]
# Find out whether it's gzip, tar or zip. Then open accordingly.
with open(ourfile,'rb') as check:
first = check.read(4)
if first == zipheader:
zipcrack(ourfile)
elif first[:2] == gzipheader:
gunzip(ourfile)
else:
tar(ourfile)Last updated
Was this helpful?