def stop(self, event, frame): self.exit = True if not self.monitor_on: self.remove_mon_iface(self.mon_iface) os.system('service network-manager restart') print("") print_err('Closing')
def channel_hop(self, mon_iface, args): channel_num = 0 max_channel = 11 if args["america"] else 13 err = None while True: if args['channel']: with self.lock: self.monchannel = args['channel'] else: channel_num += 1 if channel_num > max_channel: channel_num = 1 with self.lock: self.monchannel = str(channel_num) try: proc = Popen([ 'iw', 'dev', mon_iface, 'set', 'channel', self.monchannel ], stdout=self.DN, stderr=PIPE) for line in proc.communicate()[1].decode().split('\n'): if len( line ) > 2: # iw dev shouldnt display output unless there's an error err = f'Channel hopping failed: {line}' if self.exit: return self.output(err, self.monchannel) time.sleep(1) except OSError: print_err('Could not execute "iw"') self.exit = True return
def get_iface(self, interfaces): scanned_aps = [] if len(interfaces) < 1: print_err( 'No wireless interfaces found, bring one up and try again') self.exit = True return None if len(interfaces) == 1: for interface in interfaces: return interface # Find most powerful interface for iface in interfaces: count = 0 proc = Popen(['iwlist', iface, 'scan'], stdout=PIPE, stderr=self.DN) for line in proc.communicate()[0].decode().split('\n'): if ' - Address:' in line: # first line in iwlist scan for a new AP count += 1 scanned_aps.append((count, iface)) print_ok(f'Networks discovered by {iface}: {count}') try: interface = max(scanned_aps)[1] return interface except Exception as e: print_err(f'Minor error: {e}') iface = interfaces[0] print_i(f' Starting monitor mode on {iface}') return iface
def start_mon_mode(self, interface): print_ok(f'Starting monitor mode off {interface}') try: os.system('ifconfig %s down' % interface) os.system('iwconfig %s mode monitor' % interface) os.system('ifconfig %s up' % interface) return interface except Exception: print_err('Could not start monitor mode') self.exit = True
def check_monitor(self, iface): try: proc = Popen(['iwconfig', iface], stdout=PIPE, stderr=PIPE) data = proc.communicate() if "Mode:Monitor" in data[0].decode(): return True elif "No such device" in data[1].decode(): print_err("Interface not found") return False print_i("Interface is not in mode monitor") self.start_mon_mode(iface) return True except OSError: print_err('Could not execute "iwconfig"') return False
def iwconfig(self): monitors = [] interfaces = {} try: proc = Popen(['iwconfig'], stdout=PIPE, stderr=self.DN) except OSError: print_err('Could not execute "iwconfig"') self.exit = True return for line in proc.communicate()[0].decode().split('\n'): if len(line) == 0: continue # Isn't an empty string if line[0] != ' ': # Doesn't start with space wired_search = re.search('eth[0-9]|em[0-9]|p[1-9]p[1-9]', line) if not wired_search: # Isn't wired iface = line[:line.find(' ')] # is the interface if 'Mode:Monitor' in line: monitors.append(iface) elif 'IEEE 802.11' in line: if "ESSID:\"" in line: interfaces[iface] = 1 else: interfaces[iface] = 0 return monitors, interfaces
def output(self, err, monchannel): os.system('clear') if err: print_err(err) else: print_ok(f'{self.mon_iface} channel: {monchannel}\n') if len(self.clients_aps) > 0 and self.show_stations: print( ' ch Client BSSID (ESSID)') # Print the clients list with self.lock: for ca in self.clients_aps: print_i( f"[*] {ca['channel'].ljust(2)} - {ca['client']} ({ca['vendor']}) - {ca['bssid_ap']} ({ca['essid_ap']})" ) if len(self.aps) > 0 and self.show_aps: print('\n Access Points Enc ch ESSID') with self.lock: for ap in self.aps: print( f'[*] {ap["bssid"]} - {ap["encrypted"]} - {ap["ap_channel"].ljust(2)} - {ap["ssid"]}' ) print('')
prn=self.cb, stop_filter=self.exit_or_not) def exit_or_not(self, pkt): if self.exit: return True return False ######################################## # Test ######################################## if __name__ == "__main__": if os.geteuid(): print_err("Please run as root") else: parser = argparse.ArgumentParser() parser.add_argument("-i", "--iface", help="Specify interface") parser.add_argument("-c", "--channel", help="If you want to fix a channel") parser.add_argument( "-a", "--america", help="Set this flag if you are in America (11 channels)", action='store_true') parser.add_argument("-ap", "--aps", help="Set this flag if you don't want check aps", action='store_true')