PHP2Shell: Simplest Explanation
Two vulnerabilities in PHP's core runtime involve mishandling of memory during request processing: one from an out-of-memory condition during initialisation and one from a use-after-free. An unauthenticated attacker could send a crafted HTTP request to trigger memory corruption and, under suitable conditions, achieve remote code execution.
medium.com
Published on medium.com
PHP
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
PHP is the server-side language behind a large share of the web: it processes forms, manages sessions and talks to databases. A simplified request path looks like this:
Your browser → Web server → PHP runtime → Website application → Database
The PHP runtime is the software that actually executes PHP code. Applications such as WordPress, Drupal and Joomla build their core functions on top of it; plugins and themes add functionality, but the runtime still performs the execution. That distinction matters when the flaw lives in PHP itself: if a WordPress plugin is vulnerable, updating or removing the plugin may fix it, but if the bug is in PHP's core engine, updating WordPress alone will not necessarily protect the server.
PHP2Shell is the name given to two critical vulnerabilities in PHP, disclosed on 21 October 2026 and tracked as CVE-2026-109618 and CVE-2026-109619. They affect PHP's core runtime and can allow unauthenticated attackers to execute code remotely. The researchers who investigated them demonstrated exploitation against popular web applications including WordPress, Drupal and Joomla. Both received a CVSS v4.0 severity score of 9.2 in the initial advisories.

Setup
The write-up describes the flaws at a conceptual level and does not walk through a lab build, so there are no accounts, roles or tool versions to reproduce here. What it does give is the shape of the attack: a specially crafted HTTP request, sent without logging in, that reaches PHP's request-processing and memory-management code before the website's own application code begins executing. Success depends on the PHP build, the memory layout and other environmental factors.
Finding it
Both vulnerabilities come down to PHP mishandling its own internal memory. The two mechanisms are out-of-memory errors and use-after-free conditions, and the write-up treats them separately because each maps to one CVE.

The first flaw: memory allocation failure
Every running program needs memory to store data and perform operations. When PHP processes an HTTP request it may allocate memory for form fields, uploaded files, session information and other data. A process can run out of the memory available to it, or an operation can fail because it cannot allocate the memory it needs.
Normally software handles this safely: it stops the operation, cleans up anything partially created and leaves the program in a consistent state. The problem is when that cleanup does not happen correctly. PHP begins initialising an internal data structure, a memory allocation fails and interrupts the operation, but the runtime's internal bookkeeping does not accurately reflect what was completed. Later, cleanup code assumes the data structure is valid. That mismatch can cause PHP to access memory incorrectly. For CVE-2026-109618, the researchers demonstrated that this memory-corruption problem could be exploited to achieve remote code execution.
The second flaw: use-after-free
The hotel analogy in the write-up is a good one. A hotel assigns Room 204 to a guest. The guest checks out and the room is cleaned and made available to someone else, but the hotel's internal system still says the original guest occupies Room 204. A staff member later consults that outdated record and assumes the room still belongs to the original guest.
A program allocates memory for an object and stores a reference to it. Later it releases that memory so it can be reused, but another part of the program still holds a reference to the original location. If the program uses that reference again, it may access memory that no longer contains the original object. That can cause unexpected behaviour, crashes, memory corruption and, in some cases, code execution.
In PHP, internal state is maintained while processing requests. Some of that state belongs only to the current request; when the request finishes, the associated memory should be released and any references to it cleared. Certain error-handling paths can interrupt this process. Under the conditions described by the researchers, PHP can retain references to request-related memory after that memory has been freed. A subsequent request handled by the same worker may then encounter the stale reference before PHP has properly reset the relevant state. If an attacker can influence the memory that gets reused, the consequences become much more serious.
The important sequence is:
- PHP begins processing a request.
- An error interrupts the expected processing or cleanup sequence.
- Memory is released, but an internal reference survives.
- The same worker later processes another request.
- The stale reference is used in an unsafe way.
- Under suitable conditions, the attacker can turn the memory corruption into code execution.
The write-up is explicit that this is a simplified explanation of the underlying problem, not a guarantee that every vulnerable request will produce a successful exploit. The actual exploitation process is considerably more complicated.
Exploitation
Step 1: Send a specially crafted request
The attacker sends an HTTP request containing carefully chosen data. PHP processes some of this data before the website's application code begins executing. Under the right conditions, the request can trigger one of the vulnerable code paths without requiring the attacker to log in.
Step 2: Trigger the memory-management flaw
The attacker needs PHP to reach the vulnerable state. For CVE-2026-109618 this involves an out-of-memory condition during initialisation. For CVE-2026-109619 it involves PHP using an outdated reference to memory that has already been freed.
Step 3: Influence memory
When memory is freed it can be reused for other data. If an attacker can influence what occupies that memory, they may be able to manipulate how the vulnerable code behaves. Researchers use techniques such as heap grooming to make memory allocation patterns more predictable. Success depends on the PHP build, memory layout and other environmental factors.
Step 4: Turn memory corruption into code execution
Modern operating systems use protections such as Address Space Layout Randomization (ASLR) to make memory addresses unpredictable. To bypass this, the attacker first leverages PHP's stale global state to trigger a tiny memory leak, which reveals the server's secret memory layout. With ASLR defeated, the attacker uses the corrupted memory path to overwrite an internal PHP function pointer, redirecting the engine to execute operating-system commands instead of standard PHP code.
Root cause
The mistake is in PHP's core runtime, not in any application built on it. In the first case, a failed memory allocation during initialisation leaves internal bookkeeping out of step with reality, and later cleanup trusts a structure that was never fully built. In the second, error-handling paths interrupt the release of request-scoped state, so a worker keeps a reference to memory that has already been freed and reuses it on a later request. Because the flaw sits below the application layer, a carefully written application still runs on a vulnerable runtime. The write-up does not detail the specific code changes or the defences that failed; the bypass of ASLR described above is part of the exploitation path, not a defence that stopped the bug.
Impact
The vulnerabilities can allow unauthenticated attackers to execute code remotely, and the researchers demonstrated exploitation against popular web applications including WordPress, Drupal and Joomla. The write-up hedges the outcome: exploitation depends on the PHP build, memory layout and other environmental factors, and not every vulnerable request will succeed. Where it does succeed, the attacker can turn the memory corruption into code execution.
Fix
The initial fixes were released for PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35. The write-up advises checking the latest official advisories before relying on those version numbers. For anyone maintaining a PHP application, the priorities are:
- Check your PHP version: identify the runtime actually serving web requests, not just the command-line version.
- Install the relevant security updates: follow the official PHP or operating-system vendor advisories.
- Review suspicious activity: look for unusual PHP worker crashes, memory errors, unexpected child processes and suspicious outbound connections.
You can check the PHP version available in your terminal with:
php -v
Keep in mind that a website may use a different PHP installation from the one on your command line.
Variants to test
- Compare CLI and web runtime versions. Run
php -vand compare it with the version the web server actually loads (for example through aphpinfo()page on a staging host you control). - Exercise allocation-failure paths. A positive result is a crash or error that leaves the worker in an inconsistent state rather than a clean failure.
- Exercise request-boundary cleanup. A positive result is behaviour on a later request that depends on data from an earlier, failed one.
- Watch for the post-exploitation signals. A positive result is a PHP worker spawning a shell or connecting somewhere it never normally would.
What happened, in plain words
Imagine you have spent weeks locking up your house. You fixed the broken window, you changed the locks, you put a new alarm on the door. Then someone walks up to the front door, says a few words in a strange order, and the door simply opens. They did not break anything. They did not need a key. The door itself had a flaw in how it was built, and no amount of work on the rooms inside the house could fix that.
That is roughly what happened with PHP2Shell. It is the name given to two critical vulnerabilities in PHP, disclosed on 21 October 2026 and tracked as CVE-2026-109618 and CVE-2026-109619. They affect PHP's core runtime and can allow unauthenticated attackers to execute code remotely. The researchers who investigated them demonstrated exploitation against popular web applications including WordPress, Drupal and Joomla. Both received a CVSS v4.0 severity score of 9.2 in the initial advisories.

In this article I want to explain what that means without assuming you know anything about servers, memory or security. If you can use a browser and a computer, you can follow along. I will explain every term the first time it appears, and I will keep the order of the original technical explanation so that nothing is skipped.
Context
What PHP is
PHP is the server-side language behind a large share of the web. "Server-side" means the code runs on the computer that hosts the website, not in your browser. When you fill in a login form and press a button, your browser sends what you typed to a web server, and PHP code on that server checks it, perhaps against a database, and decides what to send back.
A simplified request path looks like this:
Your browser → Web server → PHP runtime → Website application → Database
Read that arrow by arrow. Your browser is the program on your computer. The web server is the program on the hosting machine that accepts connections from browsers. The PHP runtime is the software that actually executes PHP code. The website application is the code written by the site's developers, for example a WordPress installation. The database is where information such as user accounts and posts is stored.
Applications such as WordPress, Drupal and Joomla build their core functions on top of the PHP runtime. Plugins and themes add functionality, but the runtime still performs the execution. Think of the runtime as the engine of a car and the application as the bodywork, seats and radio. If the radio is broken you can replace the radio. If the engine has a design fault, a new radio will not help.
That distinction matters when the flaw lives in PHP itself: if a WordPress plugin is vulnerable, updating or removing the plugin may fix it, but if the bug is in PHP's core engine, updating WordPress alone will not necessarily protect the server.
What the two vulnerabilities are
PHP2Shell is the name given to two critical vulnerabilities in PHP, disclosed on 21 October 2026 and tracked as CVE-2026-109618 and CVE-2026-109619. A CVE is a public catalogue number for a known security flaw, so that people around the world can refer to the same bug unambiguously. "Critical" is a severity label meaning the flaw is about as serious as it gets.
"Unauthenticated" means the attacker does not need an account or a password. "Execute code remotely" means they can make the server run commands of their choosing from somewhere else on the internet.
CVSS is a standard scoring system for the severity of a vulnerability, and 9.2 out of 10 sits in the critical band.
Setup
The write-up describes the flaws at a conceptual level and does not walk through a lab build, so there are no accounts, roles or tool versions to reproduce here. What it does give is the shape of the attack: a specially crafted HTTP request, sent without logging in, that reaches PHP's request-processing and memory-management code before the website's own application code begins executing.
Two terms there. An HTTP request is the message your browser sends to a web server when you visit a page or submit a form; it contains a method such as GET or POST, a path, some headers and sometimes a body. "Specially crafted" means the attacker builds that message by hand, with unusual contents, instead of letting a browser produce a normal one. "Before the website's own application code begins executing" means the malicious message is handled by PHP itself, the engine, before WordPress or Drupal gets a chance to look at it. That is why a well-written application cannot defend itself here.
Success depends on the PHP build, the memory layout and other environmental factors. In other words, the same request will not behave identically on every server.
Finding it
Both vulnerabilities come down to PHP mishandling its own internal memory. The two mechanisms are out-of-memory errors and use-after-free conditions, and the write-up treats them separately because each maps to one CVE.

A quick word on memory
Before the two flaws, a short explanation of what memory is in this context. Every running program needs memory to store data and perform operations. You can picture memory as a very large sheet of numbered lockers. A program asks the operating system for a locker, writes something in it, and later says it is done with that locker so someone else can use it. The number of a locker is called an address. Programs keep small notes saying "the data I care about is in locker 4711". Those notes are called references or pointers.
When PHP processes an HTTP request it may allocate memory for form fields, uploaded files, session information and other data. "Allocate" simply means reserving a locker. A session is how a website remembers you between page loads, usually by giving your browser a small piece of data called a cookie; the server keeps the matching information in its memory.
A process can run out of the memory available to it, or an operation can fail because it cannot allocate the memory it needs. That is like arriving at the locker desk and being told there are no free lockers left.
The first flaw: memory allocation failure
Normally software handles this safely: it stops the operation, cleans up anything partially created and leaves the program in a consistent state. If you start unpacking boxes into a room and discover the room is full, the tidy response is to put everything back where it came from and leave the room as you found it.
The problem is when that cleanup does not happen correctly. PHP begins initialising an internal data structure, a memory allocation fails and interrupts the operation, but the runtime's internal bookkeeping does not accurately reflect what was completed. Later, cleanup code assumes the data structure is valid. That mismatch can cause PHP to access memory incorrectly.
In everyday terms: PHP starts building a piece of furniture, runs out of screws halfway, but its checklist still says the furniture is finished. Later a colleague reads the checklist, walks over to the half-built furniture and leans on it. Something breaks.
For CVE-2026-109618, the researchers demonstrated that this memory-corruption problem could be exploited to achieve remote code execution. Memory corruption means a program reads or writes memory it should not, so the data there no longer means what the program expects.
The second flaw: use-after-free
The hotel analogy in the write-up is a good one. A hotel assigns Room 204 to a guest. The guest checks out and the room is cleaned and made available to someone else, but the hotel's internal system still says the original guest occupies Room 204. A staff member later consults that outdated record and assumes the room still belongs to the original guest.
A program allocates memory for an object and stores a reference to it. Later it releases that memory so it can be reused, but another part of the program still holds a reference to the original location. If the program uses that reference again, it may access memory that no longer contains the original object. That can cause unexpected behaviour, crashes, memory corruption and, in some cases, code execution. This class of bug is called use-after-free: the program uses something after it has given it back.
In PHP, internal state is maintained while processing requests. Some of that state belongs only to the current request; when the request finishes, the associated memory should be released and any references to it cleared. Certain error-handling paths can interrupt this process. Under the conditions described by the researchers, PHP can retain references to request-related memory after that memory has been freed. A subsequent request handled by the same worker may then encounter the stale reference before PHP has properly reset the relevant state.
A worker here is one of the processes the web server keeps running to handle incoming requests, like a bank clerk serving customers one after another at the same window. If the clerk keeps a note about the previous customer on the desk, the next customer may be served using the wrong note. If an attacker can influence the memory that gets reused, the consequences become much more serious.
The important sequence is:
- PHP begins processing a request.
- An error interrupts the expected processing or cleanup sequence.
- Memory is released, but an internal reference survives.
- The same worker later processes another request.
- The stale reference is used in an unsafe way.
- Under suitable conditions, the attacker can turn the memory corruption into code execution.
The write-up is explicit that this is a simplified explanation of the underlying problem, not a guarantee that every vulnerable request will produce a successful exploit. The actual exploitation process is considerably more complicated.
Exploitation
Step 1: Send a specially crafted request
The attacker sends an HTTP request containing carefully chosen data. PHP processes some of this data before the website's application code begins executing. Under the right conditions, the request can trigger one of the vulnerable code paths without requiring the attacker to log in.
Why this step matters: the attacker never needs an account, a password or any access to the site's admin area. They only need to be able to reach the server over the network, which is what any ordinary visitor can do.
Step 2: Trigger the memory-management flaw
The attacker needs PHP to reach the vulnerable state. For CVE-2026-109618 this involves an out-of-memory condition during initialisation. For CVE-2026-109619 it involves PHP using an outdated reference to memory that has already been freed.
In other words, the request is shaped so that the engine stumbles into the exact situation described above: either the locker desk runs out of lockers at the wrong moment, or the clerk picks up the note from the previous customer.
Step 3: Influence memory
When memory is freed it can be reused for other data. If an attacker can influence what occupies that memory, they may be able to manipulate how the vulnerable code behaves. Researchers use techniques such as heap grooming to make memory allocation patterns more predictable.
Heap grooming means deliberately arranging what goes into the freed lockers, in a chosen order, so that the program later finds the attacker's data where it expected its own. It is like making sure that when the hotel room is re-let, it is re-let to someone working for you. Success depends on the PHP build, memory layout and other environmental factors.
Step 4: Turn memory corruption into code execution
Modern operating systems use protections such as Address Space Layout Randomization (ASLR) to make memory addresses unpredictable. ASLR shuffles where things sit in memory each time a program starts, so an attacker cannot simply hard-code "the interesting data is always in locker 4711".
To bypass this, the attacker first leverages PHP's stale global state to trigger a tiny memory leak, which reveals the server's secret memory layout. A memory leak here means a small amount of information about memory contents escaping to somewhere the attacker can observe it. With ASLR defeated, the attacker uses the corrupted memory path to overwrite an internal PHP function pointer, redirecting the engine to execute operating-system commands instead of standard PHP code.
A function pointer is a note that says "when this step is reached, run the code at this address". If an attacker can rewrite that note, the engine will run the attacker's chosen code instead. "Operating-system commands" means instructions to the underlying machine, such as listing files or starting other programs, which is far beyond what a website is supposed to do.
Root cause
The mistake is in PHP's core runtime, not in any application built on it. In the first case, a failed memory allocation during initialisation leaves internal bookkeeping out of step with reality, and later cleanup trusts a structure that was never fully built. In the second, error-handling paths interrupt the release of request-scoped state, so a worker keeps a reference to memory that has already been freed and reuses it on a later request.
Because the flaw sits below the application layer, a carefully written application still runs on a vulnerable runtime. The write-up does not detail the specific code changes or the defences that failed; the bypass of ASLR described above is part of the exploitation path, not a defence that stopped the bug.
Impact
The vulnerabilities can allow unauthenticated attackers to execute code remotely, and the researchers demonstrated exploitation against popular web applications including WordPress, Drupal and Joomla. The write-up hedges the outcome: exploitation depends on the PHP build, memory layout and other environmental factors, and not every vulnerable request will succeed. Where it does succeed, the attacker can turn the memory corruption into code execution.
"Complete remote control" is the worst outcome in this field. It means the attacker can run whatever they like on the machine, not merely read one page or one database row.
Fix
The initial fixes were released for PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35. The write-up advises checking the latest official advisories before relying on those version numbers. For anyone maintaining a PHP application, the priorities are:
- Check your PHP version: identify the runtime actually serving web requests, not just the command-line version.
- Install the relevant security updates: follow the official PHP or operating-system vendor advisories.
- Review suspicious activity: look for unusual PHP worker crashes, memory errors, unexpected child processes and suspicious outbound connections.
You can check the PHP version available in your terminal with:
php -v
Line by line: php is the name of the program, and -v is a short option meaning "show the version". The terminal is the text window on a computer where you type commands. Running this prints the version of PHP installed on that machine.
Keep in mind that a website may use a different PHP installation from the one on your command line. The version you see in a terminal is the one on the machine where you typed it, which may not be the machine serving your site, and even on the same machine the web server may load a different copy.
Variants to test
These are checks a defender can run on systems they own or are authorised to test. They are not attacks against other people's servers.
- Compare CLI and web runtime versions. Run
php -vand compare it with the version the web server actually loads (for example through aphpinfo()page on a staging host you control).phpinfo()is a built-in PHP page that prints configuration details, including the version; a staging host is a copy of the site used for testing rather than real visitors. - Exercise allocation-failure paths. A positive result is a crash or error that leaves the worker in an inconsistent state rather than a clean failure. In plain words: try to make the locker desk run out of lockers on purpose, and see whether it fails tidily or leaves a mess.
- Exercise request-boundary cleanup. A positive result is behaviour on a later request that depends on data from an earlier, failed one. This is the hotel clerk test: does the next customer get served using the previous customer's note?
- Watch for the post-exploitation signals. A positive result is a PHP worker spawning a shell or connecting somewhere it never normally would. A child process is a program started by another program; a shell is a program that runs commands. A web worker starting a shell is like a receptionist suddenly walking into the machine room and turning dials.
Glossary
- Address: the number identifying a location in a computer's memory, like a locker number.
- Address Space Layout Randomization (ASLR): an operating-system protection that shuffles where things sit in memory each time a program starts, so addresses cannot be predicted.
- Allocate: to reserve a piece of memory for a program's use.
- Application: the code written by a website's developers, such as a WordPress installation, as opposed to the engine it runs on.
- Child process: a program started by another program.
- Cookie: a small piece of data a website stores in your browser so it can recognise you on later requests.
- Critical: a severity label meaning a flaw is about as serious as it gets.
- CVE: a public catalogue number for a known security vulnerability, so people worldwide can refer to the same bug unambiguously.
- CVSS: a standard scoring system for the severity of a vulnerability, here 9.2 out of 10 in the initial advisories.
- Function pointer: an internal note saying which code to run at a given step; if rewritten, the program runs different code.
- Heap grooming: deliberately arranging what goes into freed memory so that the program later finds the attacker's data where it expected its own.
- HTTP request: the message a browser or client sends to a web server when visiting a page or submitting a form.
- Memory corruption: a program reading or writing memory it should not, so the data there no longer means what the program expects.
- Memory leak: here, a small amount of information about memory contents escaping to somewhere the attacker can observe it.
- Out-of-memory error: a failure that occurs when a program cannot obtain the memory it needs.
- PHP: a server-side programming language used to build a large share of the web.
- PHP runtime: the software that actually executes PHP code.
- phpinfo(): a built-in PHP page that prints configuration details, including the version.
- Plugin: an add-on that extends an application such as WordPress.
- Pointer: see function pointer and reference; a note recording where data lives in memory.
- Reference: a note in a program recording the memory address where its data lives.
- Remote code execution: making a server run commands of the attacker's choosing from somewhere else on the internet.
- Server-side: code that runs on the computer hosting a website, not in your browser.
- Session: how a website remembers you between page loads, usually via a cookie.
- Shell: a program that runs commands.
- Staging host: a copy of a site used for testing rather than real visitors.
- Terminal: the text window on a computer where you type commands.
- Unauthenticated: without needing an account or password.
- Use-after-free: a bug where a program keeps using memory after it has given it back for reuse.
- Vulnerability: a flaw in software that someone can abuse to make it behave in ways its authors did not intend.
- Worker: one of the processes a web server keeps running to handle incoming requests.