Skip to content
Memory corruption Write-up Advanced

A brief Study on PHP2Shell Exploits

The text describes two PHP engine flaws, an out-of-memory condition and a use-after-free, both tied to the zend_bailout() fatal-error path, and states that remote code execution is possible with either. It also mentions that a public Python exploit exists for Linux targets.

medium.com

Published on medium.com

Php2shell Vulnerabilities

S.M. Mahfuz-ul-Islam, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 3 min read.

Context

PHP2Shell is the name given here to a pair of PHP vulnerabilities that share a common failure path in the Zend Engine. The first is an out-of-memory (OOM) condition, tracked as CVE-2026-109618, and the second is a use-after-free (UAF), tracked as CVE-2026-109619. Both are described as leading to remote code execution (RCE), and both are said to involve the same fatal-error mechanism, zend_bailout().

The write-up is a short study of the published exploit rather than a disclosure of a new finding. It points readers at an exploit that Offensive Security published on 2026-10-22, and it walks through what a penetration tester does with it. The affected PHP versions are not listed in the write-up; it states only that they have already been published by NVD.

Setup

The exploit is a Python script named 52704.py, written for Linux machines. It is not available in msfconsole, so it has to be run directly from the ExploitDB tree. The write-up gives its path as:

Text
/usr/share/exploitdb/exploits/php/remote/52704.py

No target application, version string, account or role is described. The only precondition stated is a target running an affected PHP build, with the affected versions deferred to NVD.

Finding it

The write-up does not describe a discovery process. Its starting point is the public exploit and the two CVEs behind it. What it does explain is the mechanism that makes the bugs interesting: zend_bailout() is an internal PHP Zend Engine function that abruptly terminates the current PHP execution path and transfers control to an established bailout handler.

That abrupt exit is the problem. If a resource or memory pointer is not properly cleaned up during the bailout, a stale pointer can remain and cause a use-after-free in a subsequent request. A bailout triggered by an out-of-memory condition can therefore contribute to a UAF condition. The two CVEs are two routes into the same bailout path, and the write-up states that RCE is possible with both weaknesses.

Exploitation

Step 1: run the published exploit

The tester runs the script from the ExploitDB path. The write-up gives the full command line as:

Text
python3 exploit.py — host TARGET — rce ‘id>/var/www/html/proof.txt’

The write-up gives the full command line as shown above and does not explain the flags or the redirect. The write-up does not show the exploit's output or the contents of the proof file.

Step 2: confirm the lab result

The write-up labels the next item as a lab-tested proof of concept.

From the original on medium.com

The text does not describe what the screenshot contains beyond presenting it as the tested POC.

Root cause

The mistake is in cleanup during a fatal error. zend_bailout() ends the current execution path and hands control to a bailout handler, and if a resource or memory pointer is not properly cleaned up on that path, a stale pointer survives. A later request that reaches the freed memory produces the use-after-free. The OOM variant reaches the same bailout through memory exhaustion, which is why the write-up treats the two CVEs as one family.

Why the existing defences did not stop it is not discussed. The write-up does not analyse the allocator, the bailout handler or any hardening that was or was not present, so any statement about defences beyond the cleanup gap would be speculation.

Impact

Under the conditions described, an attacker who can reach an affected PHP build can achieve remote code execution. The affected versions are left to NVD.

Fix

For remediation it says only that the mitigation has already been published in NVD.

Variants to test

  1. OOM route versus UAF route. The write-up names two CVEs, one for OOM and one for UAF.
  2. Bailout followed by a second request. The stale pointer is described as surfacing in a subsequent request.
  3. Memory pressure as the trigger.
  4. Proof-file readback. The command in the write-up writes into /var/www/html.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

What happened, in plain words

A short study was published about a pair of security bugs in PHP, the programming language that runs a very large share of the websites you visit. The two bugs are grouped under the name PHP2Shell. One is an out-of-memory problem, tracked as CVE-2026-109618, and the other is a use-after-free problem, tracked as CVE-2026-109619. Both are said to allow remote code execution, which means an attacker somewhere else on the network can make the server run commands of their choosing. Both bugs are also said to go through the same internal failure path inside PHP, a function called zend_bailout().

The study is not a new discovery. It is a walkthrough of an exploit that Offensive Security published on 2026-10-22, written for penetration testers, the people who are paid to break into systems with permission so the owners can fix them first. The study explains what the bugs are, where the exploit lives, and the command a tester uses to run it. It does not list which PHP versions are affected; it says only that NVD, the National Vulnerability Database, has already published that information.

From the original on medium.com

Background: what the two bugs are

To follow this, you need one idea: a program keeps things in memory while it runs, and it is supposed to hand that memory back when it is finished with it. Think of a library where you borrow a book, and the librarian is supposed to mark it as returned when you leave. If the librarian forgets, the next person may be handed a book that is already checked out to someone else, and confusion follows.

Out-of-memory (OOM) means the program asked for more memory than it was allowed to have. Out-of-memory means the program asked for more memory than it was allowed to have.

Use-after-free (UAF) means the program kept a note of where some memory was, the memory was given back, and then the program used the old note anyway. The note now points at memory that may belong to something else. If an attacker can influence what lands in that reused memory, they can sometimes steer the program into running their own instructions. That is the step from a crash to remote code execution.

Remote code execution (RCE) is the worst outcome in this list: someone who is not sitting at the machine can cause it to run commands. It is the difference between a stranger jiggling your door handle and a stranger sitting at your kitchen table.

Both bugs are described as reaching the same fatal-error mechanism, zend_bailout(). The Zend Engine is the part of PHP that actually executes your scripts. zend_bailout() is an internal function of that engine which abruptly ends the current execution path and hands control to a bailout handler, a piece of code set up in advance to deal with exactly this kind of emergency stop.

The problem is what happens during that emergency stop. If a resource or a memory pointer is not properly cleaned up on the way out, a stale pointer can be left behind. A later request that touches that stale pointer hits memory that has already been freed, and that is the use-after-free. An out-of-memory bailout can therefore contribute to a UAF condition. The two CVEs are two roads into the same bailout, which is why the study treats them as one family.

Affected PHP versions: the study says these have already been published by NVD and does not repeat them.

Is there an exploit?

Yes. Offensive Security published one on 2026-10-22 so that penetration testers can check for this weakness in PHP. An exploit is a ready-made program that turns a bug into a practical result, in this case running a command on the target.

Exploit details

The exploit is a Python script named 52704.py, written for Linux machines. Python is a general-purpose programming language; a script is just a text file of instructions that the Python interpreter runs. It is not available in msfconsole, the console of Metasploit, a popular framework that bundles many exploits behind one menu. Because it is not in that menu, a tester runs the file directly from the ExploitDB path given in the study.

The study gives the path as:

Text
/usr/share/exploitdb/exploits/php/remote/52704.py

Line by line, this is a file path, read from left to right:

  • / is the top of the filesystem, the root folder.
  • usr/share/exploitdb is where the ExploitDB package keeps its files on a typical Linux system.
  • exploits/php/remote narrows it down to exploits for PHP, of the remote kind, meaning the attacker does not need to be logged in locally.
  • 52704.py is the script itself; the .py ending tells you it is Python.

No target application, version string, account or role is described. The only precondition stated is a target running an affected PHP build, with the affected versions deferred to NVD.

What penetration testers do

A penetration tester runs the exploit from that path. The study gives the full command line as:

Text
python3 exploit.py — host TARGET — rce ‘id>/var/www/html/proof.txt’

In plain words, piece by piece:

  • python3 starts the Python 3 interpreter, the program that reads and runs the script.
  • exploit.py is the script being run, as shown in the command.
  • — host TARGET is part of the command line as the study gives it.
  • — rce is part of the command line as the study gives it.
  • ‘id>/var/www/html/proof.txt’ is the command to run on the target, wrapped in quotes so the local shell passes it through as one piece.

The last part of the command is id>/var/www/html/proof.txt, which the study gives without further explanation.

The study does not show the exploit's output or the contents of the proof file.

Lab-tested proof of concept

The study labels the next item as a lab-tested proof of concept.

From the original on medium.com

The study does not describe what the item contains beyond labelling it a tested POC.

Root cause

The mistake is in cleanup during a fatal error. zend_bailout() ends the current execution path and hands control to a bailout handler, and if a resource or memory pointer is not properly cleaned up on that path, a stale pointer survives. A later request that reaches the freed memory produces the use-after-free. The OOM variant reaches the same bailout through memory exhaustion, which is why the study treats the two CVEs as one family.

Why the existing defences did not stop it is not discussed. The study does not analyse the allocator, the bailout handler or any hardening that was or was not present, so any statement about defences beyond the cleanup gap would be speculation.

Impact

Under the conditions described, an attacker who can reach an affected PHP build can achieve remote code execution. The study does not scope this to a particular application, deployment model or privilege level, and it does not say whether authentication or a specific request pattern is required. The affected versions are left to NVD.

Fix

The study does not describe a patch or a code change. For remediation it says only that the mitigation has already been published in NVD.

Variants to test

  1. OOM route versus UAF route. The study names two CVEs, one for OOM and one for UAF.
  2. Bailout followed by a second request. The stale pointer is described as surfacing in a subsequent request.
  3. Memory pressure as the trigger.
  4. Proof-file readback. The command in the study writes into /var/www/html.

Glossary

  • Bailout handler: code set up in advance to take over when PHP has to stop a request abruptly.
  • CVE: a public identifier for a known security vulnerability, so people can refer to the same bug unambiguously.
  • Exploit: a program or technique that turns a vulnerability into a practical result, such as running a command.
  • ExploitDB: a public collection of exploits, shipped with testing distributions such as Kali Linux.
  • Linux: a family of operating systems widely used for servers.
  • Metasploit / msfconsole: a framework that bundles many exploits behind one console; this exploit is not in it.
  • NVD: the National Vulnerability Database, a public catalogue of vulnerabilities and their details.
  • Offensive Security: the organisation that published the exploit described here.
  • Out-of-memory (OOM): a condition where a program asks for more memory than it is allowed to use.
  • Penetration tester: a security professional who attacks systems with permission, to find weaknesses before criminals do.
  • PHP: a programming language widely used to build websites.
  • Proof of concept (POC): a demonstration that a vulnerability can actually be exploited.
  • Python: a general-purpose programming language; the exploit here is a Python script.
  • Remote code execution (RCE): running commands on a machine from elsewhere over the network.
  • Script: a text file of instructions run by an interpreter such as Python.
  • Stale pointer: a saved memory address that is no longer valid because the memory was freed.
  • Use-after-free (UAF): using memory after it has been freed, which can let an attacker influence what the program does next.
  • Web root: the folder a web server serves pages from, commonly /var/www/html.
  • Zend Engine: the part of PHP that executes scripts.
  • zend_bailout(): an internal Zend Engine function that abruptly ends the current execution path and transfers control to a bailout handler.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.