1.1 Attack Surface: Session Initialization Before RINIT
session.upload_progress is intended to report the progress of file uploads. Its side effect is that the Session module is initialized during request startup, before a single line of application PHP code executes. With session.auto_start=Off, this is the sole vector through which an incoming POST request can initiate a session without the script requesting it.
If the memory allocator fails inside the multipart callback, zend_bailout unwinds the request but does not perform an orderly session shutdown, leaving global pointers (ps_globals) dangling to freed heap memory.
1.2 Stage A: Inducing OOM at the Exact Location
Simply exhausting memory is insufficient: it must be exhausted inside php_session_send_cookie(), specifically on the first allocation of php_url_encode (121 B = one page). Three simultaneous conditions are required:
heap->real_size == heap->limit- Zero free pages across all allocated chunks.
- The next allocation must be the encoder itself, not a HashTable resize.
Amplification is achieved via nested multipart file parts: files[R00000] + [a] × 62 (64 nesting levels) with filename="". Each part consumes ~147 KB of heap with an amplification ratio of ~470×.
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 4096 bytes)If the error reports 12288 or 20480, the OOM occurred prematurely during HashTable resize and no usable state remains dangling.
1.3 Stage B: Reading Freed Memory (Heap Leak)
The subsequent request encounters PS(id) dangling. Reoccupying that heap block with a forged zend_string (controlling both len and data) causes php_url_encode to copy len bytes from data, returning raw heap memory to the attacker in the Set-Cookie header:
- Chunk Base Leak (256 B): Chunk pointers aligned to 2 MiB boundary.
- Code Pointer Leak (16 B): Pointer to
zval_ptr_dtorto defeat ASLR.
1.4 Stage C: From zval to system() / passthru() (RCE)
Injecting a forged zend_string containing a fake HashTable whose destructor (pDestructor) points directly to the target internal function handler. The execution resolution path is:
php_session_track_init → zval_ptr_dtor → zend_reference_destroy → zend_array_destroy → zend_hash_destroy → pDestructor(cmd)
While zif_system executes the payload command, it terminates the worker process when writing the return zval. In contrast, zif_passthru (located exactly at +0x10 offset across all five measured builds) keeps the worker alive and streams clean output directly to the HTTP socket.