LAB REPORT // PHP2SHELL (CVE-2026-109618) // CUTOFF 2026-10-30 // RESEARCH MATERIAL
* PHP2SHELL / CVE-2026-109618

CVE-2026-109618 ↗ / PHP INTERPRETER / 2026-10-30

Reproducing PHP2Shell from scratch: lab notes.

PHP2Shell is not an application-level flaw: it is a bug inside the PHP interpreter itself. A fatal interruption (deterministic OOM) during multipart parsing of session.upload_progress leaves the session state dangling, enabling heap disclosure and Remote Code Execution (RCE).

// 00. EXECUTIVE SUMMARY

How difficult is it to reproduce PHP2Shell?

The public PoC works on the first attempt if the environment matches exactly, and fails bafflingly if any of six model assumptions change (SAPI, worker count, libc, offsets, transport, and output channel).

Scenario Difficulty Measured Lab Evidence
Public PoC in exact lab (Alpine, nginx, php -S ×4) Trivial 5/5, ~9 s/run, single command
Reproducing primitive A from scratch Medium 873 nested parts, 269,075 B, OOM 4096 in php_url_encode
Porting the chain to another build in the same branch Medium calibrate measures offsets and carrier; 3 branches with RCE
Porting A/B/C to mod_php (Apache) High Different A recipe, B shifted 0x700, 995-value spray
Patched version (PHP 8.4.27+) Closed ~50 MiB ceiling with array_init_singleton vs 128 MiB limit

Positive measured laboratory results: Confirmed RCE across 5 builds (cli-server Alpine 8.3.35, 8.4.26, 8.5.11; Apache mod_php 8.4.26 and 8.5.11), memory leak of 819,200 B in mod_php, and proprietary nginx chain with 5/5 reliability and 16/16 across 4 distinct routes.

// 01. VULNERABILITY ANALYSIS

The Exploitation Chain A → B → C

How forced memory exhaustion during request startup unwinds the stack while leaving global pointers to freed memory.

1.1 Attack Surface: Session Initialization Before RINIT

session.upload_progress is intended to report the progress of file uploads. Its side effect is that the Session module is initialized during request startup, before a single line of application PHP code executes. With session.auto_start=Off, this is the sole vector through which an incoming POST request can initiate a session without the script requesting it.

If the memory allocator fails inside the multipart callback, zend_bailout unwinds the request but does not perform an orderly session shutdown, leaving global pointers (ps_globals) dangling to freed heap memory.

1.2 Stage A: Inducing OOM at the Exact Location

Simply exhausting memory is insufficient: it must be exhausted inside php_session_send_cookie(), specifically on the first allocation of php_url_encode (121 B = one page). Three simultaneous conditions are required:

  1. heap->real_size == heap->limit
  2. Zero free pages across all allocated chunks.
  3. The next allocation must be the encoder itself, not a HashTable resize.

Amplification is achieved via nested multipart file parts: files[R00000] + [a] × 62 (64 nesting levels) with filename="". Each part consumes ~147 KB of heap with an amplification ratio of ~470×.

Successful State Diagnosis:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes)
If the error reports 12288 or 20480, the OOM occurred prematurely during HashTable resize and no usable state remains dangling.

1.3 Stage B: Reading Freed Memory (Heap Leak)

The subsequent request encounters PS(id) dangling. Reoccupying that heap block with a forged zend_string (controlling both len and data) causes php_url_encode to copy len bytes from data, returning raw heap memory to the attacker in the Set-Cookie header:

  • Chunk Base Leak (256 B): Chunk pointers aligned to 2 MiB boundary.
  • Code Pointer Leak (16 B): Pointer to zval_ptr_dtor to defeat ASLR.

1.4 Stage C: From zval to system() / passthru() (RCE)

Injecting a forged zend_string containing a fake HashTable whose destructor (pDestructor) points directly to the target internal function handler. The execution resolution path is:

php_session_track_init → zval_ptr_dtor → zend_reference_destroy → zend_array_destroy → zend_hash_destroy → pDestructor(cmd)

While zif_system executes the payload command, it terminates the worker process when writing the return zval. In contrast, zif_passthru (located exactly at +0x10 offset across all five measured builds) keeps the worker alive and streams clean output directly to the HTTP socket.

// 02. REAL TARGETS EVALUATED

stealmybitcoin.com & Cloudflare CTF

Measured behavior in public live challenges compared against controlled laboratory conditions.

stealmybitcoin.com

Stack: nginx + php -S 8.4.26, 4 workers, Alpine

Stage A was successfully reproduced remotely (tried to allocate 4096), confirming the dangling state.

Root Cause of Blockage in B: The id block was consistently claimed by a real parser zend_string (a form part name) with an unstable index (58 and 125). Silent touches appeared in only 2 out of 26 attempts (~1/10). Additionally, in cli-server requests initialize with mod=0, preventing the forgery of ps_files.

STATUS: Partial reproduction of Stage A achieved. The target was retired before completing B/C.

Cloudflare CTF

Stack: Apache mod_php 8.5.11 with Cloudflare WAF

WAF Bypass: The WAF inspected only the first 1 MiB of the HTTP body. By placing the upload progress variable name at byte offset 1,060,096, the request bypassed inspection cleanly.

Root Cause of Blockage in B: The application never invoked session_start(). The id landed in the highest memory chunk, while first-fit allocation prevented reaching it within the 8 MiB limit. Following ~40 large payload requests, edge rate-limiting engaged.

STATUS: WAF bypassed, OOM 4096 verified. Final exploitation blocked by edge rate-limiting.

// 03. ARTIFACTS & LABORATORY

Self-Contained PoC & Research Files

Laboratory harness and test scripts verified across Alpine and Apache architectures.

lab/nginx_poc.py (A/B/C Chain Excerpt) · Python 3 Stdlib
#!/usr/bin/env python3
"""
PHP2Shell (CVE-2026-109618) - Self-contained PoC for cli-server/nginx
Requirements: Python 3 (standard library only)
Research author: Wilson Lora Bodré (@b0dre)
"""

import sys
import socket
import urllib.parse

def craft_stage_a_payload(parts=873, nesting=62):
    """Crafts nested multipart payload to trigger exact OOM 4096 in php_url_encode"""
    boundary = "----WebKitFormBoundaryPhp2Shell2026"
    body = []
    # Generates 873 nested variables with 64 levels of array depth
    for i in range(parts):
        field_name = f"files[R{i:05d}]" + ("[a]" * nesting)
        body.append(f"--{boundary}\r\nContent-Disposition: form-data; name=\"{field_name}\"; filename=\"\"\r\n\r\n")
    body.append(f"--{boundary}--\r\n")
    return boundary, "".join(body).encode('latin-1')

print("[*] PHP2Shell Research Kit - Cutoff 2026-10-30")
print("[*] For full suite with gdb instrumentation and mod_php support, download the attached research package.")
The complete research ZIP kit includes omni.py, ap_chain.py, pipeline_ab.py, Docker containers, and gdb instrumentation logs.

Download Complete Research Archive

Package: php2shell-writeup-2026-10-30-en.zip (352 KB, 89 files)
SHA-256: ec92a115bbc151ff37d2409a32388cc77edd6b41fb7409078044f51a5e2b0934

Download .ZIP ↓