forked from iagox86/dnscat2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnstest.rb
82 lines (63 loc) · 2.3 KB
/
dnstest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
##
# dnslogger.rb
# Created July 22, 2015
# By Ron Bowes
#
# See: LICENSE.md
#
# Simply checks if you're the authoritative server.
##
$LOAD_PATH << File.dirname(__FILE__) # A hack to make this work on 1.8/1.9
require 'trollop'
require '../server/libs/dnser'
# version info
NAME = "dnstest"
VERSION = "v1.0.0"
Thread.abort_on_exception = true
# Options
opts = Trollop::options do
version(NAME + " " + VERSION)
opt :version, "Get the #{NAME} version", :type => :boolean, :default => false
opt :host, "The ip address to listen on", :type => :string, :default => "0.0.0.0"
opt :port, "The port to listen on", :type => :integer, :default => 53
opt :domain, "The domain to check", :type => :string, :default => nil, :required => true
opt :timeout, "The amount of time (seconds) to wait for a response", :type => :integer, :default => 10
end
if(opts[:port] < 0 || opts[:port] > 65535)
Trollop::die :port, "must be a valid port (between 0 and 65535)"
end
if(opts[:domain].nil?)
Trollop::die :domain, "Domain is required!"
end
puts("Starting #{NAME} #{VERSION} DNS server on #{opts[:host]}:#{opts[:port]}")
domain = (0...16).map { ('a'..'z').to_a[rand(26)] }.join() + "." + opts[:domain]
dnser = DNSer.new(opts[:host], opts[:port])
dnser.on_request() do |transaction|
request = transaction.request
if(request.questions.length < 1)
puts("The request didn't ask any questions!")
next
end
if(request.questions.length > 1)
puts("The request asked multiple questions! This is super unusual, if you can reproduce, please report!")
next
end
question = request.questions[0]
puts("Received: #{question}")
if(question.type == DNSer::Packet::TYPE_A && question.name == domain)
puts("You have the authoritative server!")
transaction.error!(DNSer::Packet::RCODE_NAME_ERROR)
exit()
else
puts("Received a different request: #{question}")
end
# Always respond with an error
transaction.error!(DNSer::Packet::RCODE_NAME_ERROR)
end
puts("Sending: #{domain}!")
DNSer.query(domain, { :type => DNSer::Packet::TYPE_A }) do |response|
# Do nothing
end
sleep(opts[:timeout])
puts("Request timed out... you probably don't have the authoritative server. :(")
exit(0)