SpiderLabs Blog

Open Challenge: Ruby YAML.load(YOUR_STRING_HERE) == RCE?

Written by Jonathan Claudius | Apr 27, 2015 12:41:00 PM

For some, the challenge may already be quite clear by the title of this post, but I'm going to add a little color for the sake of clarity.

Background

Back in January 2013, there was a lot of excitement about a vulnerability in Ruby on Rails (CVE-2013-0156). In short, the vulnerability allowed a remote attacker to craft a request to Rails that would allow object creation via YAML deserialization and result in remote code execution (RCE). You can check the plethora of blog posts that covered the topic at the time to learn more (I've provided some of the better ones below as references).

Since that time, there has been a lot of discussion surrounding the use of Ruby YAML.load on user-controlled content in any Ruby application because of the RCE risk. And of course, I understand that it's important for us to learn from past mistakes and try to make a safer way to load YAML content. Examples of this include using something like YAML.safe_load or using white-listing techniques to restrict your object class exposure when you actually need to deserialize objects using YAML.load.

 

My Concerns

However, one of my concerns about such potential RCE scenarios, and maybe I'm not alone, is that of context. The issue I have with context is that in all the public PoC's I've observed, the attacker needed either an existing object behaving badly (ie. ActionController::Routing::RouteSet::NamedRouteCollection) or the creation of a contrived dangerous object being loaded manually to achieve such RCE.

The question I'd like posited is whether or not it's possible to achieve arbitrary RCE with a YAML.load using only standard lib objects, which are loaded by default. After all, if you're allowing the loading of dangerous/contrived objects with eval behavior, isn't this in the same vein as evaluating a user-controlled string?

I've done a little bit of poking around this topic myself and frankly, I've come up short. I've even consulted other fellow Rubyists to provide such an example, and I've yet to get a positive response that was acceptable to demonstrate such a risk.

 

The Challenge

As a Rubyist and a Security professional, I'm compelled to test such things and seek the truth. As such, I'm opening up a community challenge to see if there are some smart people out there willing to take on such a challenge.

Here are the basic constraints:

  • Must use a currently supported Ruby version
  • Must be a string that is supplied to the YAML.load function
  • Must use STDLIB only (ie. whatever's available to you after typing "irb" at a command prompt, no additional libs, requires, or .irbrc-type behavior)
  • Must be able to do something with the RCE (i.e., throw a shell, exfill, etc.)

The challenge is open as of now and will be completed on Thursday, May 14th. I will update this post as soon as the challenge is solved or will provide an update if it goes unsolved in the time window.

 

Submissions

Please submit your solutions to the challenge by sending an e-mail to trustwaveadvisories@trustwave.com and include the subject line "Ruby YAML.load Challenge".

References

***UPDATE - May 29, 2015--No one solved the challenge, bummer. Thanks for playing!