A critical vulnerability in PHP’s extract() function enables attackers to trigger memory corruption that can lead to arbitrary native code execution across multiple PHP versions.
The vulnerability stems from a memory management issue that can be triggered by a specific usage pattern involving references and object destructors affecting all major PHP versions including 5.x, 7.x, and 8.x.
The vulnerability exists within PHP’s extract() function, specifically when used with the EXTR_REFS flag.
This function imports variables from an array into the current symbol table, which can be manipulated to create a dangerous memory condition.
When extract() processes a variable that’s an object with a defined __destruct() method, attackers can trigger a race condition.
The __destruct() method can unset the variable that extract() is currently operating on, leading to:
Security researchers demonstrated that this memory corruption can be reliably exploited to gain arbitrary code execution by overlapping a string and array zval, effectively giving attackers read/write access to PHP’s memory.
The attack follows a sophisticated pattern:
Address Space Layout Randomization (ASLR) does not prevent this attack, as exploits can leak memory addresses at runtime by manipulating overlapped data structures.
The flaw has been identified by independent security researcher LCFR in collaboration with SSD Secure Disclosure.
A minimal proof of concept triggering the vulnerability:
When debugging with ASAN (AddressSanitizer), this code produces a heap-use-after-free error in PHP 8.x, confirming the vulnerability.
The PHP development team has addressed the issue through GitHub security advisory GHSA-4pwq-3fv3-gm94.
Web application administrators and PHP developers should:
This vulnerability underscores the risks associated with PHP’s dynamic features and memory management.
Developers are urged to audit their use of extract(), apply security patches promptly, and adhere to secure coding practices to prevent exploitation of such critical flaws.
Malware Trends Report Based on 15000 SOC Teams Incidents, Q1 2025 out!-> Get Your Free Copy
A federal judge has issued a preliminary injunction that significantly limits the Department of Government…
Ransomware is not retreating it's evolving. Once a niche cybercrime, ransomware has become a multibillion-dollar…
Microsoft has issued an alert regarding sophisticated ransomware attacks targeting hybrid cloud environments in Q1…
Microsoft has warned organizations worldwide that threat actors are ramping up their exploitation of critical…
In the modern digital landscape, organizations are constantly challenged by an ever-increasing volume of security…
In today's rapidly evolving cyber threat landscape, Security Operations Centers (SOCs) face an unprecedented challenge:…