====== Networking - DNS - DNS Response Crafter ======
===== Make lots of DNS requests in quick succession: =====
import dns.resolver
resolver = dns.resolver.Resolver()for x in range(2, 10):
for i in range(85, 200):
try:
print resolver.query(chr(i) * x + '.com', 'A')
except:
pass
**NOTE:**
See: https://dnspython.readthedocs.io/en/latest/_modules/dns/resolver.html
----
===== Craft Specific DNS requests =====
import socket
from scapy . all import *
UDP_IP_ADDRESS =
RESPONSE_IP = '123.123.123.123' # Can be any address.
UDP_PORT_NO = 53 # Bind to DNS port.
TTL = 86400 # Time to live in cache.
NAME_POINTER = "\xc0\x0c " # Message compression rfc 1035 4.1.4910.
def CraftResponse(addr, data):
dns = DNS(data)
dnsrr = DNSRR(rrname=NAMEPOINTER, ttl=TTL, rdata=RESPONSEIP)
opt = DNSRROPT(rrname= '.' ,type= 'OPT' , rclass=512,
extrcode=0, version=0, z=0, rdlen=0)
return \ # Assemble and return packet.
IP(dst=addr[0])/\
UDP(dport=addr[1], sport=UDPPORTNO) /\
DNS(id=dns.id, qr=1, aa=0, tc=0,
rd=dns.rd, ra=1, z=0, ad=0, cd=0,
qdcount=1, ancount=1, nscount=0, arcount=1,
qd=dns.qd, an=dnsrr, ar=opt)
def main():
# Set up and bind socket for UDP packets.
s = socket.socket(socket.AFINET, socket.SOCKDGRAM)
s.bind(UDPIPADDRESS, UDPPORTNO)
print "Listening..."
while 1:
data, addr = s.recvfrom(65535)
packet = CraftResponse(addr, data)
send(packet, verbose=0)
if __name__ == 'main':
main()