Universal RCE with Ruby YAML.load
The author found a way to achieve remote code execution (RCE) via Ruby's YAML.load by constructing a YAML payload that triggers a deserialization gadget chain, originally discovered for Marshal.load. An attacker who can supply YAML to YAML.load could execute arbitrary commands on the server.
Published on staaldraad.github.io
Last year Luke Jahnke wrote an excellent blog post on the elttam blog about finding a universal RCE deserialization gadget chain for Ruby 2.x. In the post he discusses the process of finding and eventually exploiting a gadget chain for Marshal.load.
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 use of YAML.load on untrusted input, which allows instantiation of arbitrary Ruby objects and triggers a gadget chain leading to command execution.
Impact
An attacker who can supply YAML input to YAML.load could execute arbitrary commands on the server, leading to full compromise.
What the attacker needed
Application uses YAML.load on user input
How it was found
- Generate a YAML payload using YAML.dump on a Gem::Requirement object initialized with a dependency list.
- Observe that the generated YAML does not contain the full gadget chain and fails to produce RCE.
- Manually craft a YAML payload that sets up the required objects: Gem::Requirement with a Gem::DependencyList containing Gem::Source::SpecificFile objects, one with a Gem::StubSpecification whose loaded_from field contains a command.
- Load the crafted YAML with YAML.load to trigger the gadget chain and 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.
YAML is a data format like JSON, often used for configuration files. Ruby's YAML.load method can turn YAML text into Ruby objects, and if an attacker controls that text, they can craft it to create objects that, when used, run commands on the server. This is called deserialization RCE.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.