php2shell Explained How A Php Memory Error Became Remote Code Execution
Two memory-safety bugs in PHP's request handling could let an unauthenticated attacker trigger memory exhaustion and then exploit partially initialised or freed internal state to achieve remote code execution. The article is a learning case study that explains the research rather than an original discovery.
Published on systemweakness.com
A security research article led me down a rabbit hole: How can making a web server run out of memory possibly allow someone to execute code on it?
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.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely PHP incremented internal hash-table entry counts before a fallible allocation and kept request-owned state pointing at freed memory, so cleanup or later requests interpreted uninitialised or stale bytes as valid internal structures.
Impact
In affected configurations an unauthenticated attacker could achieve remote code execution with the privileges of the PHP worker, though exploitability depends on the runtime and deployment path and not every PHP application was compromised.
What the attacker needed
Affected PHP runtime and deployment path; no authentication required; attacker can send crafted HTTP requests
The fix
PHP made memory_limit a soft limit so allocations can finish and state stays consistent, added a hard limit that terminates the process before unsafe cleanup, and fixed the stale-state issue in releases issued on 21 October 2026.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
PHP is a programming language that runs on a website's server, not in your browser. These bugs meant that if PHP ran out of memory at just the wrong moment, it could later mistake leftover or half-built internal data for something real, and in some setups an attacker could turn that confusion into running their own code on the server. The article is a teaching walkthrough of the public research, not a new attack.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.