From 37b25a142f921333f126ee51cbc6f8864f09c95b Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Sun, 19 Jan 2020 11:51:11 +0100 Subject: [PATCH] add password download --- pwnagotchi/defaults.toml | 1 + pwnagotchi/plugins/default/onlinehashcrack.py | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/pwnagotchi/defaults.toml b/pwnagotchi/defaults.toml index 45cff59..1afcae8 100644 --- a/pwnagotchi/defaults.toml +++ b/pwnagotchi/defaults.toml @@ -36,6 +36,7 @@ main.plugins.webgpsmap.enabled = false main.plugins.onlinehashcrack.enabled = false main.plugins.onlinehashcrack.email = "" +main.plugins.onlinehashcrack.dashboard = "" main.plugins.wpa-sec.enabled = false main.plugins.wpa-sec.api_key = "" diff --git a/pwnagotchi/plugins/default/onlinehashcrack.py b/pwnagotchi/plugins/default/onlinehashcrack.py index 534ddc4..18d5f6b 100644 --- a/pwnagotchi/plugins/default/onlinehashcrack.py +++ b/pwnagotchi/plugins/default/onlinehashcrack.py @@ -2,6 +2,7 @@ import os import logging import re import requests +from datetime import datetime from threading import Lock from pwnagotchi.utils import StatusFile import pwnagotchi.plugins as plugins @@ -71,6 +72,24 @@ class OnlineHashCrack(plugins.Plugin): logging.error(f"OHC: Got an exception while uploading {path} -> {e}") raise e + def _download_cracked(self, save_file, timeout=120): + """ + Downloads the cracked passwords and saves them + + returns the number of downloaded passwords + """ + try: + s = requests.Session() + dashboard = s.get(self.options['dashboard'], timeout=timeout) + result = s.get('https://www.onlinehashcrack.com/wpa-exportcsv', timeout=timeout) + result.raise_for_status() + with open(save_file, 'wt') as output_file: + output_file.write(result.content) + except requests.exceptions.RequestException as req_e: + raise req_e + except OSError as os_e: + raise os_e + def on_internet_available(self, agent): """ Called in manual mode when there's internet connectivity @@ -112,3 +131,19 @@ class OnlineHashCrack(plugins.Plugin): self.skip.append(handshake) logging.error("OHC: %s", 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("OHC: Downloaded cracked passwords.") + except requests.exceptions.RequestException as req_e: + logging.debug("OHC: %s", req_e) + except OSError as os_e: + logging.debug("OHC: %s", os_e) +