PHP Insecure Deserialization (unserialize)

Detects PHP unserialize() called on user-controlled input, enabling object injection and remote code execution.

zakirkun 91598c3 2 files · 2.7 KB Updated

File contents

PHP Insecure Deserialization

Overview

PHP's unserialize() function reconstructs PHP objects from a string representation. When called with user-controlled input, attackers can craft malicious serialized strings that:

  • Invoke __wakeup() and __destruct() magic methods
  • Chain gadgets from existing classes to achieve RCE
  • Read/write arbitrary files

This is the basis of PHP Object Injection attacks.

Remediation

  • Never call unserialize() on user input
  • Use json_decode() for data exchange
  • If deserialization is required, validate with allowed_classes option

Safe:

$data = json_decode($_POST['data'], true); // Safe alternative
// OR if PHP object needed, restrict classes:
$obj = unserialize($data, ['allowed_classes' => ['SafeClass']]);

zakirkun/ice-tea/tree/main/skills/deserialization/php-unserialize commit 91598c3685

Frequently asked questions

npx skillmds@latest add zakirkun/php-insecure-deserialization-unserialize