perf: 🎨 Minor Performance improvements, code cleanup, no more double entries

Minor tweaks in performance, added reading of old discoveries back to sniffer, code cleanup, and diagram work.
This commit is contained in:
anoduck 2024-02-10 18:18:43 -05:00
parent ca561ccea1
commit f77911440c
2 changed files with 38 additions and 8 deletions

View file

@ -10,6 +10,9 @@
# ---------------------------------------
* Changelog
** Unreleased
*** 2024.02.10
- Revising Diagram of processes
- adding function to load data from csv
*** 2024.01.27
- Garbage collection for class definitions
- massive refactoring of how variables are passed.

View file

@ -76,6 +76,7 @@ log_file = string(default='/var/log/ctiger.log')
[ATTACK]
scan_file = string(default='ct_aps.csv')
mon_type = option('create', 'switch', default='switch')
network_file = string(default='local_networks.csv')
use_daemon = boolean(default=False)
# -----------------------------------------------------------
@ -246,7 +247,6 @@ class Purge(object):
self.log.debug(
'Sending RTS frame to {0} with type 1 and subtype 11'.format(bssid))
sendp(new_pkt, verbose=0)
return
def get_interface(self) -> tuple:
ndev = NetDev()
@ -278,14 +278,14 @@ class Purge(object):
dbm_signal = pkt.dBm_AntSignal
pkt_chan = self.extract_channel(pkt[Dot11])
self.log.debug('Extracted channel: {0}'.format(pkt_chan))
pkg_df = pd.read_csv(self.valid_file, index_col=0)
if bssid in pkg_df.index:
if bssid in self.devices:
self.log.info('Duplicate CTS from {0}'.format(bssid))
return
self.scan_df.loc[bssid] = [self.macaddr, dbm_signal,
pkt_chan, 'N/A']
self.scan_df.to_csv(self.valid_file, mode='a', index=False)
self.log.info('Results written to {0}'.format(valid_file))
else:
self.devices.append(bssid)
self.scan_df.loc[bssid] = [self.macaddr, dbm_signal, pkt_chan, 'N/A']
self.scan_df.to_csv(self.valid_file, mode='a', index=False)
self.log.info('Results written to {0}'.format(valid_file))
def probe_prn(self, pkt):
bssid = pkt[Dot11FCS].addr2
@ -293,7 +293,6 @@ class Purge(object):
self.log.debug('Extracted bssid: {0}'.format(bssid))
self.log.info('Sending RTS frame to {0}'.format(bssid))
self.send_pkt(bssid)
return
def mac_revealer(self, interface, mon_type, valid_file, channels, log):
self.interface = interface
@ -304,6 +303,12 @@ class Purge(object):
log.info('mac revealer started')
log.info('setting up class attributes')
self.scan_df = get_df()
devices = load_df(valid_file, log)
if devices:
self.devices = devices
else:
log.info('No valid targets found')
self.devices = []
log.info('acquired Dataframe')
mon_if, macaddr = self.get_interface()
self.mon_if = mon_if
@ -475,6 +480,25 @@ def proc_attack(interface, scan_file, mon_type, log):
start_attack(mon_dev, scan_file, log)
# -------------------------------------------------------------
# ██╗ ██████╗ █████╗ ██████╗ ██████╗ ███████╗
# ██║ ██╔═══██╗██╔══██╗██╔══██╗ ██╔══██╗██╔════╝
# ██║ ██║ ██║███████║██║ ██║ ██║ ██║█████╗
# ██║ ██║ ██║██╔══██║██║ ██║ ██║ ██║██╔══╝
# ███████╗╚██████╔╝██║ ██║██████╔╝ ██████╔╝██║
# ╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═╝
# -------------------------------------------------------------
def load_df(valid_file, log):
if os.path.exists(valid_file):
log.info('Loading valid targets from: ', valid_file)
targets = pd.read_csv(valid_file, index_col=0)
devices = targets.bssid.to_list()
return devices
else:
log.info('No valid targets found')
return None
# -------------------------------------------------------------
# ██████╗ ███████╗████████╗ ██████╗ ███████╗
# ██╔════╝ ██╔════╝╚══██╔══╝ ██╔══██╗██╔════╝
@ -684,6 +708,9 @@ else:
dest='mon_type',
default=config['ATTACK']['mon_type'],
help='Create new monitor inf or switch mode.')
att_parse.add_argument('-n', '--netfile', dest='network_file',
default=config['ATTACK']['network_file'],
help='Network file to use.')
# att_parse.add_argument('-d', '--use_daemon', action='store_true',
# dest='use_daemon', required=False,
# help='Run in daemon mode.')