Skip to content
OSULZER.AT
Security13 min read

PHP2Shell Explained: How an Attack Works and Why the Vulnerability Is So Dangerous

Why PHP2Shell is more dangerous than an ordinary plugin flaw: how an attack works in interactive diagrams, the role of mod_php and PHP-FPM, and what to do.

I have already written two posts about PHP2Shell: what website owners need to do now and which PHP versions close the gap. This one is about the question behind them: How does such an attack work - and why is this vulnerability so dangerous?

It is based on the German-language video “PHP2Shell: How a memory error becomes a shell” by Hood Informatik, which explains the background very clearly. I have added the reports of the researchers who found the flaws and the official advisory - all sources are listed at the end. I deliberately leave out technical details on exploiting the vulnerability; the diagrams show the process the way it matters to you as a website owner, and you can click through them step by step.

Why PHP2Shell is so dangerous

Most security vulnerabilities WordPress owners hear about are in a plugin or theme. Then only websites with exactly that plugin are affected, and a plugin update fixes the problem. PHP2Shell is different:

  • The flaw is in PHP itself - the program that runs your PHP code. That means WordPress, WooCommerce, Joomla, Drupal, Shopware, Nextcloud, Laravel and every other PHP application are affected, according to Calif going back to PHP 5.4.
  • No login required. Attackers need neither a password nor any action by a user. Crafted requests over the internet are enough.
  • The attack happens before your code. In the most dangerous variant, it takes place while PHP is still reading the request - before a single line of your application runs. Your own code can be flawless and the server is still vulnerable.
  • The result is remote code execution. Anyone who can run their own code on the server can read data, leave backdoors or use the server for further attacks.

Leaked posts before the disclosure often mentioned a CVSS score of 10. The PHP team settled on 9.2 because the attack is complex: whether it succeeds depends on the PHP version, the web server and the state of the memory, and an attacker may need many attempts. That is still enough for mass attacks - automated attempts cost an attacker nothing.

How an attack works

From your website’s point of view, an attack via PHP2Shell roughly looks like this. Below each step, you can see which protection takes effect at that point.

Course of an attack - and where you stop it

1 · SearchFinding serversAutomated scanners search the internet for websites running PHP.
2 · RequestsCrafted requestsSpecially built requests are meant to push PHP to a specific limit - often over many attempts.
3 · ErrorPHP abortsPHP runs out of memory and aborts in the middle of its work. A half-finished state remains in memory.
4 · TakeoverForeign code runsPHP keeps working with the broken state - and in the worst case runs the attacker's code.
5 · ConsequencesServer compromisedBackdoors, stolen credentials and customer data, spam or malware.
ProtectionHard to preventEvery public website gets scanned - what matters is what happens next.
ProtectionWeb application firewallProviders such as Cloudflare filter known attack patterns before they reach your server - a stopgap, not a replacement for the update.
ProtectionPHP updateThe patched versions no longer abort in the middle of their work - no broken state is left behind. This is where the chain is reliably broken.
ProtectionBackups & monitoringClean, off-site backups and an eye on unusual activity limit the damage if it does happen.
  1. Finding servers. Attackers search automatically for websites running PHP - that is around 70% of all websites.
  2. Sending crafted requests. At first glance the requests look harmless, but they are built to push PHP to its memory limit. It often takes many attempts.
  3. PHP aborts in the middle of its work. Instead of stopping cleanly, PHP abruptly leaves the task it is working on - a half-finished state remains in memory.
  4. Foreign code runs. PHP relies on this state being valid and keeps working with it. If the attacker controls the data in it, they can run their own code.
  5. The server is compromised. From here, the damage depends on what the attacker intends and how well your website is secured and backed up.
Click through the steps: the attack is shown at the top, what protects you at that point below.

Why a memory error can do so much damage

To understand why a simple lack of memory can lead to a server takeover, two basics help.

First: PHP processes are reused. A process handles a request, cleans up and then takes the next one. For each request it gets its own memory area, which is released at the end. That is safe - as long as nothing points to this released memory afterwards.

Second, every request goes through three phases:

A request in three phases

Phase 1StartupPHP reads the data of the request - form fields, cookies, file uploads.this is where PHP2Shell strikes
Phase 2Your scriptWordPress, your shop or your application runs.
Phase 3ShutdownPHP cleans up and releases the memory. Then the process waits for the next request.
Both vulnerabilities arise at the transition between these phases - the most dangerous variant as early as phase 1, before your application starts.

PHP limits the memory per request, to 128 MB by default. When this limit was exceeded, PHP did not return a clean error but abruptly left the task it was working on and jumped straight to error handling. The aborted task never finishes its work: it may already have recorded that new data exists without having fully created it.

Later, PHP relies on everything that has been recorded being valid. With the first vulnerability, this happens while the same request is being cleaned up. With the second vulnerability, a leftover reference points to memory that was released long ago - and only the next request to the same process accesses it. Experts call this a use-after-free. In both cases: whoever can influence the leftover data influences what PHP does with it.

The researchers at Wiz also show that this path can leak memory contents to the outside - in the worst case including passwords or API keys from other people’s requests.

How the update fixes the problem

The patch goes straight to the root cause: it removes the abrupt abort when memory runs out.

Memory limit reached - two possible paths

Starting pointMemory limit reachedA request needs more memory than PHP allows it.
Without update
Abrupt abortThe running task is left halfway through.
Broken state remainsHalf-finished data is left behind - the attack surface.
With update
Finished cleanlyThe task may complete its work; only then does PHP abort.
Nothing left behindAs a safeguard, the process ends at a second, higher limit - without reusing broken data.
  1. The memory limit is reached. A request needs more memory than PHP allows it. This is where the paths split.
  2. Without update: PHP aborts abruptly. The task currently running is left halfway through.
  3. Without update: a broken state remains. Half-finished data or references to released memory are left behind - the starting point for the attack.
  4. With update: the task finishes cleanly. PHP lets the running work complete and only aborts afterwards.
  5. With update: nothing is left behind. As a safeguard, there is a second, higher limit at which the process ends on the spot - without reusing any broken state.
The update changes how PHP handles running out of memory - which is why it closes both vulnerabilities at the root.

mod_php or PHP-FPM: who is affected and how badly?

On web servers, PHP usually runs in one of two variants: with mod_php, PHP is built into the Apache web server as a module. With PHP-FPM, PHP runs as a separate service to which the web server passes requests. The advisory lists all variants as affected, but the risk is distributed differently:

Variant Risk according to the advisory and the researchers
mod_php (Apache) Highest. Full code execution was demonstrated with default settings - regardless of which application is running.
PHP-FPM High. Here, a successful attack also depends on the application. The researchers still demonstrated it against widely used systems such as WordPress.
php-cgi, FrankenPHP, LiteSpeed Affected, and likewise only fully protected by the update.

For you, this means: the variant at most decides how urgent the update is - not whether you need it.

20 years old: why the flaw only became dangerous now

What stands out most is how old the underlying problem is:

From known flaw to shell

  1. 2004 - Security researcher Stefan Esser finds a similar vulnerability involving the memory limit.
  2. 2020 - A related bug is reported and classified as harmless.
  3. 2024 - A security audit (OSTIF and Quarkslab) finds the problem again but cannot prove it is exploitable.
  4. August 2026 - Calif, Wiz and OpenAI provide exactly that proof with the help of AI models and report the vulnerabilities to the PHP team.
  5. October 21, 2026 - The PHP team releases the security updates, one day earlier than planned, because details leaked on October 20.
A behavior known for years was considered too complicated to exploit - until 2026.

The AI did not “find” the flaw: the Calif researcher knew about the old vulnerabilities and had the model search for them specifically. The AI sped up the laborious work of turning a known flaw into a working attack. Wiz writes that a single researcher managed in a week what previously would have taken a world-class team months. For the industry, that is the real lesson: a known flaw can no longer be considered harmless just because it is hard to exploit.

Is PHP2Shell already being exploited?

As of October 22, 2026, this is disputed:

  • Cloudflare has observed attack attempts on customer sites and seen attackers trying to get around its protection rules.
  • watchTowr reports attacks on its decoy servers (honeypots) since October 21.
  • Other sources had no confirmed cases up to their publication, and the US agency CISA does not yet list the vulnerabilities in its catalog of actively exploited vulnerabilities.

So there are attack attempts, but no confirmed picture of mass exploitation yet. The researchers’ complete attack has not been made public.

How to recognize attack attempts

Because the attack runs below your application, the logs of WordPress or your shop often show nothing. The researchers name other signs that you or your hosting provider can watch for:

  • a striking number of 500 errors in a short time,
  • messages about an exceeded memory limit in the PHP error log, often in connection with upload requests,
  • unusually large or strange-looking session cookies in the server’s responses,
  • PHP processes that restart unusually often.

On their own, these signs are no proof - but piling up at the same time, they are a good reason to take a closer look.

What you should do now

  1. Check and update your PHP version - even if your own code is clean. PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35 are safe, as is a package from your Linux distribution that contains the fix. How to check your version and what to watch out for on Debian and Ubuntu is covered in this post.
  2. Restart PHP-FPM after the update, otherwise the old processes keep running the old version. With managed hosting, your provider takes care of this - ask if in doubt.
  3. Replace old PHP versions. There are no official updates for PHP 8.1 and older. Many hosting providers are therefore locking affected websites or forcing the switch. What can go wrong in the process is described in “There has been a critical error on this website” after the PHP update.
  4. Use workarounds only as a bridge. The advisory names settings that make individual attack paths harder, and providers such as Cloudflare filter known patterns. According to the researchers, both are only partial measures and no replacement for the update.

I can help you with the switch

Not sure which PHP version runs on your server, or your website shows errors after the update? I check your website, move it to a current PHP version and fix incompatibilities in plugins and theme. If it has to be fast: my WordPress emergency support is there for exactly that. And so you do not have to take care of such updates yourself in the future, there is WordPress maintenance. If plugins or the theme need to be adapted, I take care of that as a WordPress programmer in Vienna.

Sources

WordPress Maintenance

So it never comes to that

Tested updates, daily backups, and malware protection - from €40 per month.

See maintenance

New project?

Contact.

Tell me briefly about your project - I'll get back to you personally.

Your data is used solely to handle your inquiry. More in the privacy policy.