Remote Code Execution via Ruby on Rails Active Storage Insecure Deserialization
An insecure deserialization vulnerability in Ruby on Rails Active Storage allowed an attacker to pass a crafted signed message containing a malicious Ruby object, which was deserialized with Marshal.load() without validation. By chaining this with a file disclosure bug to obtain the secret key, an unauthenticated attacker could achieve remote code execution.
zerodayinitiative.com
Published on zerodayinitiative.com
An insecure deserialization vulnerability has been reported in the ActiveStorage component of Ruby on Rails. This vulnerability is due to deserializing a Ruby object within an HTTP URL using Marshal.load() without sufficient validation.
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
The application deserializes a user-supplied value using Marshal.load() after only verifying its integrity with a secret that may be known or disclosed, without validating the object's class or content.
Impact
A remote unauthenticated attacker could achieve arbitrary code execution under the security context of the affected Ruby on Rails application, but this requires chaining with CVE-2019-5418 to obtain the secret key in production.
What the attacker needed
Rails 5.2.x or 6.0.0.x with Active Storage; Secret key known or disclosed (e.g., via CVE-2019-5418); Ability to send HTTP requests to the application
How it was found
- Obtain the secret key used to sign messages, for example by exploiting CVE-2019-5418 to read credentials.yml.enc and master.key, or by knowing the application name in development mode.
- Craft a malicious serialized Ruby object, such as ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy, that executes code when deserialized.
- Generate a valid signed message containing the malicious object using the secret key.
- Send an HTTP request to a URL containing /rails/active_storage/disk/ with the crafted encoded_key and encoded_token parameters.
- The application verifies the signature, decodes the message, and calls Marshal.load() on it, executing the malicious object.
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 on Rails is a framework for building web applications. Active Storage is a part of it that handles file uploads and downloads. The bug is that when someone requests a file, the application takes a piece of data from the URL and turns it back into a Ruby object without checking it properly. If an attacker can make that data look valid, they can make the application run their own code.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.