{"id":59369,"date":"2024-09-01T21:29:55","date_gmt":"2024-09-01T18:29:55","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181220\/dns_amp.rb.txt"},"modified":"2024-09-01T21:29:55","modified_gmt":"2024-09-01T18:29:55","slug":"dns-amplification-scanner","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/dns-amplification-scanner\/","title":{"rendered":"DNS Amplification 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::Auxiliary::Report<br \/>include Msf::Exploit::Capture<br \/>include Msf::Auxiliary::UDPScanner<br \/>include Msf::Auxiliary::DRDoS<\/p>\n<p>def initialize<br \/>super(<br \/>&#8216;Name&#8217; =&gt; &#8216;DNS Amplification Scanner&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>This module can be used to discover DNS servers which expose recursive<br \/>name lookups which can be used in an amplification attack against a<br \/>third party.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [ &#8216;xistence &lt;xistence[at]0x90.nl&gt;&#8217;], # Original scanner module<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;References&#8217; =&gt;<br \/>[<br \/>[&#8216;CVE&#8217;, &#8216;2006-0987&#8217;],<br \/>[&#8216;CVE&#8217;, &#8216;2006-0988&#8217;],<br \/>])<\/p>\n<p>register_options( [<br \/>Opt::RPORT(53),<br \/>OptString.new(&#8216;DOMAINNAME&#8217;, [true, &#8216;Domain to use for the DNS request&#8217;, &#8216;isc.org&#8217; ]),<br \/>OptString.new(&#8216;QUERYTYPE&#8217;, [true, &#8216;Query type(A, NS, SOA, MX, TXT, AAAA, RRSIG, DNSKEY, ANY)&#8217;, &#8216;ANY&#8217; ]),<br \/>])<br \/>end<\/p>\n<p>def rport<br \/>datastore[&#8216;RPORT&#8217;]end<\/p>\n<p>def setup<br \/>super<\/p>\n<p># Check for DNS query types byte<br \/>case datastore[&#8216;QUERYTYPE&#8217;]when &#8216;A&#8217;<br \/>querypacket=&#8221;\\x01&#8243;<br \/>when &#8216;NS&#8217;<br \/>querypacket=&#8221;\\x02&#8243;<br \/>when &#8216;SOA&#8217;<br \/>querypacket=&#8221;\\x06&#8243;<br \/>when &#8216;MX&#8217;<br \/>querypacket=&#8221;\\x0f&#8221;<br \/>when &#8216;TXT&#8217;<br \/>querypacket=&#8221;\\x10&#8243;<br \/>when &#8216;AAAA&#8217;<br \/>querypacket=&#8221;\\x1c&#8221;<br \/>when &#8216;RRSIG&#8217;<br \/>querypacket=&#8221;\\x2e&#8221;<br \/>when &#8216;DNSKEY&#8217;<br \/>querypacket=&#8221;\\x30&#8243;<br \/>when &#8216;ANY&#8217;<br \/>querypacket=&#8221;\\xff&#8221;<br \/>else<br \/>print_error(&#8220;Invalid query type!&#8221;)<br \/>return<br \/>end<\/p>\n<p>targdomainpacket = []# Before every part of the domainname there should be the length of that part (instead of a &#8220;.&#8221;)<br \/># So isc.org divided is 3isc3org<br \/>datastore[&#8216;DOMAINNAME&#8217;].split(&#8216;.&#8217;).each do |domainpart|<br \/># The length of the domain part in hex<br \/>domainpartlength = &#8220;%02x&#8221; % domainpart.length<br \/># Convert the name part to a hex string<br \/>domainpart = domainpart.each_byte.map { |b| b.to_s(16) }.join()<br \/># Combine the length of the name part and the name part<br \/>targdomainpacket.push(domainpartlength + domainpart)<br \/>end<br \/># Convert the targdomainpacket to a string<br \/>targdomainpacket = targdomainpacket.join.to_s<br \/># Create a correct hex character string to be used in the packet<br \/>targdomainpacket = targdomainpacket.scan(\/..\/).map { |x| x.hex.chr }.join<br \/># DNS Packet including our target domain and query type<br \/>@msearch_probe = &#8220;\\x09\\x8d\\x01\\x00\\x00\\x01\\x00\\x00\\x00\\x00\\x00\\x00&#8221; + targdomainpacket + &#8220;\\x00\\x00&#8221; + querypacket + &#8220;\\x00\\x01&#8221;<br \/>end<\/p>\n<p>def scanner_prescan(batch)<br \/>print_status(&#8220;Sending DNS probes to #{batch[0]}-&gt;#{batch[-1]} (#{batch.length} hosts)&#8221;)<br \/># Standard packet is 60 bytes. Add the domain size to this<br \/>sendpacketsize = 60 + datastore[&#8216;DOMAINNAME&#8217;].length<br \/>print_status(&#8220;Sending #{sendpacketsize} bytes to each host using the IN #{datastore[&#8216;QUERYTYPE&#8217;]} #{datastore[&#8216;DOMAINNAME&#8217;]} request&#8221;)<br \/>@results = {}<br \/>end<\/p>\n<p>def scan_host(ip)<br \/>if spoofed?<br \/>datastore[&#8216;ScannerRecvWindow&#8217;] = 0<br \/>scanner_spoof_send(@msearch_probe, ip, datastore[&#8216;RPORT&#8217;], datastore[&#8216;SRCIP&#8217;], datastore[&#8216;NUM_REQUESTS&#8217;])<br \/>else<br \/>scanner_send(@msearch_probe, ip, datastore[&#8216;RPORT&#8217;])<br \/>end<br \/>end<\/p>\n<p>def scanner_process(data, shost, sport)<\/p>\n<p># Check the response data for \\x09\\x8d and the next 2 bytes, which contain our DNS flags<br \/>if data =~\/\\x09\\x8d(..)\/<br \/>flags = $1<br \/>flags = flags.unpack(&#8216;B*&#8217;)[0].scan(\/.\/)<br \/># Query Response<br \/>qr = flags[0]# Recursion Available<br \/>ra = flags[8]# Response Code<br \/>rcode = flags[12] + flags[13] + flags[14] + flags[15]\n<p># If these flags are set, we get a valid response<br \/># don&#8217;t test recursion available if correct answer received<br \/># at least the case with bind and &#8220;additional-from-cache no&#8221; or version &lt; 9.5+<br \/>if qr == &#8220;1&#8221; and rcode == &#8220;0000&#8221;<br \/>sendlength = 60 + datastore[&#8216;DOMAINNAME&#8217;].length<br \/>receivelength = 42 + data.length<br \/>amp = receivelength \/ sendlength.to_f<br \/>print_good(&#8220;#{shost}:#{datastore[&#8216;RPORT&#8217;]} &#8211; Response is #{receivelength} bytes [#{amp.round(2)}x Amplification]&#8221;)<br \/>report_service(:host =&gt; shost, :port =&gt; datastore[&#8216;RPORT&#8217;], :proto =&gt; &#8216;udp&#8217;, :name =&gt; &#8220;dns&#8221;)<br \/>report_vuln(<br \/>:host =&gt; shost,<br \/>:port =&gt; datastore[&#8216;RPORT&#8217;],<br \/>:proto =&gt; &#8216;udp&#8217;, :name =&gt; &#8220;DNS&#8221;,<br \/>:info =&gt; &#8220;DNS amplification &#8211; #{data.length} bytes [#{amp.round(2)}x Amplification]&#8221;,<br \/>:refs =&gt; self.references)<br \/>end<\/p>\n<p># If these flags are set, we get a valid response but recursion is not available<br \/>if qr == &#8220;1&#8221; and ra == &#8220;0&#8221; and rcode == &#8220;0101&#8221;<br \/>print_status(&#8220;#{shost}:#{datastore[&#8216;RPORT&#8217;]} &#8211; Recursion not allowed&#8221;)<br \/>report_service(:host =&gt; shost, :port =&gt; datastore[&#8216;RPORT&#8217;], :proto =&gt; &#8216;udp&#8217;, :name =&gt; &#8220;dns&#8221;)<br \/>end<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::Auxiliary::Reportinclude Msf::Exploit::Captureinclude Msf::Auxiliary::UDPScannerinclude Msf::Auxiliary::DRDoS def initializesuper(&#8216;Name&#8217; =&gt; &#8216;DNS Amplification Scanner&#8217;,&#8216;Description&#8217; =&gt; %q{This module can be used to discover DNS servers which expose recursivename lookups which can be used in an amplification attack against athird party.},&#8216;Author&#8217; =&gt; [ &#8216;xistence &lt;xistence[at]0x90.nl&gt;&#8217;], # Original scanner &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-59369","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59369","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=59369"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59369\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}