Deserialization Attacks: A CEH and PenTest+ Exam Prep Guide
What Is a Deserialization Attack?
Serialization converts an in-memory object into a byte stream or string so it can be stored or sent over a network; deserialization reverses the process, rebuilding the object on the other end. Most application frameworks do this constantly — session tokens, cached objects, and API payloads all pass through serialization at some point.
An insecure deserialization attack happens when an application deserializes data from an untrusted source without first verifying it. Because the deserialization process itself can trigger code execution — not just rebuild harmless data — an attacker who controls the serialized input can potentially hijack that process entirely. For both CEH and PenTest+, this sits under the OWASP Top 10: it was A8:2017-Insecure Deserialization and now lives inside A08:2021-Software and Data Integrity Failures, alongside other attacks that abuse an application's trust in data it shouldn't trust.
A Quick Refresher on How Serialization Works
Every major language ships a native way to serialize objects, and each has become a target:
- Java —
ObjectInputStreamand thereadObject()method rebuilds objects from a binary stream; common in RMI, JMX, and session storage. - PHP —
serialize()/unserialize()convert objects to and from a distinctive string format, often seen in cookies and cached data. - Python —
pickle.loads()reconstructs arbitrary Python objects, including ones that execute code on load. - .NET —
BinaryFormatterand ViewState serializes objects for state management, notoriously in ASP.NET web forms.
None of these formats were designed with untrusted input in mind — they assume the byte stream came from the application itself, not an attacker. That assumption is the entire vulnerability.
The Gadget Chain: Why Deserialization Becomes RCE
A malicious serialized blob rarely contains attack code directly. Instead, it references classes already loaded by the application — a gadget chain: a sequence of otherwise-benign method calls that, when triggered in order during deserialization, ultimately execute an attacker-chosen command.
Ecosystem | Attacker's approach | Primary effect |
|---|---|---|
Java (Apache Commons Collections, etc.) | Crafts a serialized object referencing chained library classes to reach | Remote code execution on deserialization |
PHP Object Injection | Submits a forged serialized object with attacker-controlled property values | Triggers unintended magic methods ( |
.NET ViewState/BinaryFormatter | Forges a ViewState blob (often aided by a leaked | RCE via gadget chains built with tools like ysoserial.net |
Java gadget chains are the most exam-relevant because a single vulnerable library on the classpath — even one the developers never call directly — is enough to make the whole application exploitable.
How the Attack Is Carried Out
A typical deserialization attack, as CEH and PenTest+ material walk through it:
- Identify serialized data — look for base64-encoded blobs or telltale format markers (
O:8:"..."for PHP,rO0ABfor Java) in cookies, hidden form fields, or API parameters. - Fingerprint the library and version — error messages, stack traces, or known framework versions point to a specific gadget chain that will work.
- Build the payload — tools like ysoserial (Java), ysoserial.net (.NET), or PHPGGC (PHP) generate ready-made gadget chains for known-vulnerable libraries.
- Deliver the payload — the forged serialized object replaces the legitimate one in the request.
- Trigger deserialization — the application deserializes it automatically, and the gadget chain executes, typically returning a shell.
Why It Matters: The Business Impact
- Remote code execution — the most severe outcome; a successful gadget chain often hands the attacker a shell on the application server.
- Authentication bypass — forged session or ViewState objects can impersonate another user without valid credentials.
- Data tampering — object properties can be altered before reconstruction, silently changing prices, permissions, or business logic.
- Denial of service — deeply nested or recursive objects can exhaust memory or CPU during deserialization alone.
For a report, the finding is never just "deserialization is possible" — it's the specific library and version, the gadget chain used, and what code execution actually achieved.
Detection and Mitigation
Control | What it does |
|---|---|
Avoid native deserialization of untrusted input | Prefer data formats like JSON or XML with strict schema validation instead of language-native binary formats |
Integrity checks (HMAC/signing) | Signs serialized data so any tampering invalidates it before deserialization runs |
Class/type allow-listing | Restricts deserialization to a known-safe set of classes, blocking gadget-chain classes outright |
Least-privilege execution | Runs the deserializing process with minimal OS permissions to limit RCE impact if exploitation succeeds |
Best-practice guidance to remember for the exam: never deserialize data from an untrusted source at all if it can be avoided — everything else on this list is a mitigation for when it can't.
CEH Exam Tips
- Insecure deserialization is covered in CEH's Hacking Web Applications module, listed as one of the OWASP Top 10 web application risks alongside injection and broken access control.
- Know the term gadget chain cold, plus at least one tool by name: ysoserial for Java is the most commonly referenced.
- CEH expects you to recognize the format markers of serialized data (Java, PHP, .NET) well enough to spot them in a cookie or parameter during a scenario question.
- Don't confuse insecure deserialization with SQL injection — both involve untrusted input reaching unsafe processing, but deserialization exploits the reconstruction of objects, not a database query.
- Expect it paired with its OWASP Top 10 category name change: A8:2017-Insecure Deserialization is now folded into A08:2021-Software and Data Integrity Failures.
PenTest+ Exam Tips
Deserialization attacks map to PenTest+'s Attacks and Exploits domain, under application-based attacks, grouped with injection, XML external entity (XXE), and directory traversal attacks.
- Scenario-based framing — expect a description of behavior (an app accepting a base64 cookie that changes user state) rather than being asked to name "deserialization" outright.
- Tool identification — ysoserial and similar payload generators may appear as answer choices tied to a specific language or framework.
- Caution in execution — PenTest+ emphasizes that deserialization payloads can crash production systems; expect questions on confirming scope and having a rollback plan before testing it live.
- Reporting weight — findings should tie the specific gadget chain or library version to a concrete remediation, not just "RCE achieved."
Bottom line for dual-cert studiers: the mechanics — gadget chains, forged objects, RCE — are identical across both exams; only the lens changes, from "recognize and defend" (CEH) to "authorize, exploit carefully, and report" (PenTest+).
Key Takeaways
Deserialization attacks exploit a basic assumption most developers never question: that data rebuilt into an object came from a trustworthy place. When it doesn't, the reconstruction process itself becomes the attack surface, and a well-built gadget chain can turn a single vulnerable library into full remote code execution.
For exam day, anchor on three things: what a gadget chain is and why it doesn't require attacker-written code, the format markers that reveal serialized data in a request, and the fact that PenTest+ will always push you one step further — from "what the payload achieved" to "what you tell the client to fix."
No comments:
Post a Comment