{"id":59357,"date":"2024-09-01T20:29:44","date_gmt":"2024-09-01T17:29:44","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181172\/rails_json_yaml_scanner.rb.txt"},"modified":"2024-09-01T20:29:44","modified_gmt":"2024-09-01T17:29:44","slug":"ruby-on-rails-json-processor-yaml-deserialization-scanner","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/ruby-on-rails-json-processor-yaml-deserialization-scanner\/","title":{"rendered":"Ruby On Rails JSON Processor YAML Deserialization Scanner"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Auxiliary<br \/>include Msf::Exploit::Remote::HttpClient<br \/>include Msf::Auxiliary::Scanner<\/p>\n<p>def initialize(info={})<br \/>super(update_info(info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Ruby on Rails JSON Processor YAML Deserialization Scanner&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module attempts to identify Ruby on Rails instances vulnerable to<br \/>an arbitrary object instantiation flaw in the JSON request processor.<br \/>},<br \/>&#8216;Author&#8217; =&gt;<br \/>[<br \/>&#8216;jjarmoc&#8217;, # scanner module<br \/>&#8216;hdm&#8217; # CVE-2013-0156 scanner, basis of this technique.<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt;<br \/>[<br \/>[&#8216;CVE&#8217;, &#8216;2013-0333&#8217;]]))<\/p>\n<p>register_options([<br \/>OptString.new(&#8216;TARGETURI&#8217;, [true, &#8220;The URI to test&#8221;, &#8220;\/&#8221;]),<br \/>OptEnum.new(&#8216;HTTP_METHOD&#8217;, [true, &#8216;HTTP Method&#8217;, &#8216;POST&#8217;, [&#8216;GET&#8217;, &#8216;POST&#8217;, &#8216;PUT&#8217;]]),<br \/>])<br \/>end<\/p>\n<p>def send_probe(pdata)<br \/>res = send_request_cgi({<br \/>&#8216;uri&#8217; =&gt; normalize_uri(datastore[&#8216;TARGETURI&#8217;]),<br \/>&#8216;method&#8217; =&gt; datastore[&#8216;HTTP_METHOD&#8217;],<br \/>&#8216;ctype&#8217; =&gt; &#8216;application\/json&#8217;,<br \/>&#8216;data&#8217; =&gt; pdata<br \/>})<br \/>end<\/p>\n<p>def run_host(ip)<\/p>\n<p># Straight JSON as a baseline<br \/>res1 = send_probe(<br \/>&#8220;{ \\&#8221;#{Rex::Text.rand_text_alpha(rand(8)+1)}\\&#8221; : \\&#8221;#{Rex::Text.rand_text_alpha(rand(8)+1)}\\&#8221; }&#8221;<br \/>)<\/p>\n<p>unless res1<br \/>vprint_status(&#8220;#{rhost}:#{rport} No reply to the initial JSON request&#8221;)<br \/>return<br \/>end<\/p>\n<p>if res1.code.to_s =~ \/^[5]\/<br \/>vprint_error(&#8220;#{rhost}:#{rport} The server replied with #{res1.code} for our initial JSON request, double check TARGETURI and HTTP_METHOD&#8221;)<br \/>return<br \/>end<\/p>\n<p># Deserialize a hash, this should work if YAML deserializes.<br \/>res2 = send_probe(&#8220;&#8212; {}\\n&#8221;.gsub(&#8216;:&#8217;, &#8216;\\u003a&#8217;))<\/p>\n<p>unless res2<br \/>vprint_status(&#8220;#{rhost}:#{rport} No reply to the initial YAML probe&#8221;)<br \/>return<br \/>end<\/p>\n<p># Deserialize a malformed object, inducing an error.<br \/>res3 = send_probe(&#8220;&#8212; !ruby\/object:\\x00&#8221;.gsub(&#8216;:&#8217;, &#8216;\\u003a&#8217;))<\/p>\n<p>unless res3<br \/>vprint_status(&#8220;#{rhost}:#{rport} No reply to the second YAML probe&#8221;)<br \/>return<br \/>end<\/p>\n<p>vprint_status(&#8220;Probe response codes: #{res1.code} \/ #{res2.code} \/ #{res3.code}&#8221;)<\/p>\n<p>if (res2.code == res1.code) and (res3.code != res2.code) and (res3.code != 200)<br \/># If first and second requests are the same, and the third is different but not a 200, we&#8217;re vulnerable.<br \/>print_good(&#8220;#{rhost}:#{rport} is likely vulnerable due to a #{res3.code} reply for invalid YAML&#8221;)<br \/>report_vuln({<br \/>:host =&gt; rhost,<br \/>:port =&gt; rport,<br \/>:proto =&gt; &#8216;tcp&#8217;,<br \/>:name =&gt; self.name,<br \/>:info =&gt; &#8220;Module triggered a #{res3.code} reply&#8221;,<br \/>:refs =&gt; self.references<br \/>})<br \/>else<br \/># Otherwise we&#8217;re not likely vulnerable.<br \/>vprint_status(&#8220;#{rhost}:#{rport} is not likely to be vulnerable or TARGETURI &amp; HTTP_METHOD must be set&#8221;)<br \/>end<br \/>end<br \/>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Auxiliaryinclude Msf::Exploit::Remote::HttpClientinclude Msf::Auxiliary::Scanner def initialize(info={})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Ruby on Rails JSON Processor YAML Deserialization Scanner&#8217;,&#8216;Description&#8217; =&gt; %q{This module attempts to identify Ruby on Rails instances vulnerable toan arbitrary object instantiation flaw in the JSON request processor.},&#8216;Author&#8217; =&gt;[&#8216;jjarmoc&#8217;, # scanner module&#8216;hdm&#8217; # CVE-2013-0156 scanner, basis &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-59357","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=59357"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59357\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}