added context to threads

This commit is contained in:
anoduck 2024-01-25 07:40:09 -05:00
parent 82d00bb8d2
commit 32eca30e62

View file

@ -40,7 +40,7 @@ sys.path.append(os.path.expanduser('~/.cache/pypoetry/virtualenvs/crouching-tige
# _ _ _ ____ ___ _ ___ _ ___ ___
# \ ( ) / )_\ / _ \ )_ _( )_\ \ _) ) | ) __( ( _(
# )\_/( /( )\ ) ' / _| |_ /( )\ | ( | (__ | _) _) \
# \_/ )_/ \_(|_()_\ )_____()_/ \_(/__o) )____( )___( )____)
# \_/ )_/ \_(|_()_\ )_____()_/ \_(/__o) )____( )___( )____)
# ------------------------------------------------------------
config_file = os.path.abspath("/etc/ctiger/config.ini")
pc = Counter()
@ -174,7 +174,7 @@ class NetDev:
Possible values are "create" or "switch".
Returns:
str: The name of the created or switched monitor interface.
str: The name of the created or switched monitor interface.
"""
global macaddr
@ -221,6 +221,11 @@ class Purge(object):
def __getitem__(self, pkt):
return pkt
def chan_hop(self, mon_if, ichan) -> None:
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))
def channel_runner(self, mon_if, channels) -> None:
self.mon_if = mon_if
self.channels = channels
@ -234,10 +239,8 @@ class Purge(object):
print(f'name={thread.name}, daemon={thread.daemon}')
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)
with threading.Timer(14.7, chan_hop, args=(mon_if, ichan)) as timer:
timer.start()
def send_pkt(self, bssid) -> None:
self.bssid = bssid
@ -323,13 +326,13 @@ class Purge(object):
iface=mon_if, prn=self.cts_prn,
monitor=True)
cts_sniff.start()
channel_thread = threading.Thread(target=self.channel_runner,
args=(self.mon_if,
self.channels))
channel_thread.start()
log.info('Channel runner started.')
log.info('Probe sniffer started')
log.info('CTS sniffer started')
with threading.Thread(target=self.channel_runner,
args=(self.mon_if,
self.channels)) as channel_thread:
channel_thread.start()
log.info('Channel runner started.')
log.info('Probe sniffer started')
log.info('CTS sniffer started')
def start_purge(interface, mon_type, valid_file, channels) -> None:
@ -388,7 +391,7 @@ class attack:
log.debug('sending deauth to ', targ, ' with type 4')
sendp(pkt, iface=mon_dev, verbose=0)
pkt = RadioTap()/Dot11(type=0, subtype=12,
addr1="ff:ff:ff:ff:ff:ff", addr2=targ, addr3=targ)/Dot11Deauth()
addr1="ff:ff:ff:ff:ff:ff", addr2=targ, addr3=targ)/Dot11Deauth()
log.debug('sending deauth to ', targ, ' with type 12')
sendp(pkt, iface=mon_dev, verbose=0)
@ -431,19 +434,17 @@ class attack:
asniff.start()
log.info('Starting channel hopper')
while True:
ch_thread = threading.Thread(
target=self.chan_hopper,
args=(mon_dev, channels))
ch_thread.start()
if asniff.results is not None:
with asniff.results() as ares:
for row in ares:
if row[1] in targets:
log.info('Found target: ', row[1])
fg_thread = threading.Thread(
target=self.feed_gather,
args=(mon_dev, row))
fg_thread.start()
with threading.Thread(target=self.chan_hopper,
args=(mon_dev, channels)) as ch_thread:
ch_thread.start()
if asniff.results is not None:
with asniff.results() as ares:
for row in ares:
if row[1] in targets:
log.info('Found target: ', row[1])
with threading.Thread(target=self.feed_gather,
args=(mon_dev, row)) as fg_thread:
fg_thread.start()
def start_attack(mondev, scan_file, log):
@ -465,7 +466,7 @@ def proc_attack(interface, scan_file, mon_type):
mon_dev = start_monitor(interface, mon_type)
mp.set_start_method('spawn')
attack_daemon = mp.Process(target=start_attack, args=(mon_dev, scan_file),
name='attack_daemon', daemon=True)
name='attack_daemon', daemon=True)
daemon = False
if daemon:
log.info('Daemonizing & sending to background...')
@ -520,19 +521,19 @@ def get_log(log_file):
open(log, 'a').close()
if rot:
rotate_logfile(log)
log = logging.getLogger(__name__)
log = logging.getLogger(__name__)
if log.hasHandlers():
log.handlers.clear()
if lev == 'info':
log.setLevel(logging.INFO)
elif lev == 'debug':
log.setLevel(logging.DEBUG)
handler = logging.FileHandler(log, mode='a', encoding='utf-8')
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
log.info('started motion detection')
log.info('Acquired Logger')
handler = logging.FileHandler(log, mode='a', encoding='utf-8')
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
log.addHandler(handler)
log.info('started motion detection')
log.info('Acquired Logger')
return log
@ -622,13 +623,13 @@ spec = cfg.split("\n")
if not os.path.isfile(config_file):
if not os.path.exists(os.path.dirname(config_file)):
os.mkdir(os.path.dirname(config_file))
config = ConfigObj(config_file, configspec=spec)
config.filename = config_file
validator = validate.Validator()
config.validate(validator, copy=True)
config.write()
print("configuration file written to ", config_path)
sys.exit()
config = ConfigObj(config_file, configspec=spec)
config.filename = config_file
validator = validate.Validator()
config.validate(validator, copy=True)
config.write()
print("configuration file written to ", config_path)
sys.exit()
else:
config = ConfigObj(config_file, configspec=spec)
@ -687,7 +688,7 @@ else:
mac_parse = subparse.add_parser('mac', help='Grab Valid addresses')
mac_parse.add_argument('-t', '--type', dest='mon_type', choices=['create',
'switch'], default=config['MAC_PURGE']['if_type'],
'switch'], default=config['MAC_PURGE']['if_type'],
help='Create new monitor inf or switch mode.')
mac_parse.add_argument('-f', '--file', dest='valid_file',
default=config['MAC_PURGE']['valid_results'],