Deep dive into PHP2Shell: from heap memory basics to a working exploit
What happened next
This article is a technical walkthrough of the PHP2Shell vulnerabilities, based on the author's reading of the PHP source code, experiments, and investigations. The author started it on 26 October 2026 and says there was little detailed analysis of these bugs and their exploitation at the time. It is written to explain both what happens and why, for readers with basic C knowledge and no experience with low-level memory exploitation.
The article begins with memory basics, including the stack, the heap[2], and how an allocator reuses freed memory. It then explains how a stale pointer left behind after a free can lead to use-after-free[1] reads and writes that touch another object's data. Later sections describe an exploit in stages, from an HTTP request that triggers an out-of-memory condition to forging a hash table that hijacks a destructor pointer and leads to remote code execution[3].
The final sections cover the Steal My Bitcoin CTF[4] challenge that started the research and explain why the attack is much harder on a real production server. The author states that this is personal understanding, not an official analysis, and asks readers to send corrections.
Read the original djad04.github.ioDiscussion
Discussion
Commenters mostly praise the write-up as readable and well documented, and several plan to read it closely. One reader got lost near the end, unsure how the forged hash table is treated as an object so that its destructor runs, and another asked whether anyone has reproduced the bug on a php-fpm endpoint. A Lobsters commenter said the text looks human-written.
Links from the post and discussion
Sources
-
djad04.github.io
I spent countless nights digging into PHP2Shell. Here's a deep dive into how it actually works, from memory to PHP internals to a real exploit.


