Upload via python library
This commit is contained in:
parent
683d260c74
commit
b8e6f9f979
@ -1,25 +1,22 @@
|
|||||||
__author__ = '33197631+dadav@users.noreply.github.com'
|
__author__ = '33197631+dadav@users.noreply.github.com'
|
||||||
__version__ = '1.0.0'
|
__version__ = '1.0.0'
|
||||||
__name__ = 'wpa_sec'
|
__name__ = 'wpa-sec'
|
||||||
__license__ = 'GPL3'
|
__license__ = 'GPL3'
|
||||||
__description__ = 'This plugin automatically uploades handshakes to https://wpa-sec.stanev.org'
|
__description__ = 'This plugin automatically uploades handshakes to https://wpa-sec.stanev.org'
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import requests
|
||||||
|
|
||||||
READY = False
|
READY = False
|
||||||
API_KEY = None
|
API_KEY = None
|
||||||
ALREADY_UPLOADED = None
|
ALREADY_UPLOADED = None
|
||||||
|
|
||||||
|
|
||||||
# INSTALLATION:
|
|
||||||
## apt-get install libcurl4-openssl-dev
|
|
||||||
## https://github.com/ZerBea/hcxtools.git
|
|
||||||
## cd hcxtools; gcc wlancap2wpasec.c -o wlancap2wpasec -lcurl
|
|
||||||
## mv wlancap2wpasec /usr/bin/
|
|
||||||
|
|
||||||
def on_loaded():
|
def on_loaded():
|
||||||
|
"""
|
||||||
|
Gets called when the plugin gets loaded
|
||||||
|
"""
|
||||||
global READY
|
global READY
|
||||||
global API_KEY
|
global API_KEY
|
||||||
global ALREADY_UPLOADED
|
global ALREADY_UPLOADED
|
||||||
@ -28,50 +25,57 @@ def on_loaded():
|
|||||||
logging.error("WPA_SEC: API-KEY isn't set. Can't upload to wpa-sec.stanev.org")
|
logging.error("WPA_SEC: API-KEY isn't set. Can't upload to wpa-sec.stanev.org")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
|
||||||
subprocess.call("wlancap2wpasec -h >/dev/null".split(), stdout=open(os.devnull, 'wb'))
|
|
||||||
except OSError:
|
|
||||||
logging.error("WPA_SEC: Can't find wlancap2wpasec. Install hcxtools to use this plugin!")
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open('/root/.wpa_sec_uploads', 'r') as f:
|
with open('/root/.wpa_sec_uploads', 'r') as f:
|
||||||
ALREADY_UPLOADED = f.read().splitlines()
|
ALREADY_UPLOADED = f.read().splitlines()
|
||||||
except OSError:
|
except OSError:
|
||||||
logging.error('WPA_SEC: No upload-file found.')
|
logging.warning('WPA_SEC: No upload-file found.')
|
||||||
ALREADY_UPLOADED = []
|
ALREADY_UPLOADED = []
|
||||||
|
|
||||||
READY = True
|
READY = True
|
||||||
|
|
||||||
|
|
||||||
def _upload_to_wpasec(path):
|
def _upload_to_wpasec(path, timeout=30):
|
||||||
try:
|
"""
|
||||||
subprocess.call(f"wlancap2wpasec -k {API_KEY} {path}".split(), stdout=open(os.devnull, 'wb'))
|
Uploads the file to wpa-sec.stanev.org
|
||||||
except OSError as os_e:
|
"""
|
||||||
logging.error(f"WPA_SEC: Error while uploading {path}")
|
with open(path, 'rb') as file_to_upload:
|
||||||
raise os_e
|
headers = {'key': API_KEY}
|
||||||
|
payload = {'file': file_to_upload}
|
||||||
|
|
||||||
|
try:
|
||||||
|
requests.post('https://wpa-sec.stanev.org/?submit',
|
||||||
|
headers=headers,
|
||||||
|
files=payload,
|
||||||
|
timeout=timeout)
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
|
logging.error(f"WPA_SEC: Got an exception while uploading {path} -> {e}")
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
# called in manual mode when there's internet connectivity
|
|
||||||
def on_internet_available(display, config, log):
|
def on_internet_available(display, config, log):
|
||||||
|
"""
|
||||||
|
Called in manual mode when there's internet connectivity
|
||||||
|
"""
|
||||||
if READY:
|
if READY:
|
||||||
|
|
||||||
handshake_dir = config['bettercap']['handshakes']
|
handshake_dir = config['bettercap']['handshakes']
|
||||||
handshake_filenames = os.listdir(handshake_dir)
|
handshake_filenames = os.listdir(handshake_dir)
|
||||||
handshake_paths = [os.path.join(handshake_dir, filename) for filename in handshake_filenames]
|
handshake_paths = [os.path.join(handshake_dir, filename) for filename in handshake_filenames]
|
||||||
handshake_new = set(handshake_paths) - set(ALREADY_UPLOADED)
|
handshake_new = set(handshake_paths) - set(ALREADY_UPLOADED)
|
||||||
|
|
||||||
if handshake_new:
|
if handshake_new:
|
||||||
logging.info("Internet connectivity detected.\
|
logging.info("WPA_SEC: Internet connectivity detected.\
|
||||||
Uploading new handshakes to wpa-sec.stanev.org")
|
Uploading new handshakes to wpa-sec.stanev.org")
|
||||||
|
|
||||||
for idx, handshake in enumerate(handshake_new):
|
for idx, handshake in enumerate(handshake_new):
|
||||||
display.set('status', "Uploading handshake to wpa-sec.stanev.org ({idx + 1}/{len(handshake_new})")
|
display.set('status', f"Uploading handshake to wpa-sec.stanev.org ({idx + 1}/{len(handshake_new)})")
|
||||||
display.update(force=True)
|
display.update(force=True)
|
||||||
try:
|
try:
|
||||||
_upload_to_wpasec(handshake)
|
_upload_to_wpasec(handshake)
|
||||||
ALREADY_UPLOADED.append(handshake)
|
ALREADY_UPLOADED.append(handshake)
|
||||||
with open('/root/.wpa_sec_uploads', 'a') as f:
|
with open('/root/.wpa_sec_uploads', 'a') as f:
|
||||||
f.write(handshake + "\n")
|
f.write(handshake + "\n")
|
||||||
except OSError:
|
except requests.exceptions.RequestException:
|
||||||
pass
|
pass
|
||||||
|
except OSError as os_e:
|
||||||
|
logging.error(f"WPA_SEC: Got the following error: {os_e}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user