The php2shell Vulnerability in PHP Core: Memory Exhaustion Mechanics and Remote Code ExecutionLongread · digest for October 24
System administrator in a dark server room checking a terminal alert for the php2shell flaw and PHP patch status.
Longread5 sections≈ 5 min

The php2shell Vulnerability in PHP Core: Memory Exhaustion Mechanics and Remote Code Execution

If you administer web servers or build backends in PHP, the last few days probably came with a few late-night pages. Security researchers at Wiz published technical details of a critical vulnerability chain in PHP's core dubbed php2shell (tracked as CVE-2026-109618 and CVE-2026-109619).

Its CVSS v4.0 severity score is a chilling 9.2 out of 10 (Critical)—and for good reason. An unauthenticated attacker can achieve Remote Code Execution (RCE) on your server with a single specially crafted HTTP POST request.

The nastiest part is the attack vector. Your application code can follow every best practice in the book—strictly typed Laravel or Symfony, parameterized SQL queries, thorough input sanitization—and it still won't save you. php2shell strikes deeper, inside PHP's low-level C parser before a single line of your PHP script ever runs.

Anatomy of the Attack: How multipart Breaks the Runtime

Let's trace how an ordinary form upload turns into a remote system shell.

Step-by-step diagram of the php2shell attack chain in the rfc1867.c parser from memory exhaustion to shell takeover.

HTTP defines multipart/form-data for sending files and form fields by splitting payloads with text boundaries. Inside PHP's core, main/rfc1867.c is responsible for parsing that byte stream.

Here is the chain of events when the exploit lands:

  1. Malformed incoming stream: The attacker sends an HTTP POST request with multipart/form-data, intentionally omitting or mangling Content-Length or switching to Transfer-Encoding: chunked.
  2. Junk avalanche: The request body packs thousands of tiny empty form fields, deeply nested headers, and carefully shaped binary sequences designed to mimic internal C pointer structures.
  3. Forced OOM: The rfc1867.c parser eagerly allocates heap memory in Zend Engine for every field. Eventually, the process hits memory_limit (or exhausts available RAM) and throws Fatal error: Allowed memory size exhausted.
  4. The fatal shutdown routine: You'd expect the process to simply abort safely. Instead, on a fatal error, Zend Engine invokes its emergency shutdown handler to release file descriptors and clean up caches.
  5. Dereferencing a corrupted pointer: That cleanup code naively assumes the incoming form's linked lists and hash tables were fully initialized. Because of the sudden OOM bailout, the list is left half-built. The cleanup loop reads an attacker-controlled value from the incomplete buffer, treats it as a destructor function pointer, and jumps straight to it.

At that point, the CPU executes shellcode embedded in the request body. Because the web server—whether PHP-FPM, Apache mod_php, LiteSpeed, or FrankenPHP—runs under www-data or nginx, the attacker gains full access to the server's filesystem and database.

Why WAF Rules Are Only a Temporary Bandage

As soon as php2shell went public, major security and CDN providers—including Cloudflare, Fastly, and AWS WAF—pushed emergency signature rules to block suspicious POST requests packed with excessive multipart sections.

Relying on a WAF alone, however, is dangerous. Security researchers have already demonstrated several ways to slip past static filters:

  • splitting multipart boundaries across tiny TCP micro-chunks;
  • tweaking line-ending encodings (\r\n vs. \n);
  • injecting unusual field headers that simple WAF regexes ignore while PHP's internal parser happily accepts them.

A WAF buys sysadmins a few precious hours of breathing room, but the only real fix is updating the PHP binaries on your servers.

Official Patches and How to Update

The PHP Group security team shipped out-of-band emergency releases for every supported branch:

  • 8.5 branch updated to 8.5.12;
  • 8.4 patched to 8.4.27;
  • 8.3 updated to 8.3.36;
  • 8.2 received 8.2.35.

Check your running runtime version on the server first:

php -v
# Or check the specific running pool binary:
php-fpm8.4 -v

If you're on Debian or Ubuntu using Ondřej Surý's official repositories (ppa:ondrej/php), the upgrade is straightforward:

sudo apt update
sudo apt install --only-upgrade php8.4-fpm php8.4-cli php8.4-common
# Crucial: always restart the service after upgrading!
sudo systemctl restart php8.4-fpm

In Docker setups, rebuild your images against updated base tags like php:8.4-fpm-alpine or force apk upgrade --no-cache inside your Dockerfile.

The End-of-Life (EOL) Trap

The biggest headache hits projects still running older PHP versions: 8.1, 8.0, 7.4, or older. All of them are officially End-of-Life (EOL), meaning the core PHP team no longer ships free security patches for them.

If your legacy app is stuck on PHP 7.4, you have three options:

  1. Emergency migration to 8.2+ (the cleanest long-term fix, though the heaviest lift).
  2. Long-term support distros: Red Hat Enterprise Linux, Ubuntu Pro, and Debian LTS backport security fixes into their older system packages.
  3. Commercial patching: buying third-party security patches from vendors like TuxCare.

Checking Your Server for Signs of Compromise

If a server sat exposed without a patch, audit active processes immediately. Since shellcode typically spawns a command shell or network tools to fetch payloads, inspect your process tree:

# Look for shells or download utilities spawned by PHP-FPM workers
ps -ef --forest | grep -E 'php-fpm.*(sh|bash|curl|wget|nc|python)'

Any /bin/sh or /bin/bash process whose parent is php-fpm is an unmistakable red flag that the box has been compromised.

The bigger trend: binary parsers in the crosshairs

The php2shell disclosure landed right alongside another critical flaw—a buffer overflow in the C-based Brotli decoder bundled with Node.js. Security researchers are clearly shifting focus from application code down to low-level runtime network parsers. Keep a close eye on base image updates and don't sit on system patches.

Want a deep diveVotes help us choose what to break down in detail. This material has 0 votes.
Sources · 3