Skip to content

Commit aa0412d

Browse files
authored
Merge pull request #14 from flashnuke/fix/iface_name
Fix/iface name
2 parents fe756bf + bf54ac5 commit aa0412d

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

deadnet.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323

2424
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):
2626
self.network_interface = iface
2727
self.arp_poison_interval = s_time
2828
self.ipv6_preflen = ipv6_preflen or IPV6_PREFLEN
@@ -37,13 +37,15 @@ def __init__(self, iface, cidrlen, s_time, gateway, disable_ipv6, ipv6_preflen):
3737
self.subnet_ipv4 = self.user_ipv4.split(".")[:3]
3838
self.subnet_ipv4_sr = f"{'.'.join(self.subnet_ipv4)}.0/{self.cidrlen_ipv4}"
3939

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)
4141
if not self.gateway_ipv4:
4242
raise Exception(f"{RED}[!]{WHITE} Unable to automatically set IPv4 gateway address, try setting manually"
4343
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()
4545
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}")
4749
self.gateway_ipv6 = mac2ipv6_ll(self.gateway_mac, IPV6_LL_PREF)
4850

4951
self.print_settings()
@@ -72,7 +74,7 @@ def get_gateway_mac(self):
7274
for line in output.split('\n'):
7375
columns = line.split()
7476
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:
7678
gateway_hwaddr = columns[4]
7779
break
7880
except Exception as exc:
@@ -88,6 +90,7 @@ def user_abort(self):
8890
def print_settings(self):
8991
printf("- net iface" + self.network_interface.rjust(38))
9092
printf("- sleep time" + str(self.arp_poison_interval).rjust(32) + "[sec]")
93+
printf("- MAC gateway" + self.gateway_mac.rjust(36))
9194
printf("- IPv4 subnet" + self.subnet_ipv4_sr.rjust(36))
9295
printf("- IPv4 gateway" + self.gateway_ipv4.rjust(35))
9396
printf("- IPv6 gateway" + self.gateway_ipv6.rjust(35))
@@ -197,6 +200,6 @@ def get_gateway_ipv4(iface):
197200
arguments = define_args()
198201
invalidate_print() # after arg parsing
199202

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)
202205
attacker.start_attack()

utils/argparser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ def define_args():
2121
help=f"set the sleep time between each arp poison attempt (default -> {_DEF_SLEEPTIME}[sec])",
2222
required=False)
2323

24-
parser.add_argument("-g", "--set-gateway", dest='gateway', type=str, metavar=(""), default=None,
25-
help="set the gateway ip manually (defaults to x.x.x.1)",
24+
parser.add_argument("-g", "--gateway-ipv4", dest='gateway_ipv4', type=str, metavar=(""), default=None,
25+
help="set the gateway ipv4 manually (defaults to x.x.x.1)",
26+
required=False)
27+
28+
parser.add_argument("-M", "--gateway-mac", dest='gateway_mac', type=str, metavar=(""), default=None,
29+
help="set the gateway mac address (use if unable to fetch automatically)",
2630
required=False)
2731

2832
parser.add_argument("-6", "--disable-ipv6", dest='disable_ipv6', action="store_true",
2933
default=False, help="disable IPv6 dead router attack"
3034
" (enabled by default)", required=False)
3135

32-
parser.add_argument("-pl", "--set-preflen", dest='preflen', type=int, metavar=(""), default=_DEF_PREFLEN,
36+
parser.add_argument("-p", "--set-preflen", dest='preflen', type=int, metavar=(""), default=_DEF_PREFLEN,
3337
help=f"set the prefix length of the IPv6 subnet (default -> {_DEF_PREFLEN})",
3438
required=False)
3539

utils/methods.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import re
12
import sys
23
import time
34

45

6+
def is_valid_mac(mac):
7+
return re.match(r'^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$', mac)
8+
9+
510
def get_ts_ms():
611
return int(time.time() * 1_000)
712

0 commit comments

Comments
 (0)