JSchmoe

open DNS resolver scanner

Mar 21st, 2016
159
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import logging
  4. logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
  5. from scapy.all import *
  6. import random, threading
  7.  
  8. def gen_ip():
  9.     try:
  10.         while True:
  11.             yield ".".join([str(random.randint(0,255)) for i in range(4)])
  12.     except KeyboardInterrupt:
  13.         exit()
  14.  
  15. def check_answer_len(ip):
  16.     packetlen = len(IP(dst=ip)/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname="mibbit.com", qtype="ALL")))
  17.    
  18.     answer = sr1(IP(dst=ip)/UDP(dport=53)/DNS(rd=1,qd=DNSQR(qname="mibbit.com", qtype="ALL")),verbose=0, timeout=1)#Mibbit gives good gainz
  19.    
  20.     try:
  21.         print("Sent packet of size: "+str(packetlen))
  22.         print(str(ip)+" returned reply of length: "+str(len(answer)))
  23.         print("Size increased by "+str(100*(float(len(answer))/float(packetlen)-100))+"%")
  24.         with open("./dnsips","a") as f:
  25.             if len(answer) > packetlen:
  26.                 try:
  27.                     f.write(ip+"\t"+str(packetlen)+"->"+str(len(answer))+"\n")
  28.                 except:
  29.                     print("erro writn")
  30.         return
  31.     except Exception as e:
  32.         print(str(e))
  33.        
  34. def server_scan():
  35.     for ip in gen_ip():
  36.         try:
  37.             print(ip)
  38.             resp = sr1(IP(dst=ip)/UDP(dport=53)/DNS(qd=DNSQR(qname="google.com", qtype="A")),timeout=1,verbose=0)
  39.             if not resp:
  40.                 continue
  41.             check_answer_len(ip)
  42.         except Exception as e:
  43.             print("Exception: "+str(e))
  44.             break
  45.            
  46. for i in range(50):
  47.     try:
  48.         threading.Thread(target=server_scan).start()
  49.     except:
  50.         exit()
  51.            
  52. server_scan()
RAW Paste Data