Skip to content

Latest commit

 

History

History
50 lines (27 loc) · 9.45 KB

ARTICLE.md

File metadata and controls

50 lines (27 loc) · 9.45 KB

Why php2shell Chains Survive php -S and Collapse Behind FPM and a Proxy

English · Español

Public php2shell demonstrations look reliable against a persistent PHP server and fail behind a reverse proxy and PHP-FPM. Measurements across php:8.4.26-apache, php:8.4.26-fpm, and multi-worker setups reveal an architectural gap, not a timing fluke. Three mechanisms determine whether an out-of-memory (OOM) bailout yields code execution or collapses into HTTP 502 errors and clean responses: proxy buffering with KeepAlive On, PHP-FPM crash isolation (exit 70) paired with FastCGI output-contract separation, and the boundary between EG(objects_store) headers, object_buckets, and ASLR entropy.

Persistent workers versus FPM behind a proxy

Request-startup OOM primitives (CVE-2026-109618 and CVE-2026-109619) require worker state to outlive an aborted request (COVERAGE.md §§1–2). Persistent workers—Apache mod_php prefork or the CLI server (php -S)—survive a startup OOM (raw/chain-d-eg-shutdown.txt), letting a follow-up request on that worker read residual heap or session state (PORTABILITY.md; COVERAGE.md §§1, 5).

PHP-FPM behind Nginx breaks that condition at the proxy, process, and allocator layers.

1. KeepAlive On and proxy buffering break worker pairing

Uncoordinated OOM chains fail on multi-worker pools because the follow-up request hits a different child. In PORTABILITY.md, php:8.4.26-apache (memory_limit=8M, display_errors=On, 4 workers) without saturation yields 0/3 and zero aborts. Holding N-1 workers busy with slow connections restores pairing: 6/6 PROOF at 4 workers (24 aborts), 4/4 PROOF at 8 workers (16 aborts), and 3/3 PROOF at 16 workers (12 aborts) (PORTABILITY.md, item 3).

Placing Nginx in front of 4 workers exposes two non-PHP gates that sever pairing:

  • Proxy buffering (0/1): With Nginx buffering off and 64 KB trickle delivery, the chain hits 3/3 PROOF (12 aborts) (PORTABILITY.md, table and item 4). Enabling proxy buffering on drops success to 0/1 (PORTABILITY.md). Buffering absorbs the incoming request body before forwarding, so the connection never pins the backend worker in the state OOM pairing needs (PORTABILITY.md, item 4). That measured mechanism operates on incoming connection state; attributing 0/1 to response reassembly lacks backing in the captures and remains an unmeasured hypothesis.
  • KeepAlive On (0/5): Enabling KeepAlive On against the 4-worker profile fails 0/5 despite 20 aborts (PORTABILITY.md, table and item 5). Persistent HTTP connections alter dispatch across consecutive requests, keeping the follow-up request off the corrupted worker. PORTABILITY.md notes KeepAlive On as the matrix's cheapest mitigation because it lives outside PHP.

Body limits also gate reachability. When Content-Length is present, post_max_size—not memory_limit—gates OOM: at 512M memory limit, a 12 MB field fails 0/3 (0 aborts) while a 480 MB field reaches 1/1 PROOF (4 aborts) (PORTABILITY.md, item 1). Unpatched mod_php bypasses post_max_size on chunked bodies, letting a 70 MB chunked request trigger startup OOM under 128M/8M defaults (raw/chain-d-eg-shutdown.txt; COVERAGE.md §1). FPM rejects chunked bodies without CONTENT_LENGTH, and Nginx enforces its body limit upstream (COVERAGE.md §1).

2. FPM crash isolation (exit 70) and output separation

Once traffic reaches PHP-FPM, process isolation and the FastCGI output contract cut off both the leak channel and synchronous output.

Persistent SAPIs (php -S and mod_php) return HTTP 500 or an altered Set-Cookie header after OOM while keeping the worker alive (raw/chain-d-eg-shutdown.txt; raw/rce-on-aslr-on-8426.txt). On PHP-FPM 8.4.26, a startup OOM with an upload-progress field kills the child: logs record child exited with code 70, and Nginx serves HTTP 502 (raw/fpm-chain-e-8426.txt). Destroying the worker wipes the stale session identifier before a replacement spawns with a clean zend_mm_heap, closing the in-band cookie leak (COVERAGE.md §§1, 6).

The decode-path OOM variant (CVE-2026-109619, Chain E) can survive inside a single FPM worker when a large session decode exhausts memory and leaves BG(unserialize) at level=1 with a dangling pointer (raw/fpm-chain-e-8426.txt; CHAIN-E.md). Still, FastCGI isolation blocks remote execution through two barriers:

  1. Free-list corruption on reuse: In the default FPM path (raw/fpm-chain-e-encoding-8426.txt), Zend MM recycles the freed 12 KB run into bin 16 and writes an encoded (bswap) free-list pointer over used_slots. The next decode reads that pointer as an index, faults with SIGSEGV in var_push, and crashes with 502 (CHAIN-E.md; COVERAGE.md §6).
  2. SAPI output-contract desynchronization: In the lab-only controlled overwrite of sapi_module.ub_write (raw/fpm-rce-ub-write.txt; CHAIN-E.md §"The post-exec desynchronisation"), replacing the output hook with system() breaks PHP's contract. PHP expects written byte count; system() returns subshell exit status (rax = 0). The SAPI layer treats zero bytes as an aborted connection, calls php_handle_aborted_connection, and returns 502 through Nginx (CHAIN-E.md). Unlike php -S chains that scan file descriptors to write stdout to the HTTP socket (COVERAGE.md §5), FPM terminates the stream and forces background decoupling (CHAIN-E.md).

3. The EG(objects_store) myth, object_buckets, and the 387-iteration sweep

A common Chain D narrative claims aborted startup leaves a stale EG(objects_store) for the next request. CHAIN-D.md measured php_request_shutdown on php:8.4.26-apache (mod_php, prefork, 128M, one worker) across a warmup GET (200), a 70 MB chunked startup OOM (500), and a follow-up GET (200) (raw/chain-d-eg-shutdown.txt). Across all three shutdowns, the store pointer, next-free slot (top=1, handle 0 reserved), capacity (1024), free-list head (-1), initial bucket entries (zero), current_execute_data, and vm_stack bounds were identical (raw/chain-d-eg-shutdown.txt; CHAIN-D.md). The stale store-header claim fails (CHAIN-D.md; COVERAGE.md §2).

CHAIN-D.md separates the store header from the object_buckets array. Because raw/chain-d-eg-shutdown.txt inspected only the header and initial entries on an empty store, it leaves object_buckets reuse open. External work cited in CHAIN-D.md (segfo, cookie-bakery, and the patch resetting object_buckets at shutdown) points to object_buckets use-after-free—functional with ASLR off and dependent on a leak for ASLR on (CHAIN-D.md). As a hypothesis, object_buckets corruption stays plausible on persistent workers with a leak, whereas FPM's exit 70 crash and bin-16 churn prevent cross-request reuse.

This distinction clarifies raw/chain-e-aslr-sweep-387.txt. Contrary to summaries tying it to object_buckets or an ASLR-on/ASLR-off comparison, raw/chain-e-aslr-sweep-387.txt audits Chain E's aslr_sweep module on phpdebug:8.4.26-fpm (pm = static, one worker, behind Nginx) with ASLR active (randomize_va_space = 2) (CHAIN-E.md §"The sweep, measured"). It sends plain form values without a forged multipart body or address arithmetic (raw/chain-e-aslr-sweep-387.txt). Its default check falsely matches "OK" on page 0 in 0.01 s. Requiring command output (uid= and gid=), 387 iterations return 387 HTTP 200 responses, 0 hits, and 0 crashes in 0.34 s (raw/chain-e-aslr-sweep-387.txt; CHAIN-E.md).

Chain E succeeds in the lab with ASLR off (raw/fpm-rce-ub-write.txt) because fixed bases let a 16-byte-aligned fake destructor walk—with a locally planted 24-byte session—overwrite sapi_module.ub_write (CHAIN-E.md; COVERAGE.md §§1, 6). With ASLR on, bin-16 fragmentation and unknown bases yield a 502 DoS (raw/fpm-chain-e-encoding-8426.txt), with no sweep to bypass it (CHAIN-E.md). Even on persistent mod_php (display_errors=Off, ASLR on), reliability tracks stock 128M calibration: the upstream pure/ chain hits 10/10 (raw/9bie-pure-off-aslr-on-10run.txt), while the older 9bie chain scores 0/3 (raw/9bie-display-off-3run.txt) and 8M profiles fail 0/3 (PORTABILITY.md; COVERAGE.md §6).

Vendor fixes

PHP 8.4.27 (8.2.35, 8.3.36, 8.5.12) closes the OOM/state-corruption class across mod_php (0/5 in raw/ctl-8427.txt; 0/3 across fixed branches in raw/fixed-branches-verify.txt) and FPM (200 stable in raw/fpm-chain-e-8426.txt). Releases 8.2.36, 8.3.37, 8.4.28, 8.5.13, and 8.6.0 patch CVE-2026-115560 (COVERAGE.md §§1, 3).

Ethical scope

All measurements ran in disposable loopback lab containers for defensive verification, never against production hosts. Do not apply these techniques without explicit written authorization; consult SECURITY.md for disclosure and responsible-use rules.