Skip to content
RCE Write-up Advanced

PHP2Shell: A tale of two PHP remote vulnerabilities

PHP leaves dangling pointers and stale interpreter state when an allocation exceeds memory_limit or another fatal interrupts native code before cleanup. An attacker can trigger this with crafted multipart requests and then consume the stale state in a surviving Apache mod_php or PHP-FPM worker, leading to memory disclosure and remote code execution.

calif.io

Published on calif.io

Covered by The Wall Street Journal and The New York Times

The author, on calif.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the interpreter publishes or increments state (hash bucket counts, session globals, unserializer bookkeeping) before fallible allocations, so a fatal error skips the matching cleanup and teardown later trusts the stale state.

Impact

The authors report pre-authentication remote code execution against many popular PHP applications under default configurations, although the PHP-FPM path depends on the application exposing a reachable decoding operation.

What the attacker needed

PHP >= 5.4.0 (mod_php) or >= 7.3; Apache mod_php or PHP-FPM; Attacker can send crafted multipart requests; For FPM: app calls session_start/unserialize

The fix

It was fixed in the PHP October 2026 security release, which addressed both CVEs.

How it was found

  1. Send a multipart request that bypasses post_max_size, for example with chunked encoding or many empty nested file-upload fields, to force an out-of-memory fatal.
  2. Let the fatal interrupt a point such as hash bucket insertion, early session initialisation during upload progress, or the unserializer, so cleanup is skipped.
  3. On mod_php the worker survives with stale globals; on PHP-FPM a post-startup fatal leaves the worker alive with abandoned decoder state.
  4. Send a second multipart request without a file part so upload progress reaches the stale session or unserializer state before it is reset.
  5. Reclaim the freed memory with request data and use the stale reference and destructor lists to leak memory or place a controlled value.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

PHP normally frees memory and tidies up after each web request. If a request is deliberately made to run out of memory at just the wrong moment, some internal pointers are left pointing at memory that has already been freed. A later request can then reuse that leftover memory, which lets an attacker read data or run their own code.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.