Using unserialize() on User-Controlled Input like Cookies or POST Data
PHP applications call unserialize() directly on user-supplied data from cookies, POST/GET parameters, HTTP headers, or uploaded files without understanding that unserialize() instantiates arbitrary objects enabling object injection attacks. Common vulnerable patterns include session management deserializing cookie data: $session = unserialize(base64_decode($_COOKIE['session'])) allowing attackers to craft malicious serialized objects in cookies, form processing accepting serialized input: $formData = unserialize($_POST['data']) intended for complex data structures but exploitable for arbitrary object instantiation, and API endpoints accepting serialized payloads: $request = unserialize(file_get_contents('php://input')) in REST APIs or SOAP services. Attackers craft malicious serialized strings exploiting application classes with dangerous magic methods (__destruct(), __wakeup(), __toString(), __call()) that execute during deserialization or object destruction. Example attack: O:11:"FileManager":1:{s:17:"\0FileManager\0file";s:16:"/etc/passwd.bak";} creates FileManager instance with arbitrary file path property, triggering __destruct() that deletes specified file. More sophisticated attacks chain multiple objects creating POP (Property-Oriented Programming) chains similar to ROP in binary exploitation: attacker constructs object graph where properties point to other objects, calling magic methods in sequence executing complex attack logic culminating in code execution, file operations, or SQL injection. The vulnerability is particularly severe because: PHP unserialize() supports all classes loaded in application including framework classes, vendor libraries, and application code providing vast attack surface, magic methods execute automatically without explicit code calling them, serialized data format allows precise control over object state including private properties, and deserialization happens before any application-level validation enabling exploitation regardless of post-deserialization checks. Real-world exploitation examples include WordPress plugin vulnerabilities where unserialize() on user input enabled remote code execution, Magento eCommerce platform object injection vulnerabilities allowing admin account takeover, and numerous PHP framework deserialization chains discovered in Laravel, Symfony, Zend Framework, and Yii.