added watchdog

This commit is contained in:
dadav 2020-04-16 17:35:41 +02:00
parent 1f7bc60de6
commit 311931c81d
5 changed files with 107 additions and 5 deletions

View File

@ -9,6 +9,12 @@ if is_crypted_mode; then
done
fi
# check if wifi driver is bugged
if ! check_brcm; then
reload_brcm
sleep 10
fi
# start mon0
start_monitor_interface

View File

@ -12,9 +12,23 @@ blink_led() {
sleep 0.3
}
# check if brcm is stuck
check_brcm() {
if [[ "$(journalctl -b0 -k --no-pager | tail -10 | grep -c 'brcmf_cfg80211_nexmon_set_channel.*Set Channel failed')" -ge 3 ]]; then
return 1
fi
return 0
}
# reload mod
reload_brcm() {
rmmod brcmfmac
modprobe brcmfmac
}
# starts mon0
start_monitor_interface() {
iw phy phy0 interface add mon0 type monitor && ifconfig mon0 up
iw phy "$(iw phy | head -1 | cut -d" " -f2)" interface add mon0 type monitor && ifconfig mon0 up
}
# stops mon0

View File

@ -364,7 +364,7 @@ class Agent(Client, Automata, AsyncAdvertiser, AsyncTrainer):
def start_event_polling(self):
# start a thread and pass in the mainloop
_thread.start_new_thread(self._event_poller, (asyncio.new_event_loop(),))
_thread.start_new_thread(self._event_poller, (asyncio.get_event_loop(),))
def is_module_running(self, module):

View File

@ -0,0 +1,43 @@
import os
import logging
import re
import subprocess
from io import TextIOWrapper
from time import sleep
from threading import Lock
from pwnagotchi import plugins
class Watchdog(plugins.Plugin):
__author__ = '33197631+dadav@users.noreply.github.com'
__version__ = '0.1.0'
__license__ = 'GPL3'
__description__ = 'Restart pwnagotchi when blindbug is detected.'
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):
"""
Gets called when the plugin gets loaded
"""
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)

View File

@ -5,6 +5,37 @@
Plugins
{% endblock %}
{% block styles %}
{{ super() }}
<style>
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #3388cc;
color: #fff;
text-align: center;
border-radius: 10px;
border: 2px solid black;
padding: 20px 0;
position: absolute;
z-index: 1;
top: 100%;
left: 50%;
margin-left: -100px;
}
.tooltip:hover .tooltiptext {
visibility: visible;
}
</style>
{% endblock %}
{% block script %}
$(function(){
$('input[type=checkbox]').change(function(e) {
@ -28,10 +59,18 @@ $(function(){
{% block content %}
<div id="container">
{% for name in database.keys() %}
{% set has_info = name in loaded and loaded[name].__description__ is defined %}
<div class="plugins-box">
<h4>
<a {% if name in loaded and loaded[name].on_webhook is defined %} href="/plugins/{{name}}" {% endif %}>{{name}}</a>
</h4>
<div class="tooltip">
<h4>
<a {% if name in loaded and loaded[name].on_webhook is defined %} href="/plugins/{{name}}" {% endif %}>{{name}}</a>
</h4>
{% if has_info %}
<span class="tooltiptext">{{ loaded[name].__description__ }}</span>
{% else %}
<span class="tooltiptext">Description can't be loaded yet.</span>
{% endif %}
</div>
<form method="POST" action="/plugins/toggle">
<input type="checkbox" data-role="flipswitch" name="enabled" id="flip-checkbox-{{name}}" data-on-text="Enabled" data-off-text="Disabled" data-wrapper-class="custom-size-flipswitch" {% if name in loaded %} checked {% endif %}>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>