PHP Deserialization

Theory

PHP Object Injection is an application level vulnerability that could allow an attacker to perform different kinds of malicious attacks, such as Code Injection, SQL Injection, Path Traversal and Application Denial of Service, depending on the context. The vulnerability occurs when user-supplied input is not properly sanitized before being passed to the unserialize() PHP function. Since PHP allows object serialization, attackers could pass ad-hoc serialized strings to a vulnerable unserialize() call, resulting in an arbitrary PHP object(s) injection into the application scope.

Practice

If the PHP application use the unserialize() function whose parameter is not correctly satanized, then it is vulnerable.

<?php
$cookie = base64_decode($_COOKIE['PHPSESSID']);
unserialize($cookie);
?>

References

Last updated