Skip to content

Commit 2f5c00a

Browse files
authored
Update stealth_shift.py
1 parent 793bbd9 commit 2f5c00a

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

stealth_shift.py

+37-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,31 @@
1010
from banner import display_banner
1111

1212
def is_valid_interface(interface):
13-
"""Check if the interface name is valid."""
14-
valid_prefixes = ['eth', 'wlan', 'ens']
15-
return any(interface.startswith(prefix) for prefix in valid_prefixes) and all(c in string.ascii_letters + string.digits + ':-.' for c in interface)
13+
"""Check if the interface name is valid based on known naming conventions."""
14+
valid_prefixes = [
15+
'eth', 'wlan', 'ens', # Traditional Linux and newer Linux naming
16+
'em', 're', 'ath', 'wi', # BSD systems
17+
'en', 'lo', # macOS and loopback
18+
'e1000g', 'bge' # Solaris
19+
]
20+
21+
# Match common patterns for interface names
22+
valid_patterns = [
23+
r'^eth\d+$', # eth0, eth1, etc.
24+
r'^wlan\d+$', # wlan0, wlan1, etc.
25+
r'^ens\d+$', # ens33, ens160, etc.
26+
r'^em\d+$', # em0, em1, etc.
27+
r'^re\d+$', # re0, re1, etc.
28+
r'^ath\d+$', # ath0, ath1, etc.
29+
r'^wi\d+$', # wi0, wi1, etc.
30+
r'^e1000g\d+$', # e1000g0, e1000g1, etc.
31+
r'^bge\d+$', # bge0, bge1, etc.
32+
r'^en\d+$', # en0, en1, etc. (macOS)
33+
r'^lo$', # loopback
34+
]
35+
36+
# Check if the interface name matches any of the valid patterns
37+
return any(re.match(pattern, interface) for pattern in valid_patterns)
1638

1739
def configure_logging(verbose):
1840
"""Configure logging based on verbosity."""
@@ -46,10 +68,21 @@ def interface_exists(interface, logger):
4668

4769
def generate_mac_address(logger):
4870
"""Generate a new MAC address with a local administered bit set."""
49-
mac = [random.randint(0x02, 0x02)] + [random.randint(0x00, 0xff) for _ in range(5)]
71+
# Choose an even prefix for the first byte (0x02, 0x04, 0x06, ..., 0xFE)
72+
first_byte = random.choice([x for x in range(0x00, 0xFF + 1) if x % 2 == 0])
73+
74+
# Generate the rest of the MAC address
75+
mac = [first_byte] + [random.randint(0x00, 0xff) for _ in range(5)]
76+
77+
# Format each byte as a two-digit hexadecimal number
5078
mac_hex = [f"{x:02x}" for x in mac]
79+
80+
# Join the bytes with ':' to form the MAC address string
5181
random_mac = ':'.join(mac_hex)
82+
83+
# Log the generated MAC address
5284
logger.debug(f"Generated MAC address: {random_mac}")
85+
5386
return random_mac
5487

5588
def is_valid_mac(mac_address, logger):

0 commit comments

Comments
 (0)