Knowledge Centre Campus Rouen



Zend Engine V3.4.0 Exploit

$size = pow(2, 16);
$keys = [];
for ($i = 0; $i < $size; $i++) 
    $keys["\0" . $i] = 1;
// Causes O(n^2) insertion time due to collision chain
// Simplified pseudo – real exploit requires heap spraying
zend_string *str = zend_string_alloc(128, 0);
zend_string_realloc(str, 256, 0);
// Old pointer may leak heap metadata if not cleared

| Component | Vulnerability Type | Example | |-----------|--------------------|---------| | zend_gc (garbage collector) | Use-after-free | Recursive array destruction | | zend_hash (HashTable) | Double free / out-of-bounds read | Crafted array keys | | zend_objects (object handlers) | Type confusion | Overriding get_properties | | zend_vm (opcode handlers) | JIT miscompilation (not in 3.4.0) | N/A (no JIT yet) | | zend_string | Off-by-one | zend_string_realloc |


Let's assume a target running PHP 7.3.0 (Zend Engine v3.4.0) with a vulnerable library that unserializes user input.

Step 1: Memory Layout Recon The attacker sends a primitive payload to trigger a predictable memory leak, often via a Closure or Generator object. The leaked pointer reveals the base address of libc. zend engine v3.4.0 exploit

Step 2: The ROP Chain Since NX (No-Execute) is standard, the attacker cannot execute shellcode on the heap directly. Instead, they construct a ROP (Return Oriented Programming) chain within a serialized string.

Step 3: Triggering the UAF The attacker sends the malformed PHAR file to a file_exists($input) call. The Zend Engine enters the phar parser, triggering the deserialization flaw (CVE-2020-7068). The zend_string holding the PHAR metadata is freed prematurely. $size = pow(2, 16); $keys = []; for

Step 4: The Spray Immediately after freeing, the attacker sends a large request allocating thousands of SplFixedArray objects. The Zend Engine's heap allocator reuses the recently freed slots, placing the ROP payload directly where the zend_string used to be.

Step 5: Payload Execution When the Zend Engine later attempts to read the "freed" string's val pointer, it instead reads the attacker's ROP chain. A subsequent function call triggers the dereference, the PC (Program Counter) jumps into the ROP chain, and system('/bin/sh') is executed. // Simplified pseudo – real exploit requires heap

You might think, "Zend Engine v3.4.0 is obsolete." Yet, penetration testers frequently encounter it for three reasons:

When security researchers target the Zend Engine, they aren't looking for SQLi or XSS. They are looking for opcode manipulation and heap corruption. ZE v3.4.0, while more secure than its predecessors, introduced a specific set of exploitable quirks.

Accueil

Accueil

Sélection de la langue

Adresse

Knowledge Centre Campus Rouen
NEOMA Business School 1, rue du Maréchal Juin - BP 215 76130 Mont Saint Aignan

France 
02 32 82 58 26
Français
Historique des recherches