Testing PHP2Shell Across Apache and PHP-FPM

After PHP2Shell was announced, I wanted to see whether CVE-2026-109619 could lead to command execution over HTTP in a complete web stack. I also wanted to know whether one exploit could work across different vulnerable PHP builds without build-specific calibration. I tested three lab deployments:

I tested PHP2Shell across three deployments:

  • WordPress with Apache mod_php;
  • Symfony with Apache mod_php;
  • Symfony with nginx and PHP-FPM.

My experiments focused on CVE-2026-109619. I tested how the PHP build, worker count, and execution model affected address disclosure and command execution over HTTP.

I also cover CVE-2026-109618 to distinguish its separate same-request teardown flaw. This was not the exploitation path demonstrated in my labs.

As explained in Cobalt’s PHP2Shell technical brief, a working proof of concept is not automatically portable to every production build.

What the lab showed

In the Apache tests, the exploit POST requests stopped in PHP’s multipart parser before WordPress or Symfony bootstrapped. Session upload progress stored a pointer to request data in worker-global state. A controlled out-of-memory condition (OOM) interrupted cleanup but left the worker alive.

A second request on the same worker consumed the stale pointer after PHP had freed the request heap. This demonstrates the CVE-2026-109619 path, not the separate CVE-2026-109618 teardown flaw.
The Apache chain leaked the Zend heap and libphp base addresses, then used build-specific offsets to execute a command over HTTP.

PHP-FPM behaved differently. A startup failure terminated the child, breaking the Apache sequence. Our Symfony replica used a post-startup path that redirected PHP’s file-session writer to a writable directory served as PHP by nginx. A later GET request executed the generated file. The corruption requests still required affinity to the same FPM child.

A diagram in the PHP-FPM section below compares the worker behavior in Apache and PHP-FPM.

What I tested

The WordPress 7.1.3 and Symfony 7.4.21 tests ran on PHP 8.4.26 with Apache mod_php. A separate Apache profile used Symfony 7.4.19 with PHP 8.3.21. The nginx and PHP-FPM replica also ran on PHP 8.3.21.

Lab

Stack

Result

Main lesson

WordPress

WordPress 7.1.3, PHP 8.4.26, Apache mod_php, one and four workers

Command execution through HTTP

The sequence did not need an upload form or a plugin vulnerability.

Symfony

Symfony 7.4.21, PHP 8.4.26, Apache mod_php

Command execution through HTTP

The framework change did not change the PHP memory problem.

Symfony build profile

Symfony 7.4.19, PHP 8.3.21, Apache mod_php, one and four workers

Command execution through HTTP after build-specific calibration

The PHP 8.4.26 offsets did not work without changes on PHP 8.3.21.

nginx and PHP-FPM

Symfony 7.4.19, PHP 8.3.21, nginx and PHP-FPM, one, four, and six workers

Build-specific disclosure and command execution under lab conditions

FPM needed different calibration, an output path, and a worker strategy.

The labs ran in Docker containers on a Linux x86_64 host. ASLR was enabled on the host..
The Apache labs used memory_limit=8M and post_max_size=32M.
The PHP-FPM lab used file-backed sessions, memory_limit=128M, and post_max_size=8M. The FPM execution path also required a test-only Symfony entry point and a writable directory that nginx served as PHP.

How the chain works

PHP parses multipart/form-data during request startup, before the application’s front controller runs. Session upload progress can create session state at this stage. PHP frees the request heap at the end of the request, but the worker may remain alive and process subsequent requests.

Figure 1 - Multipart and session processing happens before the application runs

In the Apache startup chain, request A published session state before hitting a fatal interruption. Cleanup did not clear the worker’s pointer to that state. Request B then had to reach the same worker and consume the stale pointer after request A’s heap had been freed. The FPM chain used a different post-startup producer, described below.

Figure 2 - The common setup occurs before the application, then the two vulnerabilities follow different lifecycles

The two CVEs are related, but they do not have to be chained.

CVE-2026-109618 involves incomplete state consumed during request shutdown.

CVE-2026-109619 crosses a request boundary. Request A stores a pointer to request-owned data in worker-global state. An OOM or fatal error interrupts cleanup, and request B uses the stale pointer before PHP resets it.

PHP request state : How I caused a controlled Out-of-Memory

post_max_size limits the POST body accepted by PHP, while memory_limit caps the memory available to process it.
An accepted multipart body can expand into much larger in-memory structures. A request without a usable declared length may pass the initial size check, while multipart parts containing many headers can further increase PHP’s memory usage.

Empty file fields do not count toward max_file_uploads, but PHP still creates the corresponding $_FILES metadata. Nested field names multiply this work across six parallel metadata structures.

Figure 3 - Several small-looking multipart structures can create disproportionate memory pressure inside PHP

By arranging the multipart fields, I caused a later allocation to hit memory_limit after the vulnerable state had been created. The failing allocation did not need to be the one that created that state.

Sate after the fatal error

CVE-2026-109619: an old pointer survives the request

CVE-2026-109619 is a memory-lifetime issue. During request A, PHP stores temporary data in the request heap and keeps a pointer to it in a worker-owned variable. When the request ends, PHP frees the request heap, but the worker remains alive. If the pointer is not cleared, it continues to reference invalid memory. This is a dangling pointer.

The producer stores the pointer during request A. If cleanup is interrupted, the pointer remains in worker-global state. The consumer runs during request B on the same worker and reads, frees, or otherwise uses the stale pointer before PHP resets it.

In our multipart sequence, session upload progress can act as both producer and consumer. The CVE is not limited to this feature. PHP also maintains worker-level state for errors, exceptions, objects, and extensions, which may retain stale pointers if cleanup is interrupted.

An OOM can trigger the interruption, but so can a parse failure, an uncaught error, a failed require, or an execution timeout.

CVE-2026-109618: shutdown uses incomplete data

CVE-2026-109618 is an initialization-order flaw in Zend HashTable, the internal structure PHP uses for arrays such as $_POST and $_FILES. Each entry is stored in a bucket containing a key and a value.

In the affected sequence, PHP exposes a new bucket before fully initializing its fields. If a fatal error occurs at that point, request shutdown may process the incomplete bucket as a valid entry. The simplified code below shows the critical order:

</> C


index = table->used++;

table->elements++;


bucket = table->data + index;

bucket->key = allocate_key(); /* may trigger a fatal error */


bucket->hash = hash;

bucket->value = value;

If allocate_key() triggers a fatal error, PHP never executes the remaining assignments. Because the used count has already been incremented, request shutdown processes the incomplete bucket as a live entry. The flaw is caused by the ordering between initialization and teardown. The relevant code is in PHP’s zend_hash.c.

Apache mod_php: with WordPress and Symfony

PHP can create the dangerous state before /index.php, WordPress, or Symfony runs. The application does not need an upload form, a call to move_uploaded_file(), or a vulnerable controller. Application-level validation cannot protect code that executes before the application starts.

The WordPress lab produced the following results:

  • Normal GET requests loaded WordPress and accessed its database, while exploit POST requests stopped in PHP’s parser before WordPress bootstrapped.

  • The sequence did not require a WordPress upload feature, plugin flaw, or theme flaw.

  • The worker returned command output over HTTP.

  • After the test, the site still processed a normal WordPress request with database access.

Symfony was tested in the same way. Normal GET requests booted the Symfony kernel and resolved a real route. The Apache exploit POST requests stopped after PHP parsed the request and did not depend on a Symfony controller.

These tests validated the deployment context. They did not measure the effect of a complete application request path on the exploit.

I also built an Apache mod_php profile with Symfony 7.4.19 and PHP 8.3.21 to isolate the effect of changing the PHP build while keeping the same SAPI. The PHP 8.4.26 exploit profile did not work without modification. PHP 8.3.21 required different symbol offsets, allocator geometry, state placement, and heap-reuse behavior. This test was separate from the nginx and PHP-FPM tests.

The production-style profiles used display_errors=Off. This hid errors from the HTTP response but did not correct the invalid memory state.

Why multiple workers reduced reliability

With one Apache worker, requests A and B are guaranteed to reach the same process. With four workers, request B may reach another child that does not contain the stale pointer.

Figure 4 - Both requests must reach the worker that holds the relevant state

In the lab, I kept three verified keep-alive connections busy and ran the sequence through the remaining Apache child. This produced repeatable results, and all four workers were restored after the test.

The test confirms that the condition can persist in a worker pool. It is not safe for production use because occupying workers can reduce capacity or cause an outage.

Address disclosure and build calibration with ASLR

ASLR was enabled in every reference test. It changed runtime addresses between runs but did not correct the underlying PHP memory flaw.

CVE-2026-109619: disclosure from an old pointer

At this stage, I had an old pointer but no ASLR bypass. Most incorrect heap layouts crashed the worker. I had to make request B reuse memory that request A released.

Request A left session state with a pointer to freed request memory. Request B used normal multipart allocations to reuse the same memory blocks. I put controlled string metadata in the reused area. PHP followed the old pointer and read the new contents as a longer string.

PHP put this incorrect string in the session cookie. The Set-Cookie header then contained an out-of-bounds read. The response contained real process pointers and controlled bytes.

The first useful disclosure gave a pointer into the Zend Memory Manager (Zend MM). Zend MM is PHP's internal allocator. I aligned the pointer to the expected heap boundary. This calculation gave the heap base and the location of our request data.

A second disclosure gave the address of zval_ptr_dtor. PHP uses this function to destroy a zval value. The function is in the loaded libphp module. Its address gave the runtime location of that module.

Figure 5 - In the CVE-2026-109619 path, controlled heap reuse turns the stale session pointer into two disclosures: the Zend heap base, then the loaded libphp base

Calibrating offsets for the tested build

I knew the exact libphp binary in each lab. I found the relative offset of zval_ptr_dtor in that binary. Then, I subtracted the offset from the HTTP disclosure. The result was a candidate libphp base. I checked its alignment and user-space range.

</> python


candidate_base = leaked_zval_ptr_dtor - profile.zval_ptr_dtor_offset


candidate_is_plausible = (

candidate_base % profile.expected_alignment == 0

and profile.user_address_min <= candidate_base < profile.user_address_max

)

This native x86_64 result shows the calculation:

</> python


leaked_zval_ptr_dtor = 0x71d9bb411b60

zval_ptr_dtor_offset = 0x64eb60


libphp_base = leaked_zval_ptr_dtor - zval_ptr_dtor_offset

assert libphp_base == 0x71d9badc3000

The calculated base matched the worker mapping. I checked the mapping after the HTTP calculation. The exploit client did not use the mapping as an input.

I recorded the libphp build ID and SHA-256 for each exploit profile. Offsets can change between builds with the same PHP version.

Native x86_64 result

The final Apache test used display_errors=Off. The two HTTP disclosures gave both runtime bases. The HTTP response contained the command output:


HTTP/1.1 200 OK

Content-Length: 54


uid=33(www-data) gid=33(www-data) groups=33(www-data)

The container identity did not change. The Apache error-log hash was the same before and after the command response. These checks showed that the expected worker returned the response and stayed available.

The first command-execution prototype did not meet this condition. It executed the command. Then, PHP tried to destroy the forged structure and crashed the worker.

The final version used two callbacks. The first called zif_passthru() to execute the command and return its output. The second called _zend_bailout() before PHP freed the forged structure.

Apache reliability after a new startup

A successful result does not mean that each new process has a usable heap layout. Four separate Apache startups failed the first disclosure checks. The fifth startup completed the sequence. In another test, the first process failed and the next process succeeded.

Our test program stopped when disclosed addresses did not match the expected profile boundaries. This check prevented execution attempts with unverified pointers.

Nginx and PHP-FPM required a different sequence

In our PHP 8.3.21 and Symfony 7.4.19 replica, the Apache startup sequence did not work. PHP-FPM terminated the affected child. A separate decoder sequence ran after startup. It kept the child alive and enabled a file write and command execution under the conditions below.

These results apply to the local replica. I did not send intrusive requests to the observed system.

HTTP and process boundaries

A normal request passes through these steps:

  1. nginx receives the HTTP request. It applies checks such as client_max_body_size.
  2. nginx converts the request into FastCGI records and sends them to an available PHP-FPM child.
  3. The child starts the PHP request, parses the multipart body, and initializes extensions. Then, it runs the Symfony front controller.
  4. During request shutdown, PHP frees request memory. A healthy child returns to the pool and can process another request.

The vulnerability crosses steps 3 and 4. The vulnerable code is one condition. The same child must also survive until a later request uses the invalid state.

Why the Apache startup chain stops under FPM

With Apache mod_php, PHP runs inside each Apache worker. After a request startup error, Apache runs the normal request-shutdown path. It can reuse the worker. An old pointer can still exist when request B reaches that worker.

With PHP-FPM, PHP runs in a separate worker pool. nginx sends requests to the pool through FastCGI. In the tested startup-error path, the affected FPM child exited. It did not return to the pool. The FPM master started a clean child with new process state.

The old pointer from request A disappeared with the terminated child. Request B could not use that child’s heap or global state. Thus, the Apache cross-request sequence stopped.

This result does not cover all PHP-FPM error paths. A fatal error after request startup can leave the child alive. Another cross-request sequence can then occur.

 

Figure 6: PHP-FPM discards state after a startup failure, but a fatal error after successful startup follows a different lifecycle

An error after startup can leave the FPM child alive

In the tested post-startup path, the FPM child survived a fatal error and processed a later request. This result does not apply to every error after startup.The alternate sequence had four stages:

  1. Routines such as session_start(), session_decode(), and unserialize() put temporary structures in the request heap. They also store pointers in persistent worker-global state.
  2. A fatal error stopped execution before PHP cleared the worker-level pointer.
  3. Request shutdown freed the request heap. The child stayed alive, leaving the pointer referring to freed memory.
  4. A later session upload-progress request reached the same child. It used the old decoder pointer before PHP reset it.

This producer ran after request startup. In our Symfony replica, a lab-only entry point called session_start(). It decoded a prepared file-backed session and caused a controlled OOM. The FPM child survived and processed the later request.

Lab result: a file write followed by execution

The lab used nginx, PHP 8.3.21 NTS, Symfony 7.4.19, and file-backed sessions. It disabled display_errors and used a fixed FPM pool. I calibrated the sequence with one worker. Then, I used four-worker and six-worker pools to examine worker affinity.

The FPM sequence did not directly execute a command from memory corruption. First, it used the memory problem to write a file. A separate HTTP request then executed that PHP file.

The sequence had these steps:

  1. Upload-progress requests prepared file-backed session data. The data contained controlled decoder records and the PHP text for the final file.
  2. The lab-only /fpm-index.php entry point called session_start(). Session decoding caused an OOM after startup. Decoder state stayed in the surviving child.
  3. Later upload-progress requests reached the same child. They reused freed decoder memory and used the old pointer.
  4. The corruption changed the destination of ps_files, PHP’s file-session writer. The destination changed from the normal session path to /var/www/html/public/proof/shell.php.
  5. PHP saved the controlled session data. The redirected writer created shell.php on the shared filesystem.
  6. The client sent GET /proof/shell.php?0=id. nginx sent the request to PHP-FPM. PHP executed the file and returned uid=33(www-data).

The prepared session contained <?php system($_GET[0]); ?>. The redirected writer saved that text in shell.php. The final request put id in query parameter 0. PHP-FPM executed the file. It read the command from $_GET[0] and returned the system() output in the HTTP response.

Figure 7: Worker affinity is required while corrupting the session-writer state. Once the PHP file exists on shared storage, the final GET can be handled by any available FPM child

The lab had a writable public/proof directory that nginx served as PHP. This directory was a required test condition. It gave the file write a path to command execution. Symfony and PHP-FPM do not create this condition by default.

Worker affinity applied to the requests that created and used the old decoder pointer. After shell.php existed on shared storage, any FPM child with access to the file could process the final GET.

The lab showed a file-write-to-execution sequence under these conditions. It did not show a general direct command-execution method inside PHP-FPM. Other FPM paths can possibly execute a command without a file. I did not test such a path.

Multiworker validation

The producer and consumer had to reach the same FPM child. HTTP keep-alive kept the connection between the client and nginx. It did not keep the connection between nginx and one FPM child.

In the lab, a dedicated endpoint kept all but one child busy. The sequence then reached the available child. These tests show that the sequence can work in a pool when I control worker affinity. They do not establish a general remote method or a success rate. Keeping production workers busy can interrupt service.

 

Pool configuration

Observed result

Four children

I identified four children and kept three busy. The writer used the lab-only PHP path. A request for the new file returned command output.

Six children, first run

I identified six children and kept five busy. A different heap layout stopped the file-write sequence.

Six children, new run

I kept five children busy. The file-write-to-execution sequence completed. The new PHP file returned uid=33(www-data).

 

How nginx changed the HTTP response

nginx is between the client and PHP-FPM. PHP-FPM sends a result to nginx through FastCGI. nginx then makes the HTTP response. A value inside an FPM child does not necessarily reach the client. nginx can reject, change, or discard it.

I tested three output methods in the native x86_64 replica:

Output method

What PHP-FPM produced

Measured client result

Raw binary bytes in a FastCGI header

FPM placed mapped-memory bytes in a response header.

nginx rejected the invalid upstream header and returned a 502 error. No bytes reached the client.

Disclosed memory through a lab-only response-body endpoint

FPM streamed mapped memory in the response body.

HTTP 200 with 1,343,207 client-body bytes. The same FPM child served the next request.

Pointer displayed by Symfony WebProfiler

The value reached $_FILES as an integer.

HTTP 200 with 77,289 bytes. The decimal value 132471168115328 represented 0x787b58eb2280, giving the heap base 0x787b58e00000.

The WebProfiler method gave the clearest result. nginx received printable text in the response body. This method still needed the profiler route, the correct build profile, session upload progress, and worker affinity.

An HTTP 413 response gives limited evidence. nginx usually makes this response before PHP receives the body. It shows that nginx rejected that request. It does not show that PHP has a patch. It does not show how nginx handles other multipart bodies.

Conclusion

WordPress and Symfony did not cause the memory problem in these labs. They affected the available routes, memory allocations, writable paths, and output paths.

The important conditions were in PHP and the surrounding stack. They included request parsing, SAPI behavior, worker lifetime, binary layout, nginx response handling, and filesystem permissions.
An assessment must keep these three claims separate:

  1. A component contains vulnerable code.
  2. A deployment makes a useful exploitation method available.
  3. An attacker can reliably execute code through HTTP.

PHP2Shell can reach all three stages. A version scanner usually gives only a version-based indication. A worker crash shows a process failure. Backend evidence must connect that failure to the vulnerable path.

A technical assessment must state which stage the test showed. It must also state the conditions of that result.

References

Back to Blog
About Christophe Bailleux
Christophe is a Cobalt Core pentester with over 24 years of experience in cybersecurity. His background includes web application pentesting, internal network assessments focused on Active Directory, and pentest team leadership. He has written for a French cybersecurity magazine on low-level systems security, covering memory corruption, exploit mitigations, and architecture-specific research on SPARC and PA-RISC. Today, he focuses on offensive security research and AI. More By Christophe Bailleux