Add lock
This commit is contained in:
parent
e04e053cee
commit
4fb7205281
@ -2,20 +2,27 @@ import os
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
|
from threading import Lock
|
||||||
from pwnagotchi.utils import StatusFile
|
from pwnagotchi.utils import StatusFile
|
||||||
import pwnagotchi.plugins as plugins
|
import pwnagotchi.plugins as plugins
|
||||||
|
from json.decoder import JSONDecodeError
|
||||||
|
|
||||||
|
|
||||||
class OnlineHashCrack(plugins.Plugin):
|
class OnlineHashCrack(plugins.Plugin):
|
||||||
__author__ = '33197631+dadav@users.noreply.github.com'
|
__author__ = '33197631+dadav@users.noreply.github.com'
|
||||||
__version__ = '2.0.0'
|
__version__ = '2.0.1'
|
||||||
__license__ = 'GPL3'
|
__license__ = 'GPL3'
|
||||||
__description__ = 'This plugin automatically uploads handshakes to https://onlinehashcrack.com'
|
__description__ = 'This plugin automatically uploads handshakes to https://onlinehashcrack.com'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ready = False
|
self.ready = False
|
||||||
self.report = StatusFile('/root/.ohc_uploads', data_format='json')
|
try:
|
||||||
|
self.report = StatusFile('/root/.ohc_uploads', data_format='json')
|
||||||
|
except JSONDecodeError as json_err:
|
||||||
|
os.remove('/root/.ohc_uploads')
|
||||||
|
self.report = StatusFile('/root/.ohc_uploads', data_format='json')
|
||||||
self.skip = list()
|
self.skip = list()
|
||||||
|
self.lock = Lock()
|
||||||
|
|
||||||
def on_loaded(self):
|
def on_loaded(self):
|
||||||
"""
|
"""
|
||||||
@ -68,39 +75,40 @@ class OnlineHashCrack(plugins.Plugin):
|
|||||||
"""
|
"""
|
||||||
Called in manual mode when there's internet connectivity
|
Called in manual mode when there's internet connectivity
|
||||||
"""
|
"""
|
||||||
if self.ready:
|
with self.lock:
|
||||||
display = agent.view()
|
if self.ready:
|
||||||
config = agent.config()
|
display = agent.view()
|
||||||
reported = self.report.data_field_or('reported', default=list())
|
config = agent.config()
|
||||||
|
reported = self.report.data_field_or('reported', default=list())
|
||||||
|
|
||||||
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 if
|
handshake_paths = [os.path.join(handshake_dir, filename) for filename in handshake_filenames if
|
||||||
filename.endswith('.pcap')]
|
filename.endswith('.pcap')]
|
||||||
|
|
||||||
# pull out whitelisted APs
|
# pull out whitelisted APs
|
||||||
handshake_paths = filter(lambda path: self._filter_handshake_file(path), handshake_paths)
|
handshake_paths = filter(lambda path: self._filter_handshake_file(path), handshake_paths)
|
||||||
|
|
||||||
handshake_new = set(handshake_paths) - set(reported) - set(self.skip)
|
handshake_new = set(handshake_paths) - set(reported) - set(self.skip)
|
||||||
|
|
||||||
if handshake_new:
|
if handshake_new:
|
||||||
logging.info("OHC: Internet connectivity detected. Uploading new handshakes to onelinehashcrack.com")
|
logging.info("OHC: Internet connectivity detected. Uploading new handshakes to onelinehashcrack.com")
|
||||||
|
|
||||||
for idx, handshake in enumerate(handshake_new):
|
for idx, handshake in enumerate(handshake_new):
|
||||||
display.set('status',
|
display.set('status',
|
||||||
f"Uploading handshake to onlinehashcrack.com ({idx + 1}/{len(handshake_new)})")
|
f"Uploading handshake to onlinehashcrack.com ({idx + 1}/{len(handshake_new)})")
|
||||||
display.update(force=True)
|
display.update(force=True)
|
||||||
try:
|
try:
|
||||||
self._upload_to_ohc(handshake)
|
self._upload_to_ohc(handshake)
|
||||||
if handshake not in reported:
|
if handshake not in reported:
|
||||||
reported.append(handshake)
|
reported.append(handshake)
|
||||||
self.report.update(data={'reported': reported})
|
self.report.update(data={'reported': reported})
|
||||||
logging.info(f"OHC: Successfully uploaded {handshake}")
|
logging.info(f"OHC: Successfully uploaded {handshake}")
|
||||||
except requests.exceptions.RequestException as req_e:
|
except requests.exceptions.RequestException as req_e:
|
||||||
self.skip.append(handshake)
|
self.skip.append(handshake)
|
||||||
logging.error("OHC: %s", req_e)
|
logging.error("OHC: %s", req_e)
|
||||||
continue
|
continue
|
||||||
except OSError as os_e:
|
except OSError as os_e:
|
||||||
self.skip.append(handshake)
|
self.skip.append(handshake)
|
||||||
logging.error("OHC: %s", os_e)
|
logging.error("OHC: %s", os_e)
|
||||||
continue
|
continue
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import threading
|
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from threading import Lock
|
||||||
from pwnagotchi.utils import StatusFile
|
from pwnagotchi.utils import StatusFile
|
||||||
from pwnagotchi import plugins
|
from pwnagotchi import plugins
|
||||||
from json.decoder import JSONDecodeError
|
from json.decoder import JSONDecodeError
|
||||||
@ -16,7 +16,7 @@ class WpaSec(plugins.Plugin):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ready = False
|
self.ready = False
|
||||||
self.lock = threading.Lock()
|
self.lock = Lock()
|
||||||
try:
|
try:
|
||||||
self.report = StatusFile('/root/.wpa_sec_uploads', data_format='json')
|
self.report = StatusFile('/root/.wpa_sec_uploads', data_format='json')
|
||||||
except JSONDecodeError as json_err:
|
except JSONDecodeError as json_err:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user