Skip to content
Memory corruption Write-up Advanced

PHP2Shell: The Ten-Second Path From Request to Root (CVE-2026–109618/109619)

A memory-limit bailout during PHP request parsing leaves an uninitialized hash-table entry that shutdown later treats as a real value, allowing a leak of worker memory through the session cookie and, with a forged structure, command execution. An attacker could read process memory to defeat ASLR and then run commands as the PHP worker user.

Harshavardhan Follow

Published on tagirisaharshavardhan.medium.com

PHP

Harshavardhan, on tagirisaharshavardhan.medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 12 min read.

Context

PHP2Shell is a vulnerability class in the PHP runtime itself, tracked as CVE-2026-109618 and CVE-2026-109619. The two CVEs share a single root defect, classified as CWE-824, and are chained: the first leaks memory addresses, the second reuses that leak to redirect a cleanup routine into command execution.

The detail that reframes everything else is that the bug has nothing to do with the application. PHP parses the incoming request, decoding the body and building internal structures for form fields and session data, before a single line of application code runs. If the flaw fires during that parsing stage, the application never gets a chance to matter. A script that does nothing but print "OK" is exactly as exposed as a complex authentication handler, because the vulnerable surface sits one layer below the application, in the PHP runtime itself.

From the original on tagirisaharshavardhan.medium.com

Under a typical deployment, Apache's prefork model with mod_php or PHP-FPM, the same worker process serves request after request without restarting in between. That is efficient by design, and it means anything left behind incorrectly during cleanup is still sitting in that worker's memory when the next request lands. That single fact is the hinge the entire vulnerability class turns on.

Setup

Finding it

PHP caps memory per request via memory_limit. When an operation would exceed it, PHP performs what the engine itself calls a bailout, internally a longjmp(), an abrupt jump back to a safe recovery point that abandons whatever operation was mid-flight. That is the mechanism behind the familiar "Allowed memory size exhausted" error.

A request that finishes normally cleans up fully: memory is freed, and every pointer referencing it is cleared. A bailout skips the second half of that. It is an emergency exit, not an orderly shutdown.

From the original on tagirisaharshavardhan.medium.com

bailout skipping cleanup: memory freed, pointer-clearing step skipped, dangling pointer left behind, next request on the same worker follows the stale pointer

The code pattern behind the bug is one most readers will recognise instantly. When PHP inserts a new entry into a hash table, the structure backing $_POST among other things, it does two things in sequence: it bumps the table's internal "how many entries do I have" counters, and then it allocates memory for the actual entry data. In pseudocode, the order looks roughly like this:

Text
function insert_entry(table, key_name):
    slot = table.next_free_slot
    table.entry_count += 1          # counter updated first
    table.used_slots += 1
    entry = table.slots[slot]
    entry.key = allocate_and_copy(key_name)   # allocation happens second
    entry.value = ...

If the allocation on that last line is the one that blows past memory_limit, PHP aborts right there with a bailout. The counters already say "there are N entries". The Nth entry itself was never actually populated; it is just whatever bytes happened to occupy that memory beforehand.

PHP still runs its shutdown routine for that request, because a fatal error does not skip cleanup entirely. It only skips the mid-operation cleanup that would have happened if the insert had completed normally. Shutdown walks every slot the counter claims exists, including the one that is uninitialised garbage, and treats it as a real value. That is the entire root defect: one line of bookkeeping runs before the thing it is counting actually exists.

Exploitation

Once the ordering mistake is understood, the path from "a request failed" to "a shell command ran" is a short, mechanical chain with no exotic steps, just one consequence after another:

Text
Request parsing hits the memory limit mid-insertion
  → PHP bails out, counters already updated, entry never populated
  → Request shutdown still runs and walks every counted entry
  → The uninitialized entry is read and interpreted as a PHP value
  → If that value looks like an array, PHP calls its cleanup routine
  → The cleanup routine
  → That redirected call executes with attacker-supplied input

Every arrow in that chain is PHP doing something it was always going to do anyway: count, clean up, call a destructor. None of it is unusual engine behaviour in isolation. The vulnerability is entirely in what data happens to be sitting in that one uninitialised slot when shutdown gets to it.

Step 1: leak addresses with CVE-2026-109618

Modern systems randomise where code and data sit in memory specifically so that an attacker cannot predict useful addresses; that is ASLR. Before anything in the chain above can reliably redirect execution toward something like a shell-spawning function, an attacker needs real addresses to work with, not guesses.

This CVE gets there by triggering the same bailout condition while PHP is handling the session identifier. A dangling reference to the session data survives the failed request. A following request on the same worker reoccupies that freed memory, and when PHP next reads the session value to build the response cookie, it reads it as a string far longer than a real session ID, because the length field associated with that stale reference no longer matches the real data. Whatever memory follows gets reflected straight back to the client inside the Set-Cookie: PHPSESSID response header.

Public research measured this leak at up to roughly 67 KB of process memory in a single response. Buried in that leak are the runtime addresses of the heap and of PHP's own library code in that specific worker, exactly what is needed to defeat ASLR without guessing.

cookie header disclosure: real session ID followed by leaked worker memory, including code addresses, reflected in the Set-Cookie response header

Step 2: turn the read into a write with CVE-2026-109619

With those addresses known, the same underlying bug is reused in the opposite direction. Instead of reading data out of the freed memory slot, a forged internal structure gets written into it, shaped to match what PHP expects an array-like value to look like. That structure carries a function pointer, a destructor, the routine PHP calls to release a value's resources when it is done with it, and that pointer has been redirected to point at a command-execution function in the PHP library, using the address obtained from the leak above.

When shutdown walks into that planted structure and calls what it believes is a routine cleanup step, it instead executes a command with attacker-supplied input, running with whatever privileges the PHP worker has, commonly www-data on Linux.

From the original on tagirisaharshavardhan.medium.com

the two CVEs built on the shared CWE-824 root defect: one path leaks addresses, the other reuses the leak to redirect cleanup into command execution

Step 3: the delivery request

Independent analysis of multiple public proof-of-concept tools found a consistent shape to the opening request: a multipart form submission that touches PHP's session machinery before anything else happens. Stripped down to just the structure, with no sizes, no trigger values and nothing that would actually reproduce the bug, it looks roughly like this:

HTTP
POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=----BOUNDARY
Text
------BOUNDARY
Content-Disposition: form-data; name="PHPSESSID"

<session value>
------BOUNDARY
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"

<progress key>
------BOUNDARY
Content-Disposition: form-data; name="payload_field"; filename="file.txt"
Content-Type: application/octet-stream

<additional parts or a large fill value, used to force memory pressure>
------BOUNDARY--

The request is a multipart form submission that touches PHP's session machinery before anything else happens, with additional parts or a large fill value used to force memory pressure. What makes the request recognisable is not any single field: plenty of legitimate upload forms use PHPSESSID and PHP_SESSION_UPLOAD_PROGRESS without anything malicious going on. It is the combination, especially on a route that has no business handling uploads at all, paired with an unusually high part count or a field sized to deliberately pressure the memory limit. That combination, correlated with the log and process signals below, is what separates a real attempt from a false positive.

Step 4: what success looks like

A successful exploit does not match the instinctive picture of "an attack crashed something":

  • The HTTP response often comes back as a plain 200, sometimes with a memory-exhaustion error visible in the body, sometimes not at all.
  • The worker process does not necessarily crash or restart. Documented testing shows the same worker continuing to run normally immediately after executing an attacker's command.
  • The real evidence sits in the process tree: a web server process, apache2, php-fpm or equivalent, commonly running as www-data, spawning a shell (sh, bash, dash), which then runs whatever command the attacker supplied. On Windows, the parallel is the web server or PHP process spawning cmd.exe or powershell.exe.

A failed attempt, by contrast, tends to leave two distinct traces. In the PHP error log: Allowed memory size of N bytes exhausted, reported at Unknown on line 0, meaning the failure happened during request parsing, before any application script ran. And a bad address guess shows up as the worker segfaulting outright, logged as a child process exiting on signal 11.

Root cause

The defect is an ordering mistake in hash table insertion: the entry counter is incremented before the entry data is allocated. When the allocation trips memory_limit, the bailout abandons the operation with the counters already updated, and the slot the counter claims exists is never populated. Request shutdown then walks every counted entry and interprets the uninitialised slot as a real PHP value. If that value looks like an array, PHP calls its cleanup routine on it, and because the contents of the slot are attacker-influenced through cross-request reuse of the worker's memory, the destructor pointer can be redirected.

Application-level defences do not help, because the flaw fires during request parsing, before application code runs. A WAF running as a PHP module cannot help either: by the time it inspects anything, PHP has already finished parsing and the damage is done. The cross-request nature of the bug depends on the worker model: a process that serves request after request without restarting carries stale state forward, and a following request on the same worker reoccupies the freed memory.

Impact

An attacker who can reach a vulnerable PHP runtime can chain the two CVEs to execute arbitrary commands with the privileges of the PHP worker, commonly www-data on Linux. The exposure does not depend on the application's logic, its authentication or its framework patch level, since the vulnerable surface is the parser itself. The leak stage discloses up to roughly 67 KB of process memory per response, including heap and library code addresses for that worker, which is enough to defeat ASLR. The command execution stage runs with whatever privileges the worker holds, and the worker need not crash, so the response can look like an ordinary 200.

Fix

The only complete fix is updating the PHP runtime, to 8.5.12, 8.4.27, 8.3.36 or 8.2.35 depending on the branch, then restarting every worker, since a running process keeps executing the old code even after the package on disk changes.

Interim mitigations reduce exposure without closing the hole:

  • session.upload_progress.enabled = 0, applied before PHP parses any request and paired with a full worker restart, removes the trigger for most reported upload-progress techniques.
  • fatal_error_backtraces = 0, on PHP 8.5 specifically, addresses the backtrace-handling path tied to CVE-2026-109619.
  • opcache.enable = 0 makes the code-execution path harder to reach, at a real performance cost.
  • Rejecting or constraining multipart/form-data at a reverse proxy or network boundary, ahead of PHP entirely, is one of the few controls that genuinely works, because it stops the request before it reaches the vulnerable parser.

None of this replaces patching. It buys time, nothing more.

For inventory, a pure version-fingerprinting scanner that reads response headers, compares against the fixed-version table and flags what is outdated is a reasonable first pass. It is read-only and cannot crash or corrupt anything it touches. The author's PHP2Shell Exposure Scanner is a lightweight Python tool that inspects response headers and landing-page HTML for PHP version information and compares any detected version against the fixed-version thresholds configured in the script. It supports single-target and bulk scans, with table, JSON and CSV output, and is detection-only: it does not attempt exploitation or verify remote code execution. Because it relies on observable version information, results may be incomplete when version banners are suppressed, and vendor-backported fixes may not be reflected in the reported version.

Bash
python3 php2shell_scan.py https://yourapp.example

For multiple targets:

Bash
python3 php2shell_scan.py -i urls.txt --format json --out scan.json

The scanner's source is at https://github.com/HARSHA2396/php2shell-exposure-scanner. Use it only against systems you own or are authorised to assess.

Detection

Layer the signals by how far downstream they sit, and trust them accordingly.

Request-level signals (supporting evidence only):

  • Multipart POST requests with unusually high field counts or deeply nested field name structures, particularly on endpoints that do not normally take uploads.
  • Presence of PHP_SESSION_UPLOAD_PROGRESS or similar session-progress fields on routes that have nothing to do with file uploads.
  • A Set-Cookie: PHPSESSID= value dramatically longer, or differently formatted, than the application's normal session ID. Baseline this once, since a real PHP session ID is a short, fixed-length string.

PHP and web server log signals:

  • Allowed memory size exhausted errors reported at line 0, the fingerprint of a failure during request parsing rather than during script execution.
  • Worker segmentation faults clustered in a short time window on the same host.
  • A short burst of memory-exhaustion errors followed by the logs going quiet. Do not read "quiet" as "resolved".

Host and EDR signals (the strongest evidence by far):

  • Any shell interpreter spawned with a web server or PHP process as its direct parent.
  • New outbound network connections originating from that shell, or from the web/PHP process itself.
  • New files written into the web root, or command-line arguments that do not match the application's normal behaviour.

The correlation that matters: an anomalous request, followed by a parse-time memory error or an oversized session cookie, followed by a shell spawned from the web process, close together in time, on the same host. That sequence, seen together, is close to conclusive. Any one signal alone is noise.

Variants to test

  • Send a multipart POST with a high part count or a large fill value to a route that does not normally accept uploads, and watch for Allowed memory size exhausted at Unknown on line 0 in the PHP error log. A positive result is a parse-time memory error with no application script involved.
  • Include PHP_SESSION_UPLOAD_PROGRESS alongside PHPSESSID in a multipart body and inspect the Set-Cookie: PHPSESSID= value in the response. A positive result is a session cookie dramatically longer than the application's normal fixed-length ID, a supporting signal worth correlating with other evidence.
  • Repeat the same request against the same worker and check for worker segfaults logged as a child process exiting on signal 11. A positive result is clustered signal 11 exits in a short window on one host.
  • After a suspected attempt, inspect the process tree for a shell (sh, bash, dash) whose direct parent is apache2, php-fpm or equivalent, or on Windows cmd.exe or powershell.exe spawned by the web or PHP process. A positive result is a shell with a web process as its parent, even if the HTTP response was a plain 200.
  • Check whether session.upload_progress.enabled is set to 0 and whether fatal_error_backtraces is disabled on PHP 8.5, and whether multipart/form-data is constrained at a reverse proxy ahead of PHP. A positive result for exposure is any of these controls missing on a host running a vulnerable build.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 21 min read.

What happened, in plain words

A researcher named Harshavardhan worked through public research on two security bugs in PHP, the software that runs a huge share of the world's websites. The bugs are tracked as CVE-2026-109618 and CVE-2026-109619, and together the chain has a nickname: PHP2Shell. The name hints at the outcome: a single web request can, in the worst case, end with the attacker running commands on the server with the PHP worker's privileges.

From the original on tagirisaharshavardhan.medium.com

The most important thing to understand before anything else is that these bugs have nothing to do with the website built on top of PHP. Your login form can be perfect. Your framework can be fully patched. It does not matter. PHP reads and unpacks every incoming request before your own code gets a single turn, and the flaw fires during that unpacking. A page that does nothing but print "OK" is exactly as exposed as a complex authentication handler, because the broken part sits one layer below the application, inside PHP itself.

Why application security does not touch this

Start with the detail that reframes everything else. When you type an address into your browser and press Enter, a lot happens before any web page code runs. The browser sends a request over the network. A web server program on the other machine receives it. If the site is written in PHP, the web server hands the request to PHP, and PHP's first job is to parse it: read the raw bytes, work out where each form field begins and ends, decode the values, and build internal data structures that the application can then use.

Only after that parsing is finished does your application code start running. So if the bug lives in the parsing step, the application never gets a chance to defend itself. That is why the researcher says application security does not touch this.

From the original on tagirisaharshavardhan.medium.com

How a worker actually serves requests

To follow the rest, you need a picture of how a web server handles traffic. A busy site cannot start a fresh program for every visitor; that would be far too slow. Instead it keeps a pool of long-lived helper processes, often called workers. Each worker takes a request, handles it, sends the response, and then waits for the next request. It does not restart in between.

Two common setups are Apache's prefork model with mod_php, and PHP-FPM. In both, the same worker process serves request after request. That is efficient by design. It also means that if a worker leaves something behind by mistake while cleaning up after one request, that leftover is still sitting in the worker's memory when the next request arrives. This single fact is the hinge the whole vulnerability class turns on: one visitor's mess can become the next visitor's problem.

Where the defect actually lives

PHP limits how much memory a single request may use, through a setting called memory_limit. Think of it as a spending cap on a prepaid card: once the balance is gone, the transaction is refused. When an operation would go over the cap, PHP performs what the engine itself calls a bailout. Internally this is a longjmp(), which is a sudden jump back to a safe recovery point, abandoning whatever operation was halfway through. This is the mechanism behind the familiar error message "Allowed memory size exhausted".

Now compare two ways a request can end. A request that finishes normally cleans up fully: memory is freed, and every pointer that referred to it is cleared. A pointer is simply a note that says "the data you want is at this address". Clearing the pointer means crossing out the note so nobody follows it later. A bailout skips that second half. It is an emergency exit, not an orderly shutdown: the lights go off, but the door is left swinging.

From the original on tagirisaharshavardhan.medium.com

bailout skipping cleanup: memory freed, pointer-clearing step skipped, dangling pointer left behind, next request on the same worker follows the stale pointer

The actual code pattern, in plain terms

Here is the part worth sitting with, because once you see it you will recognise it everywhere. PHP stores form fields and similar data in a structure called a hash table. A hash table is like a numbered rack of pigeonholes: each entry gets a slot, and the table keeps a count of how many slots are in use.

When PHP inserts a new entry, it does two things in sequence. First it bumps the table's internal "how many entries do I have" counters. Then it allocates memory for the actual entry data. In pseudocode, the order looks roughly like this:

Text
function insert_entry(table, key_name):
    slot = table.next_free_slot
    table.entry_count += 1          # counter updated first
    table.used_slots += 1
    entry = table.slots[slot]
    entry.key = allocate_and_copy(key_name)   # allocation happens second
    entry.value = ...

Line by line:

  1. function insert_entry(table, key_name): declares a routine that takes a table and the name of the key to insert.
  2. slot = table.next_free_slot picks the next empty pigeonhole.
  3. table.entry_count += 1 increases the count of entries by one. This is the bookkeeping step, and it happens first.
  4. table.used_slots += 1 does the same for the count of used slots.
  5. entry = table.slots[slot] grabs a handle on that slot.
  6. entry.key = allocate_and_copy(key_name) asks the system for memory and copies the key name into it. This is the step that can run out of memory.
  7. entry.value = ... would fill in the value, but only if the previous line succeeded.

If the allocation on line 6 is the one that blows past memory_limit, PHP aborts right there with a bailout. The counters already say "there are N entries". But the Nth entry itself was never actually populated. It is just whatever bytes happened to occupy that memory beforehand, like a locker that was marked as rented but never cleaned out.

PHP still runs its shutdown routine for that request, because a fatal error does not skip cleanup entirely. It only skips the mid-operation cleanup that would have happened if the insert had completed normally. Shutdown walks every slot the counter claims exists, including the one that is uninitialised garbage, and treats it as a real value. That is the entire root defect: one line of bookkeeping runs before the thing it is counting actually exists.

Tracing it through to execution

Once you understand that one ordering mistake, the path from "a request failed" to "a shell command ran" is a short, mechanical chain with no exotic steps, just one consequence after another:

Text
Request parsing hits the memory limit mid-insertion
  → PHP bails out, counters already updated, entry never populated
  → Request shutdown still runs and walks every counted entry
  → The uninitialized entry is read and interpreted as a PHP value
  → If that value looks like an array, PHP calls its cleanup routine
  → The cleanup routine
  → That redirected call executes with attacker-supplied input

Line by line:

  1. While parsing the request, PHP runs out of its memory allowance in the middle of inserting an entry.
  2. PHP bails out. The counters were already increased, but the entry itself was never filled in.
  3. Shutdown still runs, and it walks every entry the counter claims exists.
  4. It reaches the uninitialised slot and reads it as if it were a real PHP value.
  5. If that value looks like an array, PHP calls the routine it uses to clean up arrays.
  6. That cleanup routine is the point where control can be redirected.
  7. The redirected call runs with input the attacker supplied.

Every arrow in that chain is PHP doing something it was always going to do anyway: count, clean up, call a destructor. A destructor is the routine a program calls to release a value's resources when it is done with it, like a librarian reshelving a book. None of this is unusual engine behaviour in isolation. The vulnerability is entirely in what data happens to be sitting in that one uninitialised slot when shutdown gets to it.

Step 1: leak addresses with CVE-2026-109618

Modern systems randomise where code and data sit in memory specifically so that an attacker cannot predict useful addresses. That defence is called ASLR, short for Address Space Layout Randomisation. Think of it as shuffling the deck before every game: even if you know which card you want, you do not know where it is.

Before anything in the chain above can reliably redirect execution toward something like a shell-spawning function, an attacker needs real addresses to work with, not guesses. This CVE gets there by triggering the same bailout condition while PHP is handling the session identifier.

A session is how a website remembers who you are between requests. When you log in, the server gives your browser a cookie, a small piece of text that the browser sends back on every later request. For PHP the cookie is usually called PHPSESSID, and its value is a short, fixed-length string that points to your session data on the server. A dangling reference to that session data survives the failed request. A following request on the same worker reoccupies that freed memory, and when PHP next reads the session value to build the response cookie, it reads it as a string far longer than a real session ID, because the length field associated with that stale reference no longer matches the real data. Whatever memory follows gets reflected straight back to the client inside the Set-Cookie: PHPSESSID response header.

Public research measured this leak at up to roughly 67 KB of process memory in a single response. Buried in that leak are the runtime addresses of the heap and of PHP's own library code in that specific worker, exactly what is needed to defeat ASLR without guessing. The heap is the general-purpose pool of memory a program uses for data it creates while running.

cookie header disclosure: real session ID followed by leaked worker memory, including code addresses, reflected in the Set-Cookie response header

Step 2: turn the read into a write with CVE-2026-109619

With those addresses known, the same underlying bug is reused in the opposite direction. Instead of reading data out of the freed memory slot, a forged internal structure gets written into it, shaped to match what PHP expects an array-like value to look like. That structure carries a function pointer, which is simply a stored address saying "when you need this job done, jump here". In this case the pointer is a destructor, the routine PHP calls to release a value's resources when it is done with it, and that pointer has been redirected to point at a command-execution function in the PHP library, using the address obtained from the leak above.

When shutdown walks into that planted structure and calls what it believes is a routine cleanup step, it instead executes a command with attacker-supplied input, running with whatever privileges the PHP worker has, commonly www-data on Linux. www-data is the account that web server processes commonly run under on Linux.

From the original on tagirisaharshavardhan.medium.com

the two CVEs built on the shared CWE-824 root defect: one path leaks addresses, the other reuses the leak to redirect cleanup into command execution

Step 3: the delivery request

Independent analysis of multiple public proof-of-concept tools found a consistent shape to the opening request: a multipart form submission that touches PHP's session machinery before anything else happens. A multipart form is the format browsers use when a form includes a file upload: the body is split into parts, each with its own headers and content, separated by a boundary string. Stripped down to just the structure, with no sizes, no trigger values and nothing that would actually reproduce the bug, it looks roughly like this:

HTTP
POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=----BOUNDARY

Line by line:

  1. POST / HTTP/1.1 is the request line. POST means "I am sending data", / is the path being requested, and HTTP/1.1 is the protocol version.
  2. Content-Type: multipart/form-data; boundary=----BOUNDARY tells the server the body is split into parts, and that the separator between parts is the string ----BOUNDARY.
Text
------BOUNDARY
Content-Disposition: form-data; name="PHPSESSID"

<session value>
------BOUNDARY
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"

<progress key>
------BOUNDARY
Content-Disposition: form-data; name="payload_field"; filename="file.txt"
Content-Type: application/octet-stream

<additional parts or a large fill value, used to force memory pressure>
------BOUNDARY--

Line by line:

  1. ------BOUNDARY opens the first part. The extra dashes are part of the separator syntax.
  2. Content-Disposition: form-data; name="PHPSESSID" names this part PHPSESSID, so PHP treats it as the session identifier field.
  3. <session value> is a placeholder for the session value; the real value is not shown.
  4. The next ------BOUNDARY closes that part and opens the next.
  5. Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS" names this part PHP_SESSION_UPLOAD_PROGRESS, a field PHP uses to track upload progress.
  6. <progress key> is a placeholder for that progress key.
  7. The next boundary opens a part with name="payload_field"; filename="file.txt", which looks like a file upload.
  8. Content-Type: application/octet-stream says the file content is raw binary data.
  9. <additional parts or a large fill value, used to force memory pressure> is where the request is padded out so that parsing it pushes PHP toward its memory limit.
  10. ------BOUNDARY-- closes the body; the trailing double dash marks the end.

The PHPSESSID and PHP_SESSION_UPLOAD_PROGRESS fields drive PHP's session machinery during parsing, and the remaining parts or fill value are there to force memory pressure. What makes the request recognisable is not any single field: plenty of legitimate upload forms use PHPSESSID and PHP_SESSION_UPLOAD_PROGRESS without anything malicious going on. It is the combination, especially on a route that has no business handling uploads at all, paired with an unusually high part count or a field sized to deliberately pressure the memory limit. That combination, correlated with the log and process signals below, is what separates a real attempt from a false positive.

Step 4: what success looks like

A successful exploit does not match the instinctive picture of "an attack crashed something". Here is what to expect instead:

  • The HTTP response often comes back as a plain 200, sometimes with a memory-exhaustion error visible in the body, sometimes not at all. A 200 is the standard "everything is fine" status code, so a successful attack can look completely ordinary.
  • The worker process does not necessarily crash or restart. Documented testing shows the same worker continuing to run normally immediately after executing an attacker's command.
  • The real evidence sits in the process tree. A process tree is the parent-child relationship between running programs. A web server process, apache2, php-fpm or equivalent, commonly running as www-data, spawns a shell (sh, bash, dash), which then runs whatever command the attacker supplied. On Windows, the parallel is the web server or PHP process spawning cmd.exe or powershell.exe.

A failed attempt, by contrast, tends to leave two distinct traces. In the PHP error log: Allowed memory size of N bytes exhausted, reported at Unknown on line 0, meaning the failure happened during request parsing, before any application script ran. And a bad address guess shows up as the worker segfaulting outright, logged as a child process exiting on signal 11. A segfault is a crash that happens when a program tries to touch memory it is not allowed to touch.

Root cause

The defect is an ordering mistake in hash table insertion: the entry counter is incremented before the entry data is allocated. When the allocation trips memory_limit, the bailout abandons the operation with the counters already updated, and the slot the counter claims exists is never populated. Request shutdown then walks every counted entry and interprets the uninitialised slot as a real PHP value. If that value looks like an array, PHP calls its cleanup routine on it, and because the contents of the slot are attacker-influenced through cross-request reuse of the worker's memory, the destructor pointer can be redirected.

Application-level defences do not help, because the flaw fires during request parsing, before application code runs. A WAF, a Web Application Firewall, is a filter that inspects traffic before it reaches the application. One running as a PHP module cannot help either: by the time it inspects anything, PHP has already finished parsing and the damage is done. The cross-request nature of the bug depends on the worker model: a process that serves request after request without restarting carries the stale state forward, which is why the leak and the write both land on the same worker.

Impact

An attacker who can reach a vulnerable PHP runtime can chain the two CVEs to execute arbitrary commands with the privileges of the PHP worker, commonly www-data on Linux. The exposure does not depend on the application's logic, its authentication or its framework patch level, since the vulnerable surface is the parser itself. The leak stage discloses up to roughly 67 KB of process memory per response, including heap and library code addresses for that worker, which is enough to defeat ASLR. The command execution stage runs with whatever privileges the worker holds, and the worker need not crash, so the response can look like an ordinary 200.

Fix

The only complete fix is updating the PHP runtime, to 8.5.12, 8.4.27, 8.3.36 or 8.2.35 depending on the branch, then restarting every worker, since a running process keeps executing the old code even after the package on disk changes. Think of it as replacing a faulty engine part: the car will not use the new part until you switch the engine off and on again.

Interim mitigations reduce exposure without closing the hole:

  • session.upload_progress.enabled = 0, applied before PHP parses any request and paired with a full worker restart, removes the trigger for most reported upload-progress techniques.
  • fatal_error_backtraces = 0, on PHP 8.5 specifically, addresses the backtrace-handling path tied to CVE-2026-109619.
  • opcache.enable = 0 makes the code-execution path harder to reach, at a real performance cost. Opcache is a PHP feature that caches compiled code in memory to speed things up.
  • Rejecting or constraining multipart/form-data at a reverse proxy or network boundary, ahead of PHP entirely, is one of the few controls that genuinely works, because it stops the request before it reaches the vulnerable parser. A reverse proxy is a server that sits in front of the real one and can filter traffic.

None of this replaces patching. It buys time, nothing more.

Checking your own exposure

Before patching, you need an accurate inventory of which hosts are actually running a vulnerable build, including containers and bundled interpreters that will not show up if you are only checking a system-level PHP install. A container is a lightweight, isolated package that runs an application and its dependencies together. A pure version-fingerprinting scanner, which reads response headers, compares against the fixed-version table and flags what is outdated, is a reasonable first pass. It is read-only and cannot crash or corrupt anything it touches, which makes it meaningfully different from anything that tries to trigger the actual bug.

The author's PHP2Shell Exposure Scanner is a lightweight Python tool that inspects response headers and landing-page HTML for PHP version information and compares any detected version against the fixed-version thresholds configured in the script. It supports single-target and bulk scans, with table, JSON and CSV output, and is detection-only: it does not attempt exploitation or verify remote code execution. Because it relies on observable version information, results may be incomplete when version banners are suppressed, and vendor-backported fixes may not be reflected in the reported version.

Bash
python3 php2shell_scan.py https://yourapp.example

Line by line:

  1. python3 runs the Python 3 interpreter.
  2. php2shell_scan.py is the scanner script.
  3. https://yourapp.example is the single target URL to check.

For multiple targets:

Bash
python3 php2shell_scan.py -i urls.txt --format json --out scan.json

Line by line:

  1. python3 php2shell_scan.py runs the scanner as before.
  2. -i urls.txt reads the list of targets from a file called urls.txt.
  3. --format json asks for the report in JSON, a structured text format that other tools can read.
  4. --out scan.json writes the report to a file called scan.json.

The scanner's source is at https://github.com/HARSHA2396/php2shell-exposure-scanner. Use it only against systems you own or are authorised to assess.

Detection

Layer the signals by how far downstream they sit, and trust them accordingly. A signal is any clue in logs or on the host that something happened; downstream means closer to the actual damage.

Request-level signals (supporting evidence only):

  • Multipart POST requests with unusually high field counts or deeply nested field name structures, particularly on endpoints that do not normally take uploads. An endpoint is a specific URL path that accepts requests.
  • Presence of PHP_SESSION_UPLOAD_PROGRESS or similar session-progress fields on routes that have nothing to do with file uploads.
  • A Set-Cookie: PHPSESSID= value dramatically longer, or differently formatted, than the application's normal session ID. Baseline this once, since a real PHP session ID is a short, fixed-length string. Baselining means recording what normal looks like so you can spot abnormal.

PHP and web server log signals:

  • Allowed memory size exhausted errors reported at line 0, the fingerprint of a failure during request parsing rather than during script execution.
  • Worker segmentation faults clustered in a short time window on the same host.
  • A short burst of memory-exhaustion errors followed by the logs going quiet. Do not read "quiet" as "resolved".

Host and EDR signals (the strongest evidence by far). EDR stands for Endpoint Detection and Response: software on a machine that watches what programs do.

  • Any shell interpreter spawned with a web server or PHP process as its direct parent.
  • New outbound network connections originating from that shell, or from the web/PHP process itself.
  • New files written into the web root, or command-line arguments that do not match the application's normal behaviour. The web root is the folder the web server serves files from.

The correlation that matters: an anomalous request, followed by a parse-time memory error or an oversized session cookie, followed by a shell spawned from the web process, close together in time, on the same host. That sequence, seen together, is close to conclusive. Any one signal alone is noise.

Variants to test

  • Send a multipart POST with a high part count or a large fill value to a route that does not normally accept uploads, and watch for Allowed memory size exhausted at Unknown on line 0 in the PHP error log. A positive result is a parse-time memory error with no application script involved.
  • Include PHP_SESSION_UPLOAD_PROGRESS alongside PHPSESSID in a multipart body and inspect the Set-Cookie: PHPSESSID= value in the response. A positive result is a session cookie dramatically longer than the application's normal fixed-length ID, which indicates leaked worker memory.
  • Repeat the same request against the same worker and check for worker segfaults logged as a child process exiting on signal 11. A positive result is clustered signal 11 exits in a short window on one host.
  • After a suspected attempt, inspect the process tree for a shell (sh, bash, dash) whose direct parent is apache2, php-fpm or equivalent, or on Windows cmd.exe or powershell.exe spawned by the web or PHP process. A positive result is a shell with a web process as its parent, even if the HTTP response was a plain 200.
  • Check whether session.upload_progress.enabled is set to 0 and whether fatal_error_backtraces is disabled on PHP 8.5, and whether multipart/form-data is constrained at a reverse proxy ahead of PHP. A positive result for exposure is any of these controls missing on a host running a vulnerable build.

Closing thought

What stays with the researcher most is how unglamorous the root cause actually is. This is not an exotic memory-corruption technique. It is a counter getting incremented one line before the thing it is counting was actually created, in cleanup code that has been shipping in production PHP for a long time. Everything downstream, the ASLR bypass through a cookie header, the forged destructor, the cross-request state reuse, is just that one ordering mistake being exploited in increasingly deliberate ways. The scariest bugs are rarely the cleverest ones to find. They are the simplest ones nobody double-checked.

Glossary

  • ASLR (Address Space Layout Randomisation): a defence that shuffles where code and data sit in memory so an attacker cannot predict addresses.
  • Bailout: PHP's emergency exit when a request exceeds its memory limit, abandoning the current operation.
  • Baselining: recording what normal behaviour looks like so you can spot what is abnormal.
  • Boundary: the separator string that marks where one part of a multipart body ends and the next begins.
  • Container: a lightweight, isolated package that runs an application and its dependencies together.
  • Cookie: a small piece of text a website stores in your browser and receives back on later requests, often used to remember who you are.
  • CVE: a public identifier for a known security vulnerability.
  • CWE-824: the classification named in the report as the shared root defect behind both CVEs.
  • Dangling pointer: a pointer that still refers to memory that has already been freed.
  • Destructor: the routine a program calls to release a value's resources when it is done with it.
  • EDR (Endpoint Detection and Response): software on a machine that watches what programs do and reports suspicious behaviour.
  • Endpoint: a specific URL path that accepts requests.
  • Function pointer: a stored address saying which routine to jump to when a job needs doing.
  • Hash table: a data structure that stores entries in numbered slots and keeps a count of how many are in use.
  • Heap: the general-purpose pool of memory a program uses for data it creates while running.
  • HTTP 200: the standard status code meaning the request succeeded.
  • JSON: a structured text format that tools can read and write.
  • longjmp(): a C function that jumps abruptly back to a saved point, abandoning the current operation.
  • memory_limit: the PHP setting that caps how much memory a single request may use.
  • Multipart form: the request format used when a form includes a file upload, splitting the body into parts.
  • Opcache: a PHP feature that caches compiled code in memory to speed things up.
  • Parsing: reading raw request bytes and turning them into structured data the application can use.
  • Pointer: a note that says where a piece of data lives in memory.
  • Process tree: the parent-child relationship between running programs.
  • Reverse proxy: a server that sits in front of the real one and can filter traffic.
  • Segfault: the operating system killing a program because it touched memory it was not allowed to touch.
  • Session: how a website remembers who you are between requests.
  • Signal 11: the operating system's notification that a program crashed with a segmentation fault.
  • WAF (Web Application Firewall): a filter that inspects traffic before it reaches the application.
  • Web root: the folder the web server serves files from.
  • Worker: a long-lived helper process that handles requests one after another without restarting.
  • www-data: the low-privilege account web server processes usually run under on Linux.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.