Skip to content

Commit

Permalink
added watchdog
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Apr 17, 2020
1 parent 1f7bc60 commit 311931c
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 5 deletions.
6 changes: 6 additions & 0 deletions builder/data/usr/bin/bettercap-launcher
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion builder/data/usr/bin/pwnlib
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pwnagotchi/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def _event_poller(self, loop):

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):
Expand Down
43 changes: 43 additions & 0 deletions pwnagotchi/plugins/default/watchdog.py
Original file line number Diff line number Diff line change
@@ -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)
45 changes: 42 additions & 3 deletions pwnagotchi/ui/web/templates/plugins.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -28,10 +59,18 @@
{% 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() }}"/>
Expand Down

0 comments on commit 311931c

Please sign in to comment.