Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Apr 17, 2020
1 parent 0b5a63a commit 6038f55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
2 changes: 2 additions & 0 deletions pwnagotchi/bettercap.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ async def start_websocket(self, consumer):
logging.debug("Error while parsing event (%s)", ex)
except websockets.exceptions.ConnectionClosedError:
logging.debug("Lost websocket connection. Reconnecting...")
except websockets.exceptions.WebSocketException as wex:
logging.debug("Websocket exception (%s)", wex)

def run(self, command, verbose_errors=True):
r = requests.post("%s/session" % self.url, auth=self.auth, json={'cmd': command})
Expand Down
29 changes: 11 additions & 18 deletions pwnagotchi/plugins/default/watchdog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import re
import subprocess
from io import TextIOWrapper
from time import sleep
from threading import Lock
from pwnagotchi import plugins


Expand All @@ -16,7 +14,6 @@ class Watchdog(plugins.Plugin):

def __init__(self):
self.options = dict()
self.lock = Lock()
self.pattern = re.compile(r'brcmf_cfg80211_nexmon_set_channel.*?Set Channel failed')

def on_loaded(self):
Expand All @@ -26,18 +23,14 @@ def on_loaded(self):
logging.info("Watchdog plugin loaded.")

def on_epoch(self, agent, epoch, epoch_data):
if self.lock.locked():
return
with self.lock:
# get last 10 lines
last_lines = ''.join(list(TextIOWrapper(subprocess.Popen(['journalctl','-n10','-k'],
stdout=subprocess.PIPE).stdout))[-10:])
if len(self.pattern.findall(last_lines)) >= 3:
display = agent.view()
display.set('status', 'Blind-Bug detected. Restarting bettercap.')
display.update(force=True)
logging.info('[WATCHDOG] Blind-Bug detected. Restarting.')
mode_file = '/root/.pwnagotchi-manual' if agent.mode == 'manual' else '/root/.pwnagotchi-auto'
os.system(f"touch {mode_file}")
os.system('systemctl restart bettercap')
sleep(10)
# get last 10 lines
last_lines = ''.join(list(TextIOWrapper(subprocess.Popen(['journalctl','-n10','-k'],
stdout=subprocess.PIPE).stdout))[-10:])
if len(self.pattern.findall(last_lines)) >= 3:
display = agent.view()
display.set('status', 'Blind-Bug detected. Restarting bettercap.')
display.update(force=True)
logging.info('[WATCHDOG] Blind-Bug detected. Restarting.')
mode = 'MANU' if agent.mode == 'manual' else 'AUTO'
import pwnagotchi
pwnagotchi.restart(mode=mode)

0 comments on commit 6038f55

Please sign in to comment.