Skip to content
RCE Write-up Advanced

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.

Alex Leahu Follow

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.

Alex Leahu, on blog.includesecurity.com

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

  1. Set up a Ruby environment with the target application's gems.
  2. Search for classes with marshal_load and instance variables that call methods.
  3. Build gadgets from both ends: initial kick-off and command execution.
  4. Chain gadgets by setting instance variables to reference each other.
  5. Serialize the final gadget with Marshal.dump to create the payload.
  6. 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.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.