From 4d024afded8277aa162e22ebb8d00426125eaa0a Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Wed, 18 Dec 2024 20:16:21 +0100 Subject: [PATCH] Small update to the build Signed-off-by: Jeroen Oudshoorn --- pwnagotchi/plugins/default/example.py | 13 +++---- pwnagotchi/plugins/default/wpa-sec.py | 51 +++++++++++++++++++-------- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/pwnagotchi/plugins/default/example.py b/pwnagotchi/plugins/default/example.py index 17f982e5..9fa650a8 100644 --- a/pwnagotchi/plugins/default/example.py +++ b/pwnagotchi/plugins/default/example.py @@ -14,6 +14,7 @@ class Example(plugins.Plugin): def __init__(self): logging.debug("example plugin created") + self.options = dict() # called when http://:/plugins// is called # must return a html page @@ -23,17 +24,17 @@ class Example(plugins.Plugin): # called when the plugin is loaded def on_loaded(self): - logging.warning("WARNING: this plugin should be disabled! options = " % self.options) + logging.warning("WARNING: this plugin should be disabled! options = %s" % self.options) # called before the plugin is unloaded def on_unload(self, ui): pass - # called hen there's internet connectivity + # called when there's internet connectivity def on_internet_available(self, agent): pass - # called to setup the ui elements + # called to set up the ui elements def on_ui_setup(self, ui): # add custom UI elements ui.add_element('ups', LabeledValue(color=BLACK, label='UPS', value='0%/0V', position=(ui.width() / 2 - 25, 0), @@ -58,7 +59,7 @@ class Example(plugins.Plugin): # or set a custom state # agent.set_bored() - # called when a non overlapping wifi channel is found to be free + # called when a non overlapping Wi-Fi channel is found to be free def on_free_channel(self, agent, channel): pass @@ -103,7 +104,7 @@ class Example(plugins.Plugin): def on_association(self, agent, access_point): pass - # called when the agent is deauthenticating a client station from an AP + # called when the agent is de-authenticating a client station from an AP def on_deauthentication(self, agent, access_point, client_station): pass @@ -112,7 +113,7 @@ class Example(plugins.Plugin): pass # called when a new handshake is captured, access_point and client_station are json objects - # if the agent could match the BSSIDs to the current list, otherwise they are just the strings of the BSSIDs + # if the agent could match the BSSID's to the current list, otherwise they are just the strings of the BSSIDs def on_handshake(self, agent, filename, access_point, client_station): pass diff --git a/pwnagotchi/plugins/default/wpa-sec.py b/pwnagotchi/plugins/default/wpa-sec.py index 8c75fe9f..1bba0e01 100644 --- a/pwnagotchi/plugins/default/wpa-sec.py +++ b/pwnagotchi/plugins/default/wpa-sec.py @@ -1,6 +1,7 @@ import os import logging import requests +import subprocess from datetime import datetime from threading import Lock from pwnagotchi.utils import StatusFile, remove_whitelisted @@ -22,10 +23,10 @@ class WpaSec(plugins.Plugin): self.ready = False self.lock = Lock() try: - self.report = StatusFile('/root/.wpa_sec_uploads', data_format='json') + self.report = StatusFile('/home/pi/.wpa_sec_uploads', data_format='json') except JSONDecodeError: - os.remove("/root/.wpa_sec_uploads") - self.report = StatusFile('/root/.wpa_sec_uploads', data_format='json') + os.remove("/home/pi/.wpa_sec_uploads") + self.report = StatusFile('/home/pi/.wpa_sec_uploads', data_format='json') self.options = dict() self.skip = list() @@ -42,14 +43,20 @@ class WpaSec(plugins.Plugin): cookies=cookie, files=payload, timeout=timeout) - if ' already submitted' in result.text: - logging.debug("%s was already submitted.", path) + if result.status_code == 200: + if 'already submitted' in result.text: + logging.debug("%s was already submitted.", path) + return False + return True + elif result.status_code != 200: + logging.error("WPA_SEC: Error code: %s", result.text) + return False except requests.exceptions.RequestException as req_e: raise req_e def _download_from_wpasec(self, output, timeout=30): """ - Downloads the results from wpasec and safes them to output + Downloads the results from wpasec and saves them to output Output-Format: bssid, station_mac, ssid, password """ @@ -110,12 +117,11 @@ class WpaSec(plugins.Plugin): logging.info("WPA_SEC: Internet connectivity detected. Uploading new handshakes to wpa-sec.stanev.org") for idx, handshake in enumerate(handshake_new): display.on_uploading(f"wpa-sec.stanev.org ({idx + 1}/{len(handshake_new)})") - try: - self._upload_to_wpasec(handshake) - reported.append(handshake) - self.report.update(data={'reported': reported}) - logging.debug("WPA_SEC: Successfully uploaded %s", handshake) + if self._upload_to_wpasec(handshake): + reported.append(handshake) + self.report.update(data={'reported': reported}) + logging.debug("WPA_SEC: Successfully uploaded %s", handshake) except requests.exceptions.RequestException as req_e: self.skip.append(handshake) logging.debug("WPA_SEC: %s", req_e) @@ -123,7 +129,6 @@ class WpaSec(plugins.Plugin): except OSError as os_e: logging.debug("WPA_SEC: %s", os_e) continue - display.on_normal() if 'download_results' in self.options and self.options['download_results']: @@ -156,6 +161,22 @@ class WpaSec(plugins.Plugin): def on_ui_update(self, ui): if 'show_pwd' in self.options and self.options['show_pwd'] and 'download_results' in self.options and self.options['download_results']: - last_line = os.popen('awk -F: \'!seen[$3]++ {print $3 " - " $4}\' /root/handshakes/wpa-sec.cracked.potfile | tail -n 1') - last_line = last_line.read().rstrip() - ui.set('pass', last_line) \ No newline at end of file + file_path = '/home/pi/handshakes/wpa-sec.cracked.potfile' + try: + with open(file_path, 'r') as file: + # Read all lines and extract the required fields + lines = file.readlines() + if lines: # Check if file is not empty + last_line = lines[-1] + parts = last_line.split(':') # Split line into fields using ':' as a delimiter + if len(parts) >= 4: + result = f"{parts[2]} - {parts[3].strip()}" + else: + result = "Malformed line format" + else: + result = "File is empty" + except FileNotFoundError: + result = "File not found" + except OSError as e: + result = f"Error reading file: {e}" + ui.set('pass', result) \ No newline at end of file