Files
ctf/2025/lake/misc/zipbomb/unpack.py
2026-06-12 05:09:39 +02:00

26 lines
673 B
Python

import zipfile
import os
import shutil
import glob
def unzip_all(src, out="data"):
shutil.rmtree(out, ignore_errors=True)
os.mkdir(out)
shutil.copy(src, f"{out}/bomb.zip")
layer = 0
while zips := glob.glob(f"{out}/*.zip"):
z = zips[0]
with zipfile.ZipFile(z) as f:
names = f.namelist()
f.extractall(out)
os.remove(z)
for n in names:
p = os.path.join(out, n)
if not n.endswith(".zip") and "flag" not in n and os.path.isfile(p):
os.remove(p)
layer += 1
print(f"Done after {layer} layers.")
if __name__ == "__main__":
unzip_all("./bomb.zip")