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.
Recently we encountered a ruby deserialization vulnerability that existed within a rails application. The backend application was using very recent ruby and rails release.
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
- Use Sprockets::Manifest to write arbitrary file with controlled content.
- Use Gem::RequestSet::GemDependencyAPI's load method to instance_eval the written file.
- For the alternative chain, set up a Rack::Response with a Set body and Sprockets::ERBProcessor as writer.
- Use Gem::Security::Policy to make to_s return a hash.
- Set environment to Rails::Initializable::Initializer with Sprockets::Context.
- 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.