PHP2Shell | How an AI Uncovered a 10-Year-Old Flaw Threatening 70% of the Web
Two memory-safety flaws in the PHP core interpreter let an unauthenticated attacker trigger an out-of-memory error during request parsing, corrupting internal state and potentially achieving remote code execution. The second flaw leaves stale pointers in a reused worker process, creating a use-after-free that an attacker could exploit with a follow-up request.
Thinuri Wickramarachchi Follow
Published on medium.com
Php2shell
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.
Context
PHP2Shell is the name given to a pair of critical zero-day vulnerabilities in the PHP core interpreter, tracked as CVE-2026-109618 and CVE-2026-109619, with a CVSS score of 9.2. They were disclosed in October 2026 and allow an unauthenticated attacker to execute code on a remote web server. The affected component is not a plugin, framework or CMS feature: it is the PHP core interpreter itself, the engine behind WordPress, Drupal, Joomla and a large share of the web.
The author frames the significance in four points:
- No authentication required: an attacker needs no username or password.
- Invisible in logs: standard web application logs show a normal
HTTP 200 OK. - Pre-execution exploitation: the attack can trigger in memory before the site's security plugins or application code ever run.
- AI-discovered: it was found through AI-assisted source code auditing, surfacing memory flaws that had sat hidden in the PHP core for over a decade.
To explain the bugs, the article first walks through how PHP handles memory, errors and requests.
Setup
The relevant preconditions are architectural:
- PHP running under PHP-FPM, where a pool of worker processes handles requests and is recycled over time. A single worker might handle 1,000 requests before restarting.
- A configured
memory_limit(the article uses 128M as its example), which is the guardrail the attack works against. - The ability to send crafted HTTP requests, in particular large file uploads or deeply nested POST form data, that drive the parser towards the memory limit.
The normal request lifecycle is described as a kitchen: PHP-FPM is a team of cooks (worker processes), and each request is an order.
- The request arrives: a worker process takes the request (for example POST form data or a file upload).
- Memory allocation: the cook reserves a cutting board (allocates temporary memory) to parse the incoming data.
- Execution: PHP runs the scripts (WordPress plugins, database calls).
- Cleanup: once the page is rendered and sent, the cook wipes the cutting board, resets everything and waits for the next request.
If a single request tries to use more RAM than memory_limit allows, PHP panics, throws an Out-Of-Memory (OOM) error and terminates the request.
Finding it
The flaw lives in how PHP recovers from that OOM condition. PHP is written in C, and when a fatal error or memory shortage occurs the program cannot simply continue: it jumps back to a safe recovery point using setjmp() and longjmp(). The article describes longjmp() as a teleporter button. When PHP starts processing a request it places a teleport pad (setjmp); if the server runs out of memory during request parsing, PHP presses the button (longjmp) and warps execution back to the error handler to clean up and abort.
The problem is what the cleanup routine finds when it arrives there.
For over 10 years these memory safety patterns went unnoticed by human auditors because they sit at the intersection of complex C macros, C library error-handling routines (setjmp/longjmp) and PHP's garbage collection. In mid-2026, researchers used advanced AI models trained on system-level code auditing to analyse the core PHP C source. The AI was instructed to map every execution path where longjmp() could interrupt memory state initialisation. It identified that PHP's request-lifecycle memory guarantees did not hold true during sudden OOM interruptions, which led directly to the discovery of PHP2Shell.

Exploitation
Vulnerability #1: CVE-2026-109618 (uninitialised cleanup)
When a complex HTTP request arrives, such as a large file upload or deeply nested POST form data, PHP initialises internal data structures step by step:
Step 1: mark structure as "Ready" → Step 2: allocate memory → Step 3: fill with valid pointers
If an attacker crafts a request that forces PHP to hit its memory_limit right between Step 1 and Step 3, PHP triggers a longjmp(). Execution warps instantly to the cleanup phase. The cleanup routine looks at the state, sees that Step 1 marked the structure as ready, and attempts to free memory referenced by pointers in that structure. Because Step 3 never happened, those pointers contain garbage memory addresses or null values. Reading or freeing garbage memory addresses leads to memory corruption, which gives an attacker the ability to manipulate execution flow and gain remote code execution.
Vulnerability #2: CVE-2026-109619 (stale global state)
Web servers recycle worker processes to save memory. When an OOM error triggers a longjmp(), PHP aborts the current request, but because the normal execution flow was abruptly skipped, global variables and pointers to freed memory survive in the worker.
When the next request, whether from an innocent visitor or the attacker, arrives at that same worker process:
- The worker process accepts the new request.
- Its internal memory management still holds pointers to memory allocated during the previous failed request, which has now been freed.
- This creates a use-after-free (UAF) scenario.
An attacker can deliberately send Request A to corrupt and poison the worker's internal state, then immediately send Request B to hijack the stale state, overwrite function pointers and execute arbitrary code on the operating system.
The attack sequence
The article introduces the attack sequence with a diagram:

Why standard security fails to detect it
- No application logs: PHP crashes internally during the engine lifecycle, or handles the error via fallback paths, before the application (for example WordPress) can log an exception.
- Returns HTTP 200: depending on how web servers such as Apache or Nginx communicate with the PHP worker process during certain memory error states, the front-facing web server may log an
HTTP 200 OKresponse while the background worker process is exploited.
Root cause
The mistake is in the PHP core's error-recovery design. The longjmp() escape hatch aborts request parsing at an arbitrary point, but the cleanup path trusts state that was set before the interruption. A structure marked ready in Step 1 is treated as fully initialised even though allocation and pointer population (Steps 2 and 3) never completed, so cleanup frees garbage or null pointers. Separately, the abrupt jump skips the normal teardown, leaving global variables and dangling pointers alive in a recycled worker process, which turns the next request on that worker into a use-after-free.
Existing defences do not help because the corruption happens inside the interpreter, below the application. Application-level controls, including security plugins, never get a chance to run, and the front-facing server can record a successful HTTP 200 OK while the worker is compromised.
Impact
An unauthenticated attacker can achieve remote code execution on a remote web server running a vulnerable PHP build. Because the flaws are in the PHP core interpreter, the exposure is not tied to one application: the article estimates that roughly 70% of the web is served by PHP, and names WordPress, Drupal and Joomla as systems built on it. The attack works by sending crafted requests that drive parsing into the memory limit, with the stale-state variant relying on a second request reaching the same recycled worker process. The article notes that the front-facing logs may show nothing more than a normal HTTP 200 OK.
Fix
Application-level fixes, such as updating WordPress plugins, will not protect you, because the flaws are inside the PHP core interpreter. The underlying runtime engine must be fixed.
1. Upgrade PHP immediately
The official PHP security team released emergency patches. Update to one of the following safe versions:
- PHP 8.5.12 or higher
- PHP 8.4.27 or higher
- PHP 8.3.36 or higher
- PHP 8.2.35 or higher
PHP 7.x and 8.1 are End-of-Life and do not receive official full upstream releases; legacy systems require OS vendor backports or migration to a supported PHP version.
2. Mitigation strategies if patching is delayed
These server configuration changes reduce memory pressure and limit attack vectors:
- Remove finite PHP memory limits for workers (use with caution): setting
memory_limit = -1inphp.iniprevents PHP's internal OOM handler from triggering. You must then enforce memory bounds at the OS level (for example Linuxcgroup v2or systemd limits) so the server does not run out of system RAM. - Reduce input pressure:
; Lower maximum POST request size
post_max_size = 8M
; Disable session upload progress if unused
session.upload_progress.enabled = 0
; Turn off public error display
display_errors = Off
- Recycle workers frequently: lower
pm.max_requestsin the PHP-FPM configuration (for examplepm.max_requests = 500). This forces worker processes to destroy themselves and restart more often, wiping stale global state before it can be exploited.
Variants to test
The report does not describe testing against other targets.
- OOM during partial initialisation: send large file uploads or deeply nested POST bodies sized to cross
memory_limitmid-parse. A positive result is a request that produces no application-level error log entry yet leaves the worker in an abnormal state, for example a subsequent request on the same worker behaving unexpectedly. - Stale-state reuse across requests: send a request designed to abort via OOM, then immediately send a second request and observe whether it is served by the same worker with corrupted internal state. A positive result is a crash, a corrupted response, or evidence that pointers from the aborted request are still referenced.
- Logging blind spots: compare what the front-facing web server records against what the PHP worker actually did during memory-error states. A positive result is an
HTTP 200 OKin the access log for a request that triggered an internal OOM abort. - Worker recycling behaviour: check
pm.max_requestsand worker lifetime on the target. A high value means stale state survives longer between requests, which widens the window for the two-request sequence.
Key takeaway
PHP2Shell is a reminder of modern software complexity: even decades-old, heavily tested open-source engines can harbour memory-safety flaws deep in their low-level runtime lifecycle. As AI tools lower the barrier to discovering these intricate edge cases, rapid patching and defence-in-depth monitoring, such as EDR and OS-level containment, matter more than ever.
What happened, in plain words
In October 2026, a write-up by Thinuri Wickramarachchi described two serious security bugs in PHP, the programming language that runs a very large part of the web. The bugs were given the nickname PHP2Shell and two official tracking numbers, CVE-2026-109618 and CVE-2026-109619. A CVE number is like a case number that the security world gives to a publicly known flaw so everyone can talk about the same thing. The pair was rated 9.2 on the CVSS scale, which is a standard way of scoring how bad a flaw is; 9.2 is very high.
What makes these bugs serious is that an attacker does not need a username or password. They only need to be able to send web requests to a server that runs a vulnerable version of PHP. If the attack works, the attacker can run their own code on that server. In security language this is called remote code execution, often shortened to RCE: someone on the internet gets your server to execute commands of their choosing.
The write-up makes four points about why this is unusual:
- No authentication required: an attacker needs no username or password.
- Invisible in logs: standard web application logs show a normal
HTTP 200 OK. - Pre-execution exploitation: the attack can trigger in memory before the site's security plugins or application code ever run.
- AI-discovered: it was found through AI-assisted source code auditing, surfacing memory flaws that had sat hidden in the PHP core for over a decade.
To understand any of that, you first need a picture of what PHP actually does when someone visits a website, and what happens when it runs out of memory. That is where the article starts.
1. The setting: how web servers think
When you open a web page, your browser sends a request to a server somewhere. The server is a computer that stays switched on and answers requests. The software that answers is often a web server such as Apache or Nginx, and behind it sits the program that actually builds the page. For PHP sites, that program is usually PHP-FPM, short for FastCGI Process Manager.
A useful comparison from the article: imagine a restaurant kitchen. PHP-FPM is a team of cooks, and each cook is a worker process, a small copy of the PHP program that handles one request at a time. When a visitor loads a page, an order comes in.
The normal request lifecycle is described in four steps:
- The request arrives: a worker process takes the request (for example POST form data or a file upload).
- Memory allocation: the cook reserves a cutting board (allocates temporary memory) to parse the incoming data.
- Execution: PHP runs the scripts (WordPress plugins, database calls).
- Cleanup: once the page is rendered and sent, the cook wipes the cutting board, resets everything and waits for the next request.
A few words in there need unpacking. POST form data is what your browser sends when you fill in a form and press submit; the data travels in the body of the request rather than in the address bar. A file upload is the same idea with a file attached. To parse incoming data means to read it and turn it into structures the program can work with, for example splitting a form into field names and values. Memory is the working space a program uses while it runs, and allocating memory means reserving a piece of it for a purpose.
To stop one greedy request from eating all the server's RAM, PHP has a safety limit called memory_limit. The article uses 128M as its example, meaning 128 megabytes. If a single request tries to use more RAM than allowed, PHP panics, throws an Out-Of-Memory (OOM) error and terminates the request. Think of it as a rule in the kitchen: no cook may take more than one shelf of ingredients, and if they try, the order is cancelled on the spot.
2. The trap: the longjmp() escape hatch
PHP itself is written in an older language called C. In C, when something fatal happens, such as running out of memory, the program cannot simply carry on as if nothing went wrong. It has to jump back to a safe place where it knows how to clean up. C provides two functions for this: setjmp() and longjmp().
The article describes longjmp() as a teleporter button:
- When PHP starts processing a request, it places a teleport pad (
setjmp). - If at any point during request parsing the server runs out of memory, PHP presses the button (
longjmp) and instantly warps execution back to the error handler to clean up and abort.
So far, so sensible. The problem is what the cleanup routine finds when it arrives at the other end. That is the heart of both bugs.

The image sits at the top of the write-up, under the subtitle that names the two CVEs and sums up the mechanism: memory limits, longjmp(), and stale states leading to unauthenticated remote code execution.
3. Vulnerability #1: CVE-2026-109618 (uninitialised cleanup)
When a complex HTTP request comes in, such as a large file upload or deeply nested POST form data, PHP builds its internal data structures step by step. The article lays the order out like this:
Step 1: mark structure as "Ready" → Step 2: allocate memory → Step 3: fill with valid pointers
A data structure is just an organised bundle of related values inside a program. A pointer is a value that says where in memory something lives, like a house address written on a piece of paper. Marking a structure as ready before filling it in is like writing "table 4 is set" on the kitchen board before the plates have actually been put down.
Now the attack. If an attacker crafts a request that forces PHP to hit its memory_limit right between Step 1 and Step 3, PHP triggers a longjmp(). Execution warps instantly to the cleanup phase. The cleanup routine looks at the state, sees that Step 1 marked the structure as ready, and tries to free the memory that the pointers in that structure refer to. But Step 3 never happened, so those pointers contain garbage memory addresses or null values. A null value means "points at nothing".
Reading or freeing garbage memory addresses leads to memory corruption: the program starts treating random bytes as if they were meaningful addresses, and an attacker can use that confusion to steer what the program does next. In this case it gives the attacker the ability to manipulate execution flow and gain remote code execution.
Why would an attacker want to hit the limit at that exact moment? Because the cleanup code trusts a flag that was set too early. The attacker's job is simply to make the request big and complicated enough that memory runs out in the middle of the setup, not before and not after.
4. The zombie worker: stale state across requests
Vulnerability #2: CVE-2026-109619 (stale global state)
Web servers recycle worker processes to save computer memory. A single PHP worker process might handle 1,000 requests before restarting. Recycling is efficient, but it means a worker carries things over from one request to the next.
When an Out-Of-Memory error triggers a longjmp(), PHP aborts the current request. However, because the normal execution flow was abruptly skipped, global variables and pointers pointing to freed memory survive. A global variable is a value that lives for the whole life of the process rather than belonging to one request. "Freed" memory is memory the program has handed back, but a leftover pointer can still claim it is there, like an old address label on a parcel that has already been delivered.
When the next request, whether from an innocent visitor or the attacker, arrives at that same worker process:
- The worker process accepts the new request.
- Its internal memory management still holds pointers to memory allocated during the previous failed request, which has now been freed.
- This creates a use-after-free (UAF) scenario.
Use-after-free means exactly what it sounds like: the program uses a piece of memory after giving it back. If someone else has since put their own data there, the program reads or writes the wrong thing.
An attacker can deliberately send Request A to corrupt and poison the worker's internal state, then immediately send Request B to hijack the stale state, overwrite function pointers and execute arbitrary code on the operating system. A function pointer is a pointer that says which piece of code to run next; overwriting one is a classic way to make a program run code of your choosing.
5. The attack sequence: step by step
The article introduces the attack sequence with a diagram:

The diagram appears right where the write-up introduces the sequence.
Why standard security fails to detect it
- No application logs: PHP crashes internally during the engine lifecycle, or handles the error via fallback paths, before the application (for example WordPress) can log an exception.
- Returns HTTP 200: depending on how web servers such as Apache or Nginx communicate with the PHP worker process during certain memory error states, the front-facing web server may log an
HTTP 200 OKresponse while the background worker process is exploited.
HTTP 200 OK is the status code a web server sends when a request succeeded. Seeing it in a log normally means "all fine". Here it can mean the opposite, because the failure happened below the layer that writes the log. An exception is an error a program reports about itself; if the program never gets that far, nothing is reported.
6. How it was revealed: the AI auditing breakthrough
For over 10 years, these memory safety patterns went unnoticed by human auditors because they sit at the intersection of complex C macros, C library error-handling routines (setjmp/longjmp) and PHP's garbage collection. A macro is a shorthand in C source code that the compiler expands into other code before building the program, which makes the code harder to read by eye. Garbage collection is the part of a runtime that finds memory no longer in use and reclaims it.
In mid-2026, researchers leveraged advanced AI models trained on system-level code auditing to analyse the core PHP C source code. The AI was instructed to map every execution path where longjmp() could interrupt memory state initialisation. It identified that PHP's request-lifecycle memory guarantees did not hold true during sudden OOM interruptions, leading directly to the discovery of PHP2Shell.
In plain terms: instead of a person reading millions of lines, a model was pointed at the source and asked a very specific question, namely where the emergency jump could land in the middle of setup. That question is what surfaced the flaw.
7. How to protect your applications
Because these flaws are inside the PHP core interpreter, application-level fixes (like updating WordPress plugins) will not protect you. You must fix the underlying runtime engine. The interpreter is the program that reads and runs PHP code; a plugin sits on top of it and never gets a say in what happens inside it.
1. Upgrade PHP immediately
The official PHP security team released emergency patches. Update your PHP installation to one of the following safe versions:
- PHP 8.5.12 or higher
- PHP 8.4.27 or higher
- PHP 8.3.36 or higher
- PHP 8.2.35 or higher
PHP 7.x and 8.1 are End-of-Life (EOL) and do not receive official full upstream releases; legacy systems require OS vendor backports or migration to a supported PHP version. End-of-Life means the version no longer gets fixes. A backport is when a vendor takes a fix written for a newer version and applies it to an older one they still support.
2. Mitigation strategies (if patching is delayed)
If you cannot upgrade immediately, apply these server configuration changes to reduce memory pressure and limit attack vectors:
- Remove finite PHP memory limits for workers (use with caution): setting
memory_limit = -1inphp.iniprevents PHP's internal OOM handler from triggering. Warning: you must enforce memory bounds at the OS level (e.g. Linuxcgroup v2or systemd limits) so your server doesn't run out of system RAM. - Reduce input pressure:
; Lower maximum POST request size
post_max_size = 8M
; Disable session upload progress if unused
session.upload_progress.enabled = 0
; Turn off public error display
display_errors = Off
Line by line, this is a snippet of php.ini, the main PHP configuration file:
-
; Lower maximum POST request sizeis a comment, ignored by PHP; it explains the next line. -
post_max_size = 8Mcaps how large a submitted form or upload may be at 8 megabytes, so a single request cannot push the parser as hard. -
; Disable session upload progress if unusedis another comment. -
session.upload_progress.enabled = 0turns off a feature that tracks upload progress in the session; if you do not use it, switching it off removes a way for uploads to create extra state. -
; Turn off public error displayis a comment. -
display_errors = Offstops PHP from printing error details to visitors, so internal failures are not shown on the page. -
Recycle workers frequently: lower
pm.max_requestsin your PHP-FPM configuration (for examplepm.max_requests = 500). This forces worker processes to destroy themselves and restart more often, wiping any stale global state before it can be exploited.
That last setting targets the second bug: if a worker only lives for 500 requests, it restarts more often, wiping stale global state before it can be exploited.
Key takeaway
PHP2Shell serves as a stark reminder of modern software complexity. Even decades-old, heavily tested open-source engines can harbour memory-safety flaws deep in their low-level runtime lifecycle. As AI tools lower the barrier to discovering these intricate edge cases, maintaining rapid patching and defence-in-depth monitoring (like EDR and OS-level containment) is more critical than ever. Defence in depth means layering several independent protections so that one failure does not mean total compromise. EDR, endpoint detection and response, is software that watches a machine for suspicious behaviour and reacts to it.
Glossary
- PHP: a programming language widely used to build websites and the software behind them.
- PHP-FPM (FastCGI Process Manager): the part of a PHP setup that keeps a pool of worker processes ready to handle incoming requests.
- Worker process: a running copy of a program that handles one request at a time and is reused for later requests.
- Request: a message a browser or other client sends to a server asking for something.
- POST form data: data submitted through a web form, carried in the body of the request.
- File upload: a request that carries a file from the client to the server.
- Parse: to read raw incoming data and turn it into structured values a program can use.
- Memory: the working space a running program uses to hold data temporarily.
- Allocate: to reserve a piece of memory for a purpose.
- Free: to hand a piece of memory back so it can be reused.
memory_limit: a PHP setting that caps how much memory one request may use.- Out-Of-Memory (OOM) error: the failure that occurs when a request tries to use more memory than its limit allows.
- C: an older, low-level programming language in which PHP itself is written.
setjmp()/longjmp(): a pair of C functions that record a safe point and later jump back to it, used to recover from fatal errors.- Data structure: an organised bundle of related values inside a program.
- Pointer: a value that records where in memory something is stored.
- Null value: a value that points at nothing.
- Garbage memory address: a meaningless address left in a pointer that was never properly filled in.
- Memory corruption: a state where a program reads or writes memory it should not, letting an attacker influence its behaviour.
- Remote code execution (RCE): an attack in which someone on the network gets a server to run code of their choosing.
- Global variable: a value that lives for the whole life of a process rather than for a single request.
- Use-after-free (UAF): using memory after it has been handed back, so the program may read or write someone else's data.
- Function pointer: a pointer that says which piece of code should run next.
- CVE: a public identifier given to a known security flaw so it can be tracked and discussed.
- CVSS: a standard scoring system for how severe a security flaw is.
- Zero-day: a flaw that was not publicly known, and for which no fix existed, at the time it was found.
- HTTP 200 OK: the status code a web server returns when a request succeeded.
- Exception: an error a program reports about itself.
- Macro: a shorthand in C source code that is expanded into other code before the program is built.
- Garbage collection: the part of a runtime that finds memory no longer in use and reclaims it.
- Interpreter: the program that reads and runs code written in a language such as PHP.
- Patch: a fix released by the software's maintainers.
- End-of-Life (EOL): a version that no longer receives fixes.
- Backport: applying a fix written for a newer version to an older version still in use.
php.ini: the main configuration file for PHP.pm.max_requests: a PHP-FPM setting for how many requests a worker handles before it restarts.- Defence in depth: layering several independent protections so one failure does not mean total compromise.
- EDR (endpoint detection and response): software that watches a machine for suspicious behaviour and reacts to it.
- cgroup v2 / systemd limits: operating-system features that cap how much memory a process may use.