Merge pull request #664 from dadav/feature/wpa-sec-download
Add wpa-sec password download
This commit is contained in:
pwnagotchi
@ -39,6 +39,7 @@ main:
|
|||||||
enabled: false
|
enabled: false
|
||||||
api_key: ~
|
api_key: ~
|
||||||
api_url: "https://wpa-sec.stanev.org"
|
api_url: "https://wpa-sec.stanev.org"
|
||||||
|
download_results: false
|
||||||
wigle:
|
wigle:
|
||||||
enabled: false
|
enabled: false
|
||||||
api_key: ~
|
api_key: ~
|
||||||
|
@ -1,18 +1,26 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import threading
|
||||||
import requests
|
import requests
|
||||||
|
from datetime import datetime
|
||||||
from pwnagotchi.utils import StatusFile
|
from pwnagotchi.utils import StatusFile
|
||||||
import pwnagotchi.plugins as plugins
|
from pwnagotchi import plugins
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
|
|
||||||
|
|
||||||
class WpaSec(plugins.Plugin):
|
class WpaSec(plugins.Plugin):
|
||||||
__author__ = '33197631+dadav@users.noreply.github.com'
|
__author__ = '33197631+dadav@users.noreply.github.com'
|
||||||
__version__ = '2.0.1'
|
__version__ = '2.1.0'
|
||||||
__license__ = 'GPL3'
|
__license__ = 'GPL3'
|
||||||
__description__ = 'This plugin automatically uploads handshakes to https://wpa-sec.stanev.org'
|
__description__ = 'This plugin automatically uploads handshakes to https://wpa-sec.stanev.org'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ready = False
|
self.ready = False
|
||||||
|
self.lock = threading.Lock()
|
||||||
|
try:
|
||||||
|
self.report = StatusFile('/root/.wpa_sec_uploads', data_format='json')
|
||||||
|
except JSONDecodeError as json_err:
|
||||||
|
os.remove("/root/.wpa_sec_uploads")
|
||||||
self.report = StatusFile('/root/.wpa_sec_uploads', data_format='json')
|
self.report = StatusFile('/root/.wpa_sec_uploads', data_format='json')
|
||||||
self.options = dict()
|
self.options = dict()
|
||||||
self.skip = list()
|
self.skip = list()
|
||||||
@ -35,6 +43,29 @@ class WpaSec(plugins.Plugin):
|
|||||||
except requests.exceptions.RequestException as req_e:
|
except requests.exceptions.RequestException as req_e:
|
||||||
raise req_e
|
raise req_e
|
||||||
|
|
||||||
|
|
||||||
|
def _download_from_wpasec(self, output, timeout=30):
|
||||||
|
"""
|
||||||
|
Downloads the results from wpasec and safes them to output
|
||||||
|
|
||||||
|
Output-Format: bssid, station_mac, ssid, password
|
||||||
|
"""
|
||||||
|
api_url = self.options['api_url']
|
||||||
|
if not api_url.endswith('/'):
|
||||||
|
api_url = f"{api_url}/"
|
||||||
|
api_url = f"{api_url}?api&dl=1"
|
||||||
|
|
||||||
|
cookie = {'key': self.options['api_key']}
|
||||||
|
try:
|
||||||
|
result = requests.get(api_url, cookies=cookie, timeout=timeout)
|
||||||
|
with open(output, 'wb') 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_loaded(self):
|
def on_loaded(self):
|
||||||
"""
|
"""
|
||||||
Gets called when the plugin gets loaded
|
Gets called when the plugin gets loaded
|
||||||
@ -53,6 +84,7 @@ class WpaSec(plugins.Plugin):
|
|||||||
"""
|
"""
|
||||||
Called in manual mode when there's internet connectivity
|
Called in manual mode when there's internet connectivity
|
||||||
"""
|
"""
|
||||||
|
with self.lock:
|
||||||
if self.ready:
|
if self.ready:
|
||||||
config = agent.config()
|
config = agent.config()
|
||||||
display = agent.view()
|
display = agent.view()
|
||||||
@ -82,3 +114,18 @@ class WpaSec(plugins.Plugin):
|
|||||||
except OSError as os_e:
|
except OSError as os_e:
|
||||||
logging.error("WPA_SEC: %s", os_e)
|
logging.error("WPA_SEC: %s", os_e)
|
||||||
continue
|
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)
|
||||||
|
Reference in New Issue
Block a user