News for hackers. Stuff that matters.
Re:Metasploit Rails 3 Remote Code Execution Hours Away by INTPenis on Wednesday January 09, 2013 @11:08PM (#5035336)
But how do you patch it?
Re:Metasploit Rails 3 Remote Code Execution Hours Away by kapilkale on Wednesday January 09, 2013 @11:23PM (#5035389)
If running Rails 3, you can disable XML parsing of parameters by adding this to an initializer:

  ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
source: https://groups.google.com/forum/#!topic/rubyonrails-security...
Re:Metasploit Rails 3 Remote Code Execution Hours Away by kapilkale on Thursday January 10, 2013 @12:06AM (#5035559)
What happens with this fix is scary at first, but is actually OK.

If you patched as described, and run the exploit code on your local server, the exploit code will return a 200 response. As in:

  [-] POSTing puts 'boom' to http://localhost:3000 ...
  [-] Success!
This doesn't mean your site is vulnerable. Rails is entirely disregarding the parameters as specified by your initializer code.

Testing locally, watch your server when the request comes through and ensure there are no parameters being registered. You don't want to see something like this:

  Started POST "/" for 127.0.0.1 at 2013-01-09 21:00:04 -0800
  Processing by StartController#index as */*
  Parameters: {"secret"=>"--- !ruby/hash:ActionDispatch::Routing::RouteSet::NamedRouteCollection\n? {}\n: !ruby/object:OpenStruct\n  table:\n    :defaults:\n      :action: create\n      :controller: foos\n    :required_parts: []\n    :requirements:\n      :action: create\n      :controller: foos\n    :segment_keys:\n    - :format\n  modifiable: true"}
Re:Metasploit Rails 3 Remote Code Execution Hours Away by gautamc on Thursday January 10, 2013 @12:34AM (#5035641)
On a patched server I see a Hash::DisallowedType (Disallowed type attribute: "yaml") exception raised by activesupport.

As a simpler test-case, I modified the rails_rce.rb ( for CVE-2013-0156 )and passed a simpler yaml that creates a Time object:

yaml = %{ --- !ruby/object:Time {} } xml = %{ <?xml version="1.0" encoding="UTF-8"?> <#{param} type="yaml">#{yaml}</#{param}> }.strip

print_info "POSTing #{code} to #{url} ..."

response = http_request( :method => :post, :url => url, :headers => {:content_type => 'text/xml'}, :body => xml )

This way a vulnerable server's log file shows something like give below(ie. the Time object was actually created from the yaml):

Started POST "/users/sign_in" for 127.0.0.1 at 2013-01-10 00:26:40 -0500 Processing by Devise::SessionsController#create as / Parameters: {"secret"=>1969-12-31 19:00:00 -0500}

A patched server raises a Hash::DisallowedType (Disallowed type attribute: "yaml") exception.

Re:Metasploit Rails 3 Remote Code Execution Hours Away by kapilkale on Thursday January 10, 2013 @12:48AM (#5035681)
I'm unable to reproduce- not sure why. Seeing no parameters. I'm getting:

  Started POST "/user/sign_in" for 127.0.0.1 at 2013-01-09 21:40:56 -0800
  Processing by UsersController#sign_in as */*
If I comment out the patch, I see:

  Parameters: {"secret"=>1969-12-31 16:00:00 -0800}
So I suspect others may not see the same exception... I'm using ActiveSupport 3.0.3, fyi.
Re:Metasploit Rails 3 Remote Code Execution Hours Away by gautamc on Thursday January 10, 2013 @01:10AM (#5035747)
Yep. I see what you mean.

activesupport-3.2.11/lib/active_support/core_ext/hash/conversions.rb has a -- DISALLOWED_XML_TYPES = %w(symbol yaml) -- which is used by its def typecast_xml_value to raise the exception.

I don't see these lines of code in activesupport-3.0.3/lib/active_support/core_ext/hash/conversions.rb

In my case I could upgrade to 3.2.11.

In your case, I am guessing you added the lines of code that disable xml and yaml parameter parsing to an initializer (or application.rb). This way, activesupport simply wouldn't try to convert the parameter value in question into a ruby object.

Re:Metasploit Rails 3 Remote Code Execution Hours Away by kapilkale on Thursday January 10, 2013 @01:31AM (#5035805)
Right. Thanks!
Re:Metasploit Rails 3 Remote Code Execution Hours Away by j_mac on Thursday January 17, 2013 @12:59PM (#5073978)
Thanks for posting this, you gave me the bits I needed to make a simple test I could use to verify the patch, without needing the metasploit stuff. (on rails 2.3, I don't get the disallowedType error, but I can verify in the logs that the patch works)

http://www.railsperformance.com/2013/01/simple-test-for-rail...

Re:Metasploit Rails 3 Remote Code Execution Hours Away by lengarvey on Wednesday January 09, 2013 @11:24PM (#5035395)
If you're running a relatively new version of Rails (hopefully 3.2.10) you can just goto your app on your dev machine and type:

bundle update rails

Then commit and deploy in the usual manner. You'll probably experience no issues with your application, but it's good practice to run your test suite before you do any sort of production deploy anyway.

If you're running an older version of Rails (pre bundler) or if you don't have a solid test-suite, you'll have a tougher time updating. But you definitely need to put aside time to figure it out now.

Re:Metasploit Rails 3 Remote Code Execution Hours Away by bonzoesc on Wednesday January 09, 2013 @11:56PM (#5035519)
You'll need to change the version of rails listed in the Gemfile. I don't think "bundle update" modifies that.
Re:Metasploit Rails 3 Remote Code Execution Hours Away by lengarvey on Thursday January 10, 2013 @12:13AM (#5035584)
Actually it depends on what your Gemfile looks like. If you've specified the exact version in your Gemfile you'll need to edit it before running `bundle update rails`. This means your Gemfile might look like:

    gem 'rails', '3.2.10'
Running `bundle update rails` when you've absolutely specified the version number won't do anything. Your Gemfile.lock file (which is the file that bundler uses to determine which gems to require) won't be changed. Instead of absolutely specifying the version of Rails you want to use, considering using the '~>' specifier. My Gemfile at Airtasker looks like:

    gem 'rails', '~> 3.2.8'
That means that when I run `bundle update rails` it will update the patch version of rails. Our Gemfile.lock has the following entry for rails:

    rails (3.2.11)
By using the '~>' specifier it means that we can easily update our gems patch versions without worrying about API changes between major and minor versions.

You can read: http://gembundler.com/v1.2/gemfile.html to find out more.

Re:Metasploit Rails 3 Remote Code Execution Hours Away by dasil003 on Thursday January 10, 2013 @04:21AM (#5036127)
For completeness it's also worth mentioning that gem 'rails', '~> 3.2.0' may not necessarily update Rails to the latest version when you run `bundle update rails`. The reason is if there is another gem which requires a gem that does not match the requirement of the latest version of Rails, it will backtrack until it finds a compatible version across the board.

So you will want to double-check the specific version that you end up with. If it doesn't work you probably can fix it with `bundle update rails something_else`, unless you have a true conflict in which case you will have to do some spelunking yourself, and perhaps the Rails hotfix should be in place in your app first.

Re:Metasploit Rails 3 Remote Code Execution Hours Away by INTPenis on Thursday January 10, 2013 @02:03AM (#5035881)
Thank you, in fact I had the 3.1.2 version specified in my Gemfile. So I changed that to 3.1.10 and now bundle show rails shows that version as installed so I think I'm in the clear.
Re:Metasploit Rails 3 Remote Code Execution Hours Away by bonzoesc on Thursday January 10, 2013 @02:05AM (#5035884)
You may want to change it to a less-specific version so future patches (and they are coming) are less work to apply.
Re:Metasploit Rails 3 Remote Code Execution Hours Away by outside1234 on Thursday January 10, 2013 @12:03AM (#5035547)
That's exactly what bundle update does.
Re:Metasploit Rails 3 Remote Code Execution Hours Away by guywithabike on Thursday January 10, 2013 @12:14AM (#5035588)
Only in Gemfile.lock. If you've hard-coded a version in Gemfile, you'll need to update it.

Eg. These will update fine:

    gem "rails"
    gem "rails", "~> 3.2"
This wont:

    gem "rails", "= 3.2.10"
Re:Metasploit Rails 3 Remote Code Execution Hours Away by jaggederest on Thursday January 10, 2013 @12:21AM (#5035607)
No, bundle update only updates the Gemfile.lock

If your gemfile looks like:

    gem 'rails', '3.2.10'
Then `bundle update` does nothing.
Re:Metasploit Rails 3 Remote Code Execution Hours Away by danielpal on Wednesday January 09, 2013 @11:10PM (#5035346)
bundle update activesupport