Occasionally, a vulnerability appears that shakes the foundation of the web. Just like Log4Shell did for Java back in 2021, the recently disclosed PHP2Shell (CVE-2026-109618 and CVE-2026-109619) has taken the spotlight. It targets PHP’s core engine (versions 5.4 up to 8.5) and enables unauthenticated Remote Code Execution (RCE) on servers running Apache mod_php or PHP-FPM.

The most alarming aspect? Because PHP processes these requests during its initialization phase, the attack triggers before any application-level code (like WordPress, Laravel, or custom routing) even begins to run. Security controls, filters, or routing implemented in PHP are powerless to stop it.

In this deep dive, we will analyze the inner workings of PHP2Shell, explore how memory corruption is achieved via specific HTTP multipart payloads, and discuss how to detect and defend against this threat.


Technical Overview: The Double-Edged Swords

The threat labeled "PHP2Shell" is actually a tandem exploit involving two related CVEs, both carrying a critical CVSS score of 9.2:

  • CVE-2026-109618 (Memory Corruption / Out of Memory): Triggered when a request forces PHP to hit its memory_limit during multipart data initialization. The fatal OOM (Out of Memory) interruption occurs when PHP is half-done initializing its data structures, leaving behind uninitialized pointers during cleanup.
  • CVE-2026-109619 (Use-After-Free via Stale Session State): Affects PHP workers that handle multiple sequential requests. When a fatal error aborts a request, PHP’s upload progress tracker fails to clear global pointers. If the worker is reused, a subsequent request can read or overwrite this "stale" dangling pointer, leading to arbitrary code execution.

Exploit Mechanics: Step-by-Step

Understanding PHP2Shell requires looking at PHP's upload_progress feature. Enabled by default, this feature uses a POST parameter (PHP_SESSION_UPLOAD_PROGRESS) to track multi-part file uploads using zval pointers internally.

                  [ Attacker HTTP POST Multipart Request ]
                                     │  (Includes PHP_SESSION_UPLOAD_PROGRESS)
                                     ▼
               ┌──────────────────────────────────────────┐
               │         PHP Native HTTP Parser           │ (Runs before application code!)
               └────────────────────┬─────────────────────┘
                                    │
                         Is `memory_limit` hit?
                         or is stream interrupted?
                                  /   \
                                 /     \
                               YES      NO ──► [ Regular PHP App Execution ]
                               /
                              ▼
               ┌──────────────────────────────────────────┐
               │    Memory Allocation Failure (OOM)       │ (CVE-2026-109618)
               └────────────────────┬─────────────────────┘
                                    │  *aborts initialization halfway*
                                    ▼
               ┌──────────────────────────────────────────┐
               │         Fatal Error Triggered            │
               │   (Cleans up, but leaves dangling      │
               │    C pointers & zval structures)         │ (Use-After-Free / Stale State)
               └────────────────────┬─────────────────────┘
                                    │
                                    ▼
               ┌──────────────────────────────────────────┐
               │   Attacker Sprays Forged Structs into   │
               │    Memory & Triggers dangling Destructor │
               └────────────────────┬─────────────────────┘
                                    │
                                    ▼
                           [ REMOTE SHELL/RCE ]

Stage 1: Forcing memory exhaustion (CVE-2026-109618)

To trigger CVE-2026-109618, the attacker needs to trigger a fatal out-of-memory error during PHP’s early multipart parsing. An attacker sends an immense multi-part form payload containing highly nested input or extremely large form data fields.

Because PHP parses this before enforcing POST limits or evaluating page code, it will eat up the allowed memory_limit (often 128M by default) right inside the engine.

When memory limit is reached, PHP initiates its engine-level panic: bailout().

Stage 2: Leaving Stale References (CVE-2026-109619)

The bailout() behavior interrupts PHP halfway through parsing file upload boundaries or loading sessions.
Specifically, the upload progress handler (php_session_rfc1867_progress) has already cached raw zval * memory pointers to monitor the incoming byte counts:

// Inside php_session.h (PHP Source)
typedef struct _php_session_rfc1867_progress {
    zval sid;
    smart_str key;
    // ...
    zval data;   // Points to the data exported in active sessions
    zval files;  // Points to files tracked in array
} php_session_rfc1867_progress;

Because the memory Allocation failure crashes the parsing sequence abruptly, PHP’s memory manager goes to clean up the request, freeing the buffers. Crucially, the global state pointers used by the session and upload handler are not reset to NULL.

They now point to freed, "dirty" heap space.

Stage 3: Spraying the Heap and Hijacking Execution

The attacker sends multiple HTTP requests to ensure they hitting the same PHP-FPM or Apache worker process. They will send:

  1. A first request to create the stale dangling pointer condition.
  2. An immediate follow-up "spray" request that populates the freed memory heap with customized, forged PHP array structures (zvals) containing specific function pointers or memory addresses.

When the worker process starts to clean up or reuse the lingering sessions on the subsequent request, the engine blindly reads the forged memory structures injected by the attacker. Since the engine believes this is a valid zval object, it can trigger its internal destructors on it:

# Sudo-concept of a custom payloads seen in early POCs:
# A crafted HTTP multipart payload with precise bytes to line up the forged zval pointers
POST /index.php HTTP/1.1
Host: target.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryXYZ
Content-Length: [massive_length]
Cookie: PHPSESSID=attacker-controlled-session-id

------WebKitFormBoundaryXYZ
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"

exploited-payload-metadata
------WebKitFormBoundaryXYZ
Content-Disposition: form-data; name="payload"; filename="rce.bin"
[Payload with specific memory offsets to hijack instruction pointers]
------WebKitFormBoundaryXYZ--

When PHP attempts to call destructors or access the stale global reference during subsequent requests, execution is forced to jump to the attacker's payload (often spawning a web shell or connecting back to a remote listener).


Identifying Targets and Vulnerability Checks

1. Verification of the Environment

Determine the active version of PHP:

php -v

All unpatched environments running PHP versions 5.4 through 8.5 (prior to the security patch on Oct 21, 2026) are inherently vulnerable.

2. Spotting the Indicators of Compromise (IoCs)

If you are analyzing server logs for attempted or successful PHP2Shell exploits, look for these telling signals:

  • Unexpected Subprocess Spawns: PHP-FPM or www-data invoking Shell interpreter processes (like sh, bash, python) without standard app logic.

    # Watch for parent processes of shell executions on Linux
    ps -efj | grep -E "(apache2|httpd|php-fpm)" | grep -E "(sh|bash|nc|curl|wget)"
    
  • Engine Crash Logs: Correlate frequent "Memory Exhaustion" fatal errors directly followed by Worker segmentation faults (SIGSEGV or signal 11) in your server logs.

    [14-Nov-2026] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate...)
    [14-Nov-2026] WARNING: [pool www] child 12345 exited on signal 11 (SIGSEGV) after 0.12345 seconds
    
  • Massive Post Payloads: Web server logs (Nginx or Apache) recording unusually large, unsuccessful POST requests to random or insignificant PHP scripts.


Defensive Countermeasures (Mitigation Playbook)

Since updating PHP requires thorough testing, you can implement the following strategies in your staging and production environments right away:

Phase A: The Absolute Fix (Patching)

This is the only 100% effective countermeasure. Apply security updates provided by your distribution or rebuild PHP using the patched source branches released on October 21, 2026:

  • PHP 8.2: Upgrade to 8.2.35+
  • PHP 8.3: Upgrade to 8.3.36+
  • PHP 8.4: Upgrade to 8.4.27+
  • PHP 8.5: Upgrade to 8.5.12+

Phase B: Web Server-level Prevention (Blocking Multipart/Form-Data)

Almost every known exploit path requires the use of HTTP multipart/form-data payloads to feed the upload progress parser. If your application or APIs do not need file uploads, you can block these requests at the web server level (e.g., Nginx or Apache) before they are passed to the PHP parser.

For Nginx:

Within your server block or the location processing PHP:

# Reject all multipart POST requests if uploads are not required
if ($http_content_type ~* "multipart/form-data") {
    return 403;
}

For Apache (.htaccess or httpd.conf):

RewriteEngine On
RewriteCond %{HTTP:Content-Type} multipart/form-data [NC]
RewriteRule ^ - [F]

Note: Be aware that this block will prevent users from uploading files (like profile photos or document uploads) so make sure to analyze user flows before applying this rule on critical pages.

Phase C: PHP Configuration Tweaks

To minimize the attack surface on systems that cannot be patched immediately, add or modify these settings in your global php.ini file:

; 1. Turn off Session Upload Progress Tracking entirely
session.upload_progress.enabled = 0

; 2. Limit the max POST payload size to a minimum size compatible with your site
post_max_size = 10M

; 3. Disable errors in production to avoid leaking server state or debug lines
display_errors = Off

; 4. Reduce nesting limits to prevent complex recursive objects
max_input_nesting_level = 64

For PHP-FPM, make sure to enforce these variables across pools (www.conf), since php-fpm does not always inherit global cli configs:

php_admin_flag[session.upload_progress.enabled] = off

Wrapping Up

PHP2Shell proves that even legacy components like session upload progress trackers—often overlooked for years—can trigger critical security incidents when analyzed under memory stress. High-severity RCEs like this highlight why input validation and boundary protections (like WAFs or reverse proxy restrictions) are crucial layers to enforce before requests hit back-end interpreter stacks.

Keep your runtimes updated, keep monitoring server workers, and stay safe in the terminal!