def test_file_setup(self): now = datetime.now() file_prefix = str(now.year) + str(now.month) + str(now.day) filename = file_prefix + "_beacon.csv" log = logger.CherryLogger() log.file_setup(file_prefix) if os.path.isdir(os.path.join(os.getcwd(), "logs")) and os.path.isfile(os.path.join(os.getcwd(), "logs", filename)): expected = True else: expected = False self.assertTrue(expected, msg="Log file setup failed.")
def test_write_to_file(self): now = datetime.now() file_prefix = str(now.year) + str(now.month) + str(now.day) filename = file_prefix + "_beacon.csv" log_file = os.path.join(os.getcwd(), "logs", filename) bssid = "de:ad:be:ef:01:23" essid = "FBI_van_1" now = datetime.now() file_prefix = str(now.year) + str(now.month) + str(now.day) log = logger.CherryLogger() log.file_name_prefix = file_prefix log.write_to_file("beacon", bssid, essid) with open(log_file) as open_file: if essid in open_file.read(): expected = True else: expected = False self.assertTrue(expected, msg="Log file write new entry failed.")
def main(): parser = argparse.ArgumentParser( description='Scan for 802.11 Beacon and/or Probe Requests.') parser.add_argument('-m', '--mode', help='0=beacons, 1=probe requests, 2=both') parser.add_argument('-i', '--interface', help='specify interface(s) to listen on') parser.add_argument('-b', '--band', help='specify the band to scan, 2.4 or 5.0') parser.add_argument( '-B', '--bssid', help='specify bssid to filter <mode 0 only> <optional>') parser.add_argument('-o', '--output', help='specify a file prefix for saved files.') parser.add_argument( '-c', '--channel-hop', action='store_ture', help= 'add this optiont to force channel hopping for the selected band/mode.' ) args = parser.parse_args() valid_modes = ["0", "1", "2"] if args.mode is not None and args.mode in valid_modes: scan_type = args.mode cherry_wasp = CoreScanner(scan_type) if args.output is not None: file_prefix = args.output else: now = datetime.datetime.now() file_prefix = str(now.year) + str(now.month) + str(now.day) cherry_wasp.file_prefix = file_prefix log = logger.CherryLogger() log.file_setup(cherry_wasp.file_prefix) else: print("[!] Error, starting the listener!") print(parser.usage) exit(-1) if args.interface is not None: conf.iface = args.interface else: print("[!] Error, no interface defined!") print(parser.usage) exit(-1) create_mon_interface = False if create_mon_interface: cherry_wasp.create_mon_interface(conf.iface) valid_bands = ["2.4", "5.0"] if args.band is None: print("[*] No band defined, defaulting to 2.4GHz.") band = "2.4" elif args.band in valid_bands: band = str(args.band) print("[*] Scanning on {0}GHz band".format(band)) else: print("[!] Error, invalid band selected!") print(parser.usage) exit(-1) if args.bssid is None: if args.channel_hop: channel_hopper = Thread(target=cherry_wasp.channel_hop, args=[band, args.interface]) channel_hopper.daemon = True channel_hopper.start() sniff(prn=cherry_wasp.scan_packet, store=0) else: # TODO: add BSSID input validation here if args.mode == "0": if args.bssid is not None: filter_bssid = str("ether src " + args.bssid) sniff(filter=filter_bssid, prn=cherry_wasp.scan_packet, store=0) else: sniff(prn=cherry_wasp.scan_packet, store=0) if args.channel_hop: channel_hopper = Thread(target=cherry_wasp.channel_hop, args=[band, args.interface]) channel_hopper.daemon = True channel_hopper.start() else: print( "[!] Invalid mode selected. No mode selected or must use mode 0 when filtering by BSSID" ) print(parser.usage) exit(-1)
def __init__(self, bssid, file_prefix): self.type = "access_point" self.bssid = bssid self.beaconed_essid = set() self.log = logger.CherryLogger() self.log.file_name_prefix = file_prefix
def __init__(self, bssid, file_prefix): self.type = "client" self.bssid = bssid self.requested_essid = set() self.log = logger.CherryLogger() self.log.file_name_prefix = file_prefix