This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
watchdog.py
56 lines (46 loc) · 1.86 KB
/
watchdog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import os
import logging
import re
import subprocess
from io import TextIOWrapper
from pwnagotchi import plugins
from pwnagotchi.utils import StatusFile
class Watchdog(plugins.Plugin):
__author__ = '[email protected]'
__version__ = '1.0.0'
__license__ = 'GPL3'
__description__ = 'Restart pwnagotchi when blindbug is detected.'
__defaults__ = {
'enabled': False,
}
def __init__(self):
self.options = dict()
self.pattern = re.compile(r'brcmf_cfg80211_nexmon_set_channel.*?Set Channel failed')
self.status = StatusFile('/root/.pwnagotchi-watchdog')
self.status.update()
def on_loaded(self):
"""
Gets called when the plugin gets loaded
"""
logging.info("Watchdog plugin loaded.")
def on_epoch(self, agent, epoch, epoch_data):
if self.status.newer_then_minutes(5):
return
data_keys = ['num_deauths', 'num_associations', 'num_handshakes']
has_interactions = any([epoch_data[x]
for x in data_keys
if x in epoch_data])
if has_interactions:
return
epoch_duration = epoch_data['duration_secs']
# get last 10 lines
last_lines = ''.join(list(TextIOWrapper(subprocess.Popen(['journalctl','-n10','-k', '--since', f"{epoch_duration} seconds ago"],
stdout=subprocess.PIPE).stdout))[-10:])
if len(self.pattern.findall(last_lines)) >= 5:
display = agent.view()
display.set('status', 'Blind-Bug detected. Restarting.')
display.update(force=True)
logging.info('[WATCHDOG] Blind-Bug detected. Restarting.')
mode = 'MANU' if agent.mode == 'manual' else 'AUTO'
import pwnagotchi
pwnagotchi.reboot(mode=mode)