Discovering Deserialization Gadget Chains in Rubyland
The text describes how to create a Ruby deserialization gadget chain from scratch using four libraries, allowing an attacker to execute arbitrary commands when a malicious serialized object is deserialized. It walks through the construction of the chain and explains the underlying Ruby mechanisms.
Published on blog.includesecurity.com
At Include Security we spend a good amount of time extending public techniques and creating new ones. In particular, when we are testing Ruby applications for our clients, we come across scenarios where there are no publicly documented Ruby deserialization gadget chains and we need to create a new one from scratch.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application deserializes untrusted data using Ruby's Marshal.load, which can instantiate arbitrary objects and trigger dangerous methods.
Impact
An attacker could execute arbitrary commands on the server if they can control data passed to Marshal.load.
What the attacker needed
Application uses Marshal.load on untrusted data; specific gems are loaded
How it was found
- Set up a Ruby environment with the target application's gems.
- Search for classes with marshal_load and instance variables that call methods.
- Build gadgets from both ends: initial kick-off and command execution.
- Chain gadgets by setting instance variables to reference each other.
- Serialize the final gadget with Marshal.dump to create the payload.
- Deserialize the payload with Marshal.load to execute the command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
This is about a way to turn harmless-looking data into a harmful command when a Ruby program reads it back. The author shows how to build a chain of objects that, when loaded, runs a system command. It's like a set of dominoes that, when tipped, leads to code execution.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.