Esempio n. 1
0
    def on_internet_available(self, agent):
        """
        Called in manual mode when there's internet connectivity
        """

        if not self.ready or self.lock.locked():
            return

        with self.lock:
            display = agent.view()
            config = agent.config()
            reported = self.report.data_field_or('reported', default=list())
            handshake_dir = config['bettercap']['handshakes']
            handshake_filenames = os.listdir(handshake_dir)
            handshake_paths = [os.path.join(handshake_dir, filename) for filename in handshake_filenames if
                               filename.endswith('.pcap')]
            # pull out whitelisted APs
            handshake_paths = remove_whitelisted(handshake_paths, self.options['whitelist'])
            handshake_new = set(handshake_paths) - set(reported) - set(self.skip)
            if handshake_new:
                logging.info("[onlinehashcrack] Internet connectivity detected, uploading new handshakes to onlinehashcrack.com...")
                for idx, handshake in enumerate(handshake_new):
                    display.set('status',
                                f"Uploading handshake to onlinehashcrack.com ({idx + 1}/{len(handshake_new)})")
                    display.update(force=True)
                    try:
                        self._upload_to_ohc(handshake)
                        if handshake not in reported:
                            reported.append(handshake)
                            self.report.update(data={'reported': reported})
                            logging.debug(f"[onlinehashcrack] Successfully uploaded {handshake}.")
                    except requests.exceptions.RequestException as req_e:
                        self.skip.append(handshake)
                        logging.debug(f"[onlinehashcrack] {req_e}")
                        continue
                    except OSError as os_e:
                        self.skip.append(handshake)
                        logging.debug(f"[onlinehashcrack] {os_e}")
                        continue
            if 'dashboard' in self.options and self.options['dashboard']:
                cracked_file = os.path.join(handshake_dir, 'onlinehashcrack.cracked')
                if os.path.exists(cracked_file):
                    last_check = datetime.fromtimestamp(os.path.getmtime(cracked_file))
                    if last_check is not None and ((datetime.now() - last_check).seconds / (60 * 60)) < 1:
                        return
                try:
                    self._download_cracked(cracked_file)
                    logging.info("[onlinehashcrack] Downloaded cracked passwords.")
                except requests.exceptions.RequestException as req_e:
                    logging.debug(f"[onlinehashcrack] {req_e}")
                except OSError as os_e:
                    logging.debug(f"[onlinehashcrack] {os_e}")
                if 'single_files' in self.options and self.options['single_files']:
                    with open(cracked_file, 'r') as cracked_list:
                        for row in csv.DictReader(cracked_list):
                            if row['password']:
                                filename = re.sub(r'[^a-zA-Z0-9]', '', row['ESSID']) + '_' + row['BSSID'].replace(':', '')
                                if os.path.exists(os.path.join(handshake_dir, filename+'.pcap')):
                                    with open(os.path.join(handshake_dir, filename+'.pcap.cracked'), 'w') as f:
                                        f.write(row['password'])
Esempio n. 2
0
    def on_internet_available(self, agent):
        """
        Called in manual mode when there's internet connectivity
        """
        if not self.ready or self.lock.locked():
            return

        with self.lock:
            config = agent.config()
            display = agent.view()
            reported = self.report.data_field_or('reported', default=list())
            handshake_dir = config['bettercap']['handshakes']
            handshake_filenames = os.listdir(handshake_dir)
            handshake_paths = [os.path.join(handshake_dir, filename) for filename in handshake_filenames if
                               filename.endswith('.pcap')]
            handshake_paths = remove_whitelisted(handshake_paths, self.options['whitelist'])
            handshake_new = set(handshake_paths) - set(reported) - set(self.skip)

            if handshake_new:
                logging.info("WPA_SEC: Internet connectivity detected. Uploading new handshakes to wpa-sec.stanev.org")
                for idx, handshake in enumerate(handshake_new):
                    display.set('status', f"Uploading handshake to wpa-sec.stanev.org ({idx + 1}/{len(handshake_new)})")
                    display.update(force=True)
                    try:
                        self._upload_to_wpasec(handshake)
                        reported.append(handshake)
                        self.report.update(data={'reported': reported})
                        logging.info("WPA_SEC: Successfully uploaded %s", handshake)
                    except requests.exceptions.RequestException as req_e:
                        self.skip.append(handshake)
                        logging.error("WPA_SEC: %s", req_e)
                        continue
                    except OSError as os_e:
                        logging.error("WPA_SEC: %s", os_e)
                        continue

            if 'download_results' in self.options and self.options['download_results']:
                cracked_file = os.path.join(handshake_dir, 'wpa-sec.cracked.potfile')
                if os.path.exists(cracked_file):
                    last_check = datetime.fromtimestamp(os.path.getmtime(cracked_file))
                    if last_check is not None and ((datetime.now() - last_check).seconds / (60 * 60)) < 1:
                        return
                try:
                    self._download_from_wpasec(os.path.join(handshake_dir, 'wpa-sec.cracked.potfile'))
                    logging.info("WPA_SEC: Downloaded cracked passwords.")
                except requests.exceptions.RequestException as req_e:
                    logging.debug("WPA_SEC: %s", req_e)
                except OSError as os_e:
                    logging.debug("WPA_SEC: %s", os_e)
Esempio n. 3
0
    def on_internet_available(self, agent):
        """
        Called in manual mode when there's internet connectivity
        """
        if not self.ready or self.lock.locked():
            return

        from scapy.all import Scapy_Exception

        config = agent.config()
        display = agent.view()
        reported = self.report.data_field_or('reported', default=list())
        handshake_dir = config['bettercap']['handshakes']
        all_files = os.listdir(handshake_dir)
        all_gps_files = [
            os.path.join(handshake_dir, filename) for filename in all_files
            if filename.endswith('.gps.json')
        ]

        all_gps_files = remove_whitelisted(all_gps_files,
                                           self.options['whitelist'])
        new_gps_files = set(all_gps_files) - set(reported) - set(self.skip)
        if new_gps_files:
            logging.info(
                "[wigle] Internet connectivity detected, Uploading new handshakes to wigle.net..."
            )
            csv_entries = list()
            no_err_entries = list()
            for gps_file in new_gps_files:
                pcap_filename = gps_file.replace('.gps.json', '.pcap')
                if not os.path.exists(pcap_filename):
                    logging.debug(f"[wigle] Can't find pcap for {gps_file}.")
                    self.skip.append(gps_file)
                    continue
                try:
                    gps_data = _extract_gps_data(gps_file)
                except OSError as os_err:
                    logging.debug(f"[wigle] {os_err}")
                    self.skip.append(gps_file)
                    continue
                except json.JSONDecodeError as json_err:
                    logging.debug(f"[wigle]: {json_err}")
                    self.skip.append(gps_file)
                    continue
                if gps_data['Latitude'] == 0 and gps_data['Longitude'] == 0:
                    logging.debug(
                        f"[wigle] Not enough gps-information for {gps_file}. Trying again next time."
                    )
                    self.skip.append(gps_file)
                    continue
                try:
                    pcap_data = extract_from_pcap(pcap_filename, [
                        WifiInfo.BSSID, WifiInfo.ESSID, WifiInfo.ENCRYPTION,
                        WifiInfo.CHANNEL, WifiInfo.RSSI
                    ])
                except FieldNotFoundError:
                    logging.debug(
                        f"[wigle] Could not extract all information. Skip {gps_file}."
                    )
                    self.skip.append(gps_file)
                    continue
                except Scapy_Exception as sc_e:
                    logging.debug(f"[wigle]: {sc_e}")
                    self.skip.append(gps_file)
                    continue
                new_entry = _transform_wigle_entry(gps_data, pcap_data)
                csv_entries.append(new_entry)
                no_err_entries.append(gps_file)
            if csv_entries:
                display.set('status', "Uploading gps-data to wigle.net...")
                display.update(force=True)
                try:
                    _send_to_wigle(csv_entries, self.options['api_key'])
                    reported += no_err_entries
                    self.report.update(data={'reported': reported})
                    logging.info(
                        f"[wigle] Successfully uploaded {len(no_err_entries)} files."
                    )
                except requests.exceptions.RequestException as re_e:
                    self.skip += no_err_entries
                    logging.debug(
                        f"[wigle] Got an exception while uploading {re_e}")
                except OSError as os_e:
                    self.skip += no_err_entries
                    logging.debug(f"[wigle] Got the following error: {os_e}")