Whew, what a bitch...milestone done

This commit is contained in:
anoduck 2023-10-22 01:46:26 -04:00
parent 4abfa99f06
commit def5522dbb

108
ctiger.py
View file

@ -207,31 +207,23 @@ def PRN2(pkt):
def strainer(pkt) -> None:
if pkt[Dot11].type == 0 and pkt[Dot11].subtype == 4:
bssid = pkt[Dot11FCS].addr2
log.info('BSSID for strainer: ' + str(bssid))
# iface = get_working_if()
macaddr = Card.mac_addr
log.debug('Local Macaddr is: ', macaddr)
log.info('BSSID for strainer: {0}'.format(bssid))
log.debug('Local Macaddr is: {0}'.format(macaddr))
new_pkt = RadioTap()/Dot11(proto=0, type=1, subtype=11,
addr1=bssid,
addr2=macaddr,
ID=65535)
log.debug('Sending RTS frame to ' + str(bssid) + ' with type 11')
res = sr1(new_pkt, timeout=2, verbose=0, retry=0)
addr1=bssid,
addr2=macaddr,
ID=65535)
log.debug('Sending RTS frame to {0} with type 11'.format(bssid))
res = sr1(new_pkt, timeout=3, verbose=0, retry=0)
if res:
if res[Dot11].type == 1 and res[Dot11].subtype == 12:
log.debug('Recieved CTS packet.')
log.info('Intercepted CTS from: ' + bssid)
log.info('Intercepted CTS from: {0}'.format(bssid))
dbm_signal = pkt.dBm_AntSignal
channel = extract_channel(res[Dot11])
scan_df.loc[bssid] = ['N/A', dbm_signal, channel, 'N/A']
@dataclass
class Card:
interface: str
mac_addr: str
# -------------------------------------------------------------------
# ███╗ ██╗███████╗████████╗██████╗ ███████╗██╗ ██╗
# ████╗ ██║██╔════╝╚══██╔══╝██╔══██╗██╔════╝██║ ██║
@ -272,8 +264,8 @@ class NetDev:
os.system(f'ip link set {self.interface} address {self.macaddr}')
log.debug('Set device address to {0}'.format(self.macaddr))
# (below) setting registry is known to cause issues.
os.system('iw set reg US')
log.debug('Set device registry to US')
# os.system('iw set reg US')
# log.debug('Set device registry to US')
os.system(f'iw dev {self.interface} set type monitor')
log.debug('{0} switched to monitor'.format(self.interface))
os.system(f'ip link set {self.interface} up')
@ -299,6 +291,7 @@ class NetDev:
str: The name of the created or switched monitor interface.
"""
global macaddr
macaddr = fake.mac_address()
self.macaddr = macaddr
log.debug('mac_address: {0}'.format(self.macaddr))
@ -311,35 +304,16 @@ class NetDev:
if self.mon_type == 'create':
self.create_if()
mon_if = self.mon_crtd
Card(interface=mon_if, mac_addr=self.macaddr)
return mon_if
elif self.mon_type == 'switch':
self.switch_if(self.interface, self.macaddr)
mon_if = self.interface
Card(interface=mon_if, mac_addr=self.macaddr)
return mon_if
else:
Exception('Invalid monitor type')
log.debug('Invalid monitor type')
sys.exit(1)
def channel_runner(self, mon_if, channels) -> None:
self.mon_if = mon_if
self.channels = channels
log.info('Channel Runner NG started.')
log.info('Preliminary channel list: {0}'.format(self.channels))
chanlist = self.channels.split(',')
chlist = list(set(chanlist))
log.info('Channel list: {0}'.format(chlist))
chans = [int(chan) for chan in chlist]
thread = threading.current_thread()
print(f'name={thread.name}, daemon={thread.daemon}')
while True:
ichan = choice(chans)
os.system(f'iw dev {self.mon_if} set channel {str(ichan)}')
# log.debug('Channel set to ', str(ichan))
sleep(14.7)
def signal_handler(signal, frame) -> None:
print('You pressed Ctrl+C!')
@ -365,59 +339,63 @@ class Purge(object):
self.valid_file = kwargs.get('valid_file')
self.channels = kwargs.get('channels')
def start_purge(self) -> None:
asyncio.run(self.mac_purge(self.interface,
self.mon_type,
self.valid_file,
self.channels))
# def get_file(self):
# return self.valid_file
# def get_df(self):
# return self.scan_df
# def get_channels(self):
# return self.channels
# def get_type(self):
# log.debug('Monitor Type: {0}'.format(self.mon_type))
# return self.mon_type
# def get_name(self):
# return self.interface
def channel_runner(self, mon_if, channels) -> None:
self.mon_if = mon_if
self.channels = channels
log.info('Channel Runner NG started.')
log.info('Preliminary channel list: {0}'.format(self.channels))
chanlist = self.channels.split(',')
chlist = list(set(chanlist))
chans = [int(chan) for chan in chlist]
log.info('Channel list: {0}'.format(chlist))
thread = threading.current_thread()
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)
async def mac_purge(self, interface, mon_type, valid_file, channels):
global scan_df
scan_df = get_df()
signal.signal(signal.SIGINT, signal_handler)
print('Enter Ctrl+C TWICE to fully stop the script.')
self.interface = interface
self.mon_type = mon_type
self.valid_file = valid_file
self.channels = channels
signal.signal(signal.SIGINT, signal_handler)
print('Enter Ctrl+C TWICE to fully stop the script.')
ndev = NetDev(interface=self.interface, mon_type=self.mon_type)
mon_if = ndev.start_monitor(interface=self.interface,
mon_type=self.mon_type)
log.info('interface {0} is up and running.'.format(mon_if))
self.mon_if = mon_if
log.info('interface {0} is up and running.'.format(self.mon_if))
# vfile = self.get_file()
# log.info('We will be writing captured macs to ', str(self.valid_file))
chop = asyncio.to_thread(ndev.channel_runner(mon_if, self.channels)) # type: ignore
chop = asyncio.to_thread(self.channel_runner,
self.mon_if, self.channels)
chopper = asyncio.create_task(chop)
log.info('Channel runner started.')
# await asyncio.sleep(0)
await asyncio.sleep(0)
while True:
log.info('starting sniffer')
asniff = AsyncSniffer(iface=mon_if,
prn=strainer,
store=False, monitor=True)
asniff.start()
if asniff.running:
log.info('asniffer started')
log.info('asniffer started')
forever_wait = threading.Event()
forever_wait.wait()
def start_purge(self) -> None:
asyncio.run(self.mac_purge(self.interface,
self.mon_type,
self.valid_file,
self.channels))
# -----------------------------------------------------------------------------
# ███████╗███╗ ██╗██╗███████╗███████╗ ███████╗████████╗ ██████╗ ██████╗
# ██╔════╝████╗ ██║██║██╔════╝██╔════╝ ██╔════╝╚══██╔══╝██╔═══██╗██╔══██╗