Gadget Chains
A sequence of methods from classes already on the target’s classpath that, linked through deserialization callbacks, carries attacker-controlled data from a deserialization entry point to a dangerous sink — turning “the attacker chose the object type” into code execution without injecting new code.
The idea
Insecure deserialization only lets an attacker name which types get reconstructed. A gadget chain is Property-Oriented Programming (POP): each gadget is benign on its own, but the deserializer’s own callbacks invoke one method which invokes the next, until a sink does something dangerous. Nothing new is injected — only existing, legitimate code is reused in an unexpected order (PentesterLab, Frohoff & Lawrence’s 2015 “Marshalling Pickles”). The concept is language-independent; only the entry points and sinks differ.
Anatomy (Gigamon / Ian Haken taxonomy)
- Kick-off (trigger) gadget — the first method the deserializer calls implicitly on an attacker-named object: a magic method (
readObject,__wakeup,__destruct, Rubymarshal_load/_load) or a container rebuilding itself (HashMapre-hashing keys →hashCode/equals,TreeMap/PriorityQueue→ comparators). - Helper / bridge gadgets — glue that forwards control and data along the graph (reflection, dynamic proxies,
InvokerTransformer-style indirection). - Bypass gadget — triggers a nested deserialization on an unfiltered stream, defeating a shallow filter.
- Sink — the dangerous operation: process execution, outbound JNDI, remote/ local bytecode loading, file write, SSRF.
Per-language entry points and sinks
| Language | Common kick-offs | Representative sinks |
|---|---|---|
| Java | readObject, collection re-hash, comparators | JRE-internal bytecode-bearing templates, outbound JNDI, URLClassLoader, JDBC drivers; URLDNS for detection only |
| PHP | __wakeup, __destruct, phar:// metadata | file write, eval/command sinks via framework POP chains (Monolog, Guzzle, Laravel) |
| Python | __reduce__, __setstate__ | any importable callable (stdlib suffices) |
| Ruby | marshal_load, _load, _load_data, and implicit hash/eql? | eval, Kernel.load, gem/spec fetchers writing files |
| .NET | setter / type-converter invocation on named types | process start, remote assembly load |
The chain’s existence is a property of the classpath: the same deserialization bug yields RCE on one deployment and nothing on another. A blocklist implicitly trusts every class it did not name — UltraRed built a working chain from Oracle Coherence + Apache Xalan classes that a custom blocklist never considered. Ruby’s history (Trail of Bits “Marshal Madness,” elttam’s universal chains and “kick-off gadgets” work) shows a decade of patch-and-bypass, with implicit kick-offs (hash, eql?) least likely to be patched because they are core language features.
Tooling (payload generation / discovery)
- Payload generators:
ysoserial(Java),ysoserial.net(.NET),phpggc(PHP). These carry curated chains tied to specific library versions — used by defenders to validate findings and build detections. - Discovery / static analysis: GadgetInspector, Tabby, Crystallizer, ODDFuzz, and FLASH (USENIX 2025, deserialization-guided call-graph construction — 90 new chains, 10 CVEs); Gleipner benchmarks detectors. Mandiant’s HeySerial/CheckYoself generate and validate hunting rules.
- AI-assisted discovery has collapsed the cost of finding novel chains — see AI-Accelerated Gadget Discovery.
Defensive implication
Because a clean result from a fixed payload library only says “none of these matched this classpath,” blocklists and denylists age badly as new chains appear. Durable controls are: do not deserialize untrusted native formats; allowlist exact expected types at the deserializer (JEP 290 ObjectInputFilter with default-deny, PHP allowed_classes, restricted Unpickler); keep gadget-bearing libraries patched; and prove findings out-of-band rather than by response. See Insecure Deserialization.
Related
- Insecure Deserialization
- Java Deserialization
- PHP Object Injection
- Python Pickle Deserialization
- .NET Deserialization
- AI-Accelerated Gadget Discovery
- Remote Code Execution
Sources
- Deserialization Gadget Chain Definition · original
- What Actually Is a Deserialization Gadget Chain? · original
- Java Deserialization Gadget Chains Explained · original
- Automated Discovery of Deserialization Gadget Chains (Black Hat) · original
- Precise and Effective Gadget Chain Mining (FLASH, USENIX) · original
- The classes the blocklist forgot · original
- Marshal Madness: Ruby Deserialization Exploits · original
- Ruby Marshal Kick-off Gadgets · original
- Systematically Hunting for Deserialization Exploits (Mandiant) · original
- Deserialization Gadget Chains in Android · original
- Gleipner: Benchmark for Gadget Chain Detection · original