fixed mon_dev startup for attack module

This commit is contained in:
anoduck 2024-01-26 15:18:03 -05:00
parent 9d710fa5cb
commit e6255b5636

View file

@ -120,7 +120,7 @@ class NetDev:
self.interface = interface
self.mon_type = mon_type
def create_if(self, interface, mon_crtd, macaddr) -> bool:
def create_if(self, mon_crtd, macaddr) -> bool:
try:
os.system(f'ip link set {self.interface} up')
os.system(
@ -139,8 +139,7 @@ class NetDev:
log.debug('Failed to create {0}'.format(self.interface), e)
sys.exit(1)
def switch_if(self, interface, macaddress) -> bool:
self.interface = interface
def switch_if(self, macaddress) -> bool:
self.macaddr = macaddress
try:
os.system(f'ip link set {self.interface} down')
@ -163,13 +162,15 @@ class NetDev:
print('Failed to change ', self.interface, ' mode', e)
sys.exit(1)
def start_monitor(self, interface, mon_type) -> str:
def start_monitor(self) -> str:
"""
Starts a monitor self.name based on the given arguments.
Args:
interface (str): The name of the interface to create the monitor interface from.
mon_type (str): The type of monitor interface to create or switch to.
interface (str): The name of the interface
to create the monitor interface from.
mon_type (str): The type of monitor interface
to create or switch to.
Possible values are "create" or "switch".
Returns:
@ -182,8 +183,6 @@ class NetDev:
log.debug('mac_address: {0}'.format(self.macaddr))
log.debug('Monitor Type: {0}'.format(self.mon_type))
log.info('Starting monitor interface')
self.interface = interface
self.mon_type = mon_type
mon_crtd = self.interface + 'mon'
self.mon_crtd = mon_crtd
if self.mon_type == 'create':
@ -223,12 +222,14 @@ class Purge(object):
def do_hop(self, mon_if, chans, log) -> None:
thread = threading.current_thread()
log.debug(f'Do Hop: name={thread.name}, daemon={thread.daemon}')
ichan = choice(chans)
log.debug('Hopping on: {0}'.format(ichan))
os.system(f'iw dev {self.mon_if} set channel {str(ichan)}')
log.debug('Channel set to {0}'.format(ichan))
while True:
ichan = choice(chans)
log.debug('Hopping on: {0}'.format(ichan))
os.system(f'iw dev {self.mon_if} set channel {str(ichan)}')
log.debug('Channel set to {0}'.format(ichan))
sleep(14.7)
def channel_runner(self, lock, log) -> None:
def channel_runner(self, log) -> None:
mon_if = self.mon_if
log.info('Channel Runner NG started.')
log.info('Preliminary channel list: {0}'.format(self.channels))
@ -239,11 +240,10 @@ class Purge(object):
thread = threading.current_thread()
log.debug(
f'Channel Runner: name={thread.name}, daemon={thread.daemon}')
timer = threading.Timer(14.7, self.do_hop,
chop = threading.Thread(target=self.do_hop,
name='chop',
args=(mon_if, chans, log))
while True:
with lock:
timer.start()
chop.start()
def send_pkt(self, bssid) -> None:
self.bssid = bssid
@ -330,8 +330,7 @@ class Purge(object):
iface=mon_if, prn=self.cts_prn,
monitor=True)
cts_sniff.start()
lock = threading.Lock()
self.channel_runner(lock, log)
self.channel_runner(log)
log.info('Channel runner started.')
log.info('Probe sniffer started')
log.info('CTS sniffer started')
@ -472,7 +471,8 @@ def start_attack(mondev, scan_file, log):
# ----------------------------------------------------------------------------
# This shit does not work.
def proc_attack(interface, scan_file, mon_type):
mon_dev = start_monitor(interface, mon_type)
ndev = NetDev(interface, mon_type)
mon_dev = ndev.start_monitor()
mp.set_start_method('spawn')
attack_daemon = mp.Process(target=start_attack, args=(mon_dev, scan_file),
name='attack_daemon', daemon=True)
@ -483,7 +483,7 @@ def proc_attack(interface, scan_file, mon_type):
attack_daemon.join()
else:
log.info('Running in foreground...')
trio.run(attack, mon_dev, scan_file)
start_attack(mon_dev, scan_file)
# -------------------------------------------------------------