Skip to content
RCE Write-up Advanced

Ruby Deserialization - Gadget on Rails

The authors found a new Ruby deserialization gadget chain that works on recent Ruby and Rails versions, allowing remote code execution. They achieved this by combining a file-write primitive from Sprockets::Manifest with a file-execution primitive from Gem::RequestSet::GemDependencyAPI, and later developed a more complex chain using Rack::Response and Sprockets::ERBProcessor.

HTTPVoid Follow

Published on httpvoid.com

Recently we encountered a ruby deserialization vulnerability that existed within a rails application. The backend application was using very recent ruby and rails release.

HTTPVoid (@httpvoid0x2f), on httpvoid.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 allows attackers to instantiate arbitrary classes and invoke dangerous methods during deserialization.

What the attacker needed

Ruby deserialization vulnerability; Ability to supply crafted serialized data

How it was found

  1. Use Sprockets::Manifest to write arbitrary file with controlled content.
  2. Use Gem::RequestSet::GemDependencyAPI's load method to instance_eval the written file.
  3. For the alternative chain, set up a Rack::Response with a Set body and Sprockets::ERBProcessor as writer.
  4. Use Gem::Security::Policy to make to_s return a hash.
  5. Set environment to Rails::Initializable::Initializer with Sprockets::Context.
  6. Trigger the chain via ActiveRecord::Associations::Association marshal_load.

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.

Deserialization is when an application turns stored data back into objects. If an attacker can control that data, they may be able to make the application create objects that trigger dangerous methods. This report shows how to chain such methods in Ruby on Rails to run arbitrary commands.

What is RCE?

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

More by HTTPVoid

View all

1 more disclosed report, best first.

More from Ruby on Rails

View all

The newest disclosed reports for this program.

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.