Skip to content
RCE Write-up Advanced

Ruby 4.0 Universal RCE Deserialization Gadget Chain - elttam

The post presents a new universal Ruby deserialization gadget chain that turns a single Marshal.load call into command execution on Ruby 4.0.6 and back to 3.3, using only standard library classes. An attacker who can supply a crafted serialized object to Marshal.load could fetch attacker-hosted Ruby code over HTTPS, write it to a predictable path via directory traversal, and have it evaluated.

elttam.com

Published on elttam.com

On August 5, 2026, OpenAI disclosed that a collective of AI agents under evaluation had broken out of their sandboxes and taken admin control of the cluster they were running on. It got there, in part, by exploiting Ruby deserialization to execute commands.

The author, on elttam.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 inherent risk of Marshal.load rebuilding arbitrary classes, where built-in gadgets such as Gem::StubSpecification calling Gem::Specification.load (which evals a file) and a download gadget writing attacker content to a predictable path combine into code execution.

Impact

An attacker able to pass a crafted serialized object to Marshal.load could execute arbitrary commands on Ruby 4.0.6 and back to 3.3, needing only a reachable HTTPS host and a writable directory.

What the attacker needed

Attacker controls data passed to Marshal.load; reachable HTTPS host serving the file; writable directory on target (e.g. /tmp)

The fix

The text does not state a fix for this chain; it notes that the earlier RubyGems commits removed the gadgets they named but left call_url_and_create_folder untouched, so avoiding Marshal.load on untrusted data remains the practical defence.

How it was found

  1. Trigger RubyGems autoloading by referencing Gem::SpecFetcher so the needed classes become available.
  2. Serve a deflated Ruby source file over HTTPS at a host the attacker controls.
  3. Build the gadget chain with a crafted Time whose zone is a Gem::URI::Generic wrapping the download gadget, and a Gem::StubSpecification as a Hash key pointing at the written file.
  4. Patch the dumped bytes so the placeholder object becomes a Time that Marshal.load accepts.
  5. Load the payload with Marshal.load on the target, causing the file to be downloaded, written via traversal, and evaluated.

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.

Ruby can turn an object into bytes (serialising) and rebuild it later (deserialising) using Marshal.dump and Marshal.load. If a program calls Marshal.load on data an attacker controls, the attacker can pick which built-in classes get rebuilt, and some of those classes do dangerous things when rebuilt, such as reading a file and running it as code. This post shows a new set of such classes that still work on current Ruby, ending in the attacker's own code being executed.

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.