November 9, 2026
PHP2Shell TryHackMe — Complete Walkthrough
On 21 October 2026 the PHP project disclosed two vulnerabilities that, between them, let an unauthenticated attacker run commands on almost…
By Mammd Hamidli
6 min read
On 21 October 2026 the PHP project disclosed two vulnerabilities that, between them, let an unauthenticated attacker run commands on almost any PHP server with nothing but ordinary HTTP requests, and began shipping emergency fixes across every supported branch. No login, no file upload the application accepts, and no bug in the application itself: the flaw lives in the PHP runtime, below whatever framework or CMS happens to be installed. The disclosure was named PHP2Shell, and because the vulnerable code has been present since PHP 5.4.0 in 2012, it reaches fourteen years of releases at once.
The two issues are tracked as CVE-2026-109618 and CVE-2026-109619, both scored 9.2 Critical on CVSS v4.0. They were found by researchers at Wiz, OpenAI and Califney, reported privately to the PHP security team, and patched in PHP 8.5.12, 8.4.27, 8.3.36 and 8.2.35. Details leaked a day before the fix, and network sensors recorded exploitation attempts within hours of disclosure, some even before the patched releases were out, so this is a live threat rather than a theoretical one.
This room takes you through the vulnerability from the ground up. You will see the harmless PHP feature it abuses, understand the single mistake in the engine that turns that feature into a weapon, and then run a working exploit against a vulnerable server in the lab to read a flag as the web server user. The focus throughout is on why the bug exists and why patching the application does nothing to stop it.
Task 1: Connecting to the Lab
Connect over SSH using the credentials below, from the AttackBox or your own terminal:
Task 2: How it works
PHP provides the session.upload_progress feature to track file uploads by storing information such as the filename, file size, and uploaded bytes in the user's session. This feature is enabled by default and is triggered through a specific multipart form field.
The critical detail is that PHP processes upload data before executing the requested PHP script. As a result, upload progress information can be written to the session without requiring session_start(), authentication, or application-level code execution.
This pre-execution behavior is the key concept behind PHP2Shell: the vulnerability takes advantage of PHP's upload-processing mechanism before the application has a chance to execute its own logic.
What is the default name of the form field that switches on PHP's upload-progress tracking?
PHP_SESSION_UPLOAD_PROGRESS
Task 3: Theory & Root Cause (PHP2Shell — CVE-2026-109618 & CVE-2026-109619)
Root Cause: When memory_limit is exceeded during the upload-progress feature, PHP performs an emergency bailout (longjmp()). This abruptly terminates execution after memory is freed but before clearing its pointer, resulting in a Dangling Pointer (CWE-824). In effect this is a use-after-free: the freed pointer is left stale rather than nulled, so it later references reallocated, attacker-controlled memory.
Server Architecture Impact (Apache prefork + mod_php): Worker processes do not restart between requests, so the stale pointer persists in memory. When the next request hits the same worker, an attacker can manipulate the newly allocated memory at that address to control what the pointer references.
Two Exploit Vectors (CVEs):
CVE-2026-109618 (Memory Disclosure):_ Reads the stale pointer with an oversized length and reflects worker memory back in response headers, enabling an ASLR bypass._
CVE-2026-109619 (Remote Code Execution):_ Leverages the corrupted internal state to hijack program execution flow and achieve a shell._
What one-word name does the PHP engine give to the longjmp it performs to abort a request that hits a fatal error such as running out of memory?
bailout
What is the CWE identifier for the weakness class behind PHP2Shell?
CWE-824
Task 4: Confirming the Target & Vulnerability Scope
- Target Verification: The target application runs locally inside a Docker container (
php2shell-target). Inspecting the container reveals it is running PHP 8.4.26 on an Apache web server. Because the security patch was applied in version 8.4.27, this version remains unpatched and directly vulnerable. - Minimal Target Surface: Requesting
/index.phpreturns a minimal response containing only the word OK. The entire application source code consists solely of<?php echo "OK\n"; ?>. - Exploit Scope: The lack of application-level logic highlights that the vulnerability resides entirely within the PHP runtime engine (via default
session.upload_progressand Apache prefork execution) rather than the application code itself. Consequently, any application running on an unpatched runtime—regardless of how secure its custom code is—is equally exposed. - Lab Environment Setup: The lab environment runs a single worker process with a lowered
memory_limitto make memory allocation predictable and the out-of-memory condition easily reproducible for the exploit script located at~/php2shell-bypass-aslr-exp/exploit.py.
What version of PHP is the target server running?
8.4.26
What single word does the target page at /index.php print in response?
OK
Task 5: Defeating ASLR via Memory Disclosure (CVE-2026-109618)
Bypassing ASLR: Modern systems protect binaries using Address Space Layout Randomisation (ASLR), randomizing memory addresses on every run. CVE-2026-109618 defeats this by exploiting the dangling pointer to leak worker process memory.
The Leak Mechanism: An out-of-memory bailout leaves a stale pointer to a session ID. When an attacker's subsequent request reoccupies that memory and inflates the string's length, PHP reads past the intended boundaries.
Exfiltration via Headers: PHP reflects this oversized string back to the client inside the Set-Cookie response header (carrying up to ~67 KB of raw process memory per request).
Two-Pass Exploit Run:
- First Pass: Leaks the PHP heap chunk base address.
- Second Pass: Leaks the base address of the PHP library (
libphp).
Armed with these dynamic base addresses, the exploit successfully circumvents ASLR, setting the stage for the remote code execution phase.
Which HTTP response header does CVE-2026-109618 abuse to return leaked process memory to the attacker?
Set-Cookie
Task 6: Remote Code Execution (CVE-2026-109619)
Forged Data Structure: With ASLR defeated, the exploit reoccupies the freed memory slot not with data to read, but with a carefully forged internal structure (HashTable).
Hijacking the Destructor: The pDestructor pointer inside this structure is overwritten with the address of system() inside libphp (obtained from the previous memory leak).
Execution Trigger: When PHP cleans up the value at the end of the request, it invokes what it believes is a standard destructor, unintentionally executing system() with attacker-controlled arguments.
Privilege Level: The commands run with the permissions of the web server worker user. Executing a payload like cat /f>/out/p1 successfully reads the flag from the target's root path /f.
When the exploit runs, which system user do the commands execute as?
www-data
What is the flag returned by the exploit?
THM{b4ilout_l3aves_th3_h3ap_dang1ing}
Task 7: Remediation, Mitigation, & Detection (PHP2Shell)
Runtime-Level Flaw: Updating web applications (e.g., WordPress, Laravel) does not fix PHP2Shell because the vulnerability resides entirely within the PHP runtime engine itself.
Permanent Fix: The runtime must be patched by updating PHP to a secure version (8.5.12, 8.4.27, 8.3.36, or 8.2.35) and restarting all worker processes.
Interim Mitigations:
- Disabling upload progress (
session.upload_progress.enabled = 0) removes the primary attack trigger. - Disabling opcode cache (
opcache.enable = 0) impedes the execution path. - In-process WAF modules are ineffective because the attack executes during request parsing before the application code is reached.
Detection Indicators: Look for abnormally large PHPSESSID values in Set-Cookie headers, large multipart POST requests with high field counts targeting PHP_SESSION_UPLOAD_PROGRESS, and recurring worker OOM crashes in server logs.
Which PHP 8.4 release fixes PHP2Shell?
8.4.27
Which php.ini directive, set to 0, disables the feature the attack relies on for delivery?
session.upload_progress.enabled
Task 8: Conclusion
You've successfully walked through the entire lifecycle of a critical runtime-level vulnerability — from engine-level memory management quirks and dangling pointers to defeating ASLR and achieving remote code execution entirely through standard HTTP requests.
It is a striking reminder that security extends far beyond application frameworks (like WordPress or Laravel) straight down to the underlying runtime. Excellent work working through the lab and gathering your notes for the writeup!