22
22
23
23
24
24
class DeadNet :
25
- def __init__ (self , iface , cidrlen , s_time , gateway , disable_ipv6 , ipv6_preflen ):
25
+ def __init__ (self , iface , cidrlen , s_time , gateway_ipv4 , gateway_mac , disable_ipv6 , ipv6_preflen ):
26
26
self .network_interface = iface
27
27
self .arp_poison_interval = s_time
28
28
self .ipv6_preflen = ipv6_preflen or IPV6_PREFLEN
@@ -37,13 +37,15 @@ def __init__(self, iface, cidrlen, s_time, gateway, disable_ipv6, ipv6_preflen):
37
37
self .subnet_ipv4 = self .user_ipv4 .split ("." )[:3 ]
38
38
self .subnet_ipv4_sr = f"{ '.' .join (self .subnet_ipv4 )} .0/{ self .cidrlen_ipv4 } "
39
39
40
- self .gateway_ipv4 = gateway or self .get_gateway_ipv4 (self .network_interface )
40
+ self .gateway_ipv4 = gateway_ipv4 or self .get_gateway_ipv4 (self .network_interface )
41
41
if not self .gateway_ipv4 :
42
42
raise Exception (f"{ RED } [!]{ WHITE } Unable to automatically set IPv4 gateway address, try setting manually"
43
43
f" by passing (-g, --set-gateway)..." )
44
- self .gateway_mac = self .get_gateway_mac ()
44
+ self .gateway_mac = gateway_mac or self .get_gateway_mac ()
45
45
if not self .gateway_mac :
46
- raise Exception (f"{ RED } [-]{ WHITE } Unable to get gateway mac -> { self .gateway_ipv4 } " )
46
+ raise Exception (f"{ RED } [-]{ WHITE } Unable to retrieve gateway ({ self .gateway_ipv4 } ) mac address" )
47
+ elif not is_valid_mac (self .gateway_mac ):
48
+ raise Exception (f"{ RED } [-]{ WHITE } Invalid gateway mac address -> { self .gateway_mac } " )
47
49
self .gateway_ipv6 = mac2ipv6_ll (self .gateway_mac , IPV6_LL_PREF )
48
50
49
51
self .print_settings ()
@@ -72,7 +74,7 @@ def get_gateway_mac(self):
72
74
for line in output .split ('\n ' ):
73
75
columns = line .split ()
74
76
if len (columns ) >= 4 :
75
- if columns [3 ] == 'lladdr' and columns [4 ] != '<incomplete>' and columns [2 ] == iface :
77
+ if columns [3 ] == 'lladdr' and columns [4 ] != '<incomplete>' and columns [2 ] == self . network_interface :
76
78
gateway_hwaddr = columns [4 ]
77
79
break
78
80
except Exception as exc :
@@ -88,6 +90,7 @@ def user_abort(self):
88
90
def print_settings (self ):
89
91
printf ("- net iface" + self .network_interface .rjust (38 ))
90
92
printf ("- sleep time" + str (self .arp_poison_interval ).rjust (32 ) + "[sec]" )
93
+ printf ("- MAC gateway" + self .gateway_mac .rjust (36 ))
91
94
printf ("- IPv4 subnet" + self .subnet_ipv4_sr .rjust (36 ))
92
95
printf ("- IPv4 gateway" + self .gateway_ipv4 .rjust (35 ))
93
96
printf ("- IPv6 gateway" + self .gateway_ipv6 .rjust (35 ))
@@ -197,6 +200,6 @@ def get_gateway_ipv4(iface):
197
200
arguments = define_args ()
198
201
invalidate_print () # after arg parsing
199
202
200
- attacker = DeadNet (arguments .iface , arguments .cidrlen , arguments .s_time , arguments .gateway ,
201
- arguments .disable_ipv6 , arguments .preflen )
203
+ attacker = DeadNet (arguments .iface , arguments .cidrlen , arguments .s_time , arguments .gateway_ipv4 ,
204
+ arguments .gateway_mac , arguments . disable_ipv6 , arguments .preflen )
202
205
attacker .start_attack ()
0 commit comments