Skip to content

Commit

Permalink
Merge pull request #855 from dadav/develop
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
evilsocket authored Apr 20, 2020
2 parents 1f7bc60 + e927511 commit a3cf492
Show file tree
Hide file tree
Showing 54 changed files with 1,813 additions and 98 deletions.
29 changes: 29 additions & 0 deletions builder/data/etc/bash_completion.d/pwnagotchi_completion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
_show_complete()
{
local cur opts node_names all_options opt_line
all_options="
pwnagotchi -h --help -C --config -U --user-config --manual --skip-session --clear --debug --version --print-config {plugins}
pwnagotchi plugins -h --help {list,install,enable,disable,uninstall,update,upgrade}
pwnagotchi plugins list -i --installed -h --help
pwnagotchi plugins install -h --help
pwnagotchi plugins uninstall -h --help
pwnagotchi plugins enable -h --help
pwnagotchi plugins disable -h --help
pwnagotchi plugins update -h --help
pwnagotchi plugins upgrade -h --help
"
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
cmd="${COMP_WORDS[@]:0:${#COMP_WORDS[@]}-1}"
opt_line="$(grep -m1 "$cmd" <<<$all_options)"
if [[ ${cur} == -* ]] ; then
opts="$(echo $opt_line | tr ' ' '\n' | awk '/^ *-/{gsub("[^a-zA-Z0-9-]","",$1);print $1}')"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi

opts="$(echo $opt_line | grep -Po '{\K[^}]+' | tr ',' '\n')"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}

complete -F _show_complete pwnagotchi
9 changes: 9 additions & 0 deletions builder/data/usr/bin/bettercap-launcher
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ if is_crypted_mode; then
done
fi

# check if wifi driver is bugged
if ! check_brcm; then
if ! reload_brcm; then
echo "Could not reload wifi driver. Reboot"
reboot
fi
sleep 10
fi

# start mon0
start_monitor_interface

Expand Down
21 changes: 21 additions & 0 deletions builder/data/usr/bin/decryption-webserver
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,27 @@ POST_RESPONSE = """
text-align: center;
}
</style>
<script type="text/javascript">
function checkPwnagotchi() {
var target = 'http://' + document.location.hostname + ':8080/';
var xhr = new XMLHttpRequest();
xhr.open('GET', target);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200 || xhr.status == 401) {
window.location.replace(target);
}else{
setTimeout(checkPwnagotchi, 1000);
}
}
};
xhr.send();
}
setTimeout(checkPwnagotchi, 1000);
</script>
</head>
<body style="margin:0;">
Expand Down
24 changes: 22 additions & 2 deletions builder/data/usr/bin/pwnlib
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,28 @@ blink_led() {
sleep 0.3
}

# check if brcm is stuck
check_brcm() {
if [[ "$(journalctl -n10 -k --since -5m | grep -c 'brcmf_cfg80211_nexmon_set_channel.*Set Channel failed')" -ge 5 ]]; then
return 1
fi
return 0
}

# reload mod
reload_brcm() {
if ! modprobe -r brcmfmac; then
return 1
fi
if ! modprobe brcmfmac; then
return 1
fi
return 0
}

# 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 Expand Up @@ -158,7 +177,8 @@ EOF

pkill wpa_supplicant
pkill dnsmasq
kill "$(pgrep -f "decryption-webserver")"
pid="$(pgrep -f "decryption-webserver")"
[[ -n "$pid" ]] && kill "$pid"

return 0
}
2 changes: 1 addition & 1 deletion pwnagotchi/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.5.2'
__version__ = '1.5.3'
7 changes: 4 additions & 3 deletions pwnagotchi/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def _load_recovery_data(self, delete=True, no_exceptions=True):


def start_session_fetcher(self):
_thread.start_new_thread(self._fetch_stats, ())
_thread.start_new_thread(self._fetch_stats, ())


def _fetch_stats(self):
Expand All @@ -323,14 +323,15 @@ def _fetch_stats(self):
async def _on_event(self, msg):
found_handshake = False
jmsg = json.loads(msg)

if jmsg['tag'] == 'wifi.client.handshake':
filename = jmsg['data']['file']
sta_mac = jmsg['data']['station']
ap_mac = jmsg['data']['ap']
key = "%s -> %s" % (sta_mac, ap_mac)
if key not in self._handshakes:
self._handshakes[key] = jmsg
s = self.session()
ap_and_station = self._find_ap_sta_in(sta_mac, ap_mac, s)
if ap_and_station is None:
logging.warning("!!! captured new handshake: %s !!!", key)
Expand Down Expand Up @@ -364,7 +365,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
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
4 changes: 4 additions & 0 deletions pwnagotchi/defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ main.name = ""
main.lang = "en"
main.confd = "/etc/pwnagotchi/conf.d/"
main.custom_plugins = ""
main.custom_plugin_repos = [
"https://github.com/evilsocket/pwnagotchi-plugins-contrib/archive/master.zip"
]
main.iface = "mon0"
main.mon_start_cmd = "/usr/bin/monstart"
main.mon_stop_cmd = "/usr/bin/monstop"
Expand Down Expand Up @@ -110,6 +113,7 @@ main.plugins.led.patterns.peer_detected = "oo oo oo oo oo oo oo"
main.plugins.led.patterns.peer_lost = "oo oo oo oo oo oo oo"

main.plugins.logtail.enabled = false
main.plugins.logtail.max-lines = 10000

main.plugins.session-stats.enabled = true
main.plugins.session-stats.save_directory = "/var/tmp/pwnagotchi/sessions/"
Expand Down
2 changes: 2 additions & 0 deletions pwnagotchi/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def toggle_plugin(name, enable=True):

if enable and name in database and name not in loaded:
load_from_file(database[name])
if name in loaded and pwnagotchi.config and name in pwnagotchi.config['main']['plugins']:
loaded[name].options = pwnagotchi.config['main']['plugins'][name]
one(name, 'loaded')
if pwnagotchi.config:
one(name, 'config_changed', pwnagotchi.config)
Expand Down
61 changes: 33 additions & 28 deletions pwnagotchi/plugins/cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Handles the commandline stuff

import sys
import os
import logging
import glob
Expand All @@ -11,7 +10,6 @@
from pwnagotchi.plugins import default_path


REPO_URL = 'https://github.com/evilsocket/pwnagotchi-plugins-contrib/archive/master.zip'
SAVE_DIR = '/usr/local/share/pwnagotchi/availaible-plugins/'
DEFAULT_INSTALL_PATH = '/usr/local/share/pwnagotchi/installed-plugins/'

Expand Down Expand Up @@ -75,7 +73,7 @@ def handle_cmd(args, config):
Parses the arguments and does the thing the user wants
"""
if args.plugincmd == 'update':
return update()
return update(config)
elif args.plugincmd == 'search':
args.installed = True # also search in installed plugins
return list_plugins(args, config, args.pattern)
Expand Down Expand Up @@ -349,41 +347,48 @@ def _analyse_dir(path):
return results


def update():
def update(config):
"""
Updates the database
"""
global REPO_URL, SAVE_DIR
global SAVE_DIR

DEST = os.path.join(SAVE_DIR, 'plugins.zip')
logging.info('Downloading plugins to %s', DEST)
urls = config['main']['custom_plugin_repos']
if not urls:
logging.info('No plugin repositories configured.')
return 1

rc = 0
for idx, REPO_URL in enumerate(urls):
DEST = os.path.join(SAVE_DIR, 'plugins%d.zip' % idx)
logging.info('Downloading plugins from %s to %s', REPO_URL, DEST)

try:
os.makedirs(SAVE_DIR, exist_ok=True)
before_update = _analyse_dir(SAVE_DIR)
try:
os.makedirs(SAVE_DIR, exist_ok=True)
before_update = _analyse_dir(SAVE_DIR)

download_file(REPO_URL, os.path.join(SAVE_DIR, DEST))
download_file(REPO_URL, os.path.join(SAVE_DIR, DEST))

logging.info('Unzipping...')
unzip(DEST, SAVE_DIR, strip_dirs=1)
logging.info('Unzipping...')
unzip(DEST, SAVE_DIR, strip_dirs=1)

after_update = _analyse_dir(SAVE_DIR)
after_update = _analyse_dir(SAVE_DIR)

b_len = len(before_update)
a_len = len(after_update)
b_len = len(before_update)
a_len = len(after_update)

if a_len > b_len:
logging.info('Found %d new file(s).', a_len - b_len)
if a_len > b_len:
logging.info('Found %d new file(s).', a_len - b_len)

changed = 0
for filename, filehash in after_update.items():
if filename in before_update and filehash != before_update[filename]:
changed += 1
changed = 0
for filename, filehash in after_update.items():
if filename in before_update and filehash != before_update[filename]:
changed += 1

if changed:
logging.info('%d file(s) were changed.', changed)
if changed:
logging.info('%d file(s) were changed.', changed)

return 0
except Exception as ex:
logging.error('Error while updating plugins %s', ex)
return 1
except Exception as ex:
logging.error('Error while updating plugins: %s', ex)
rc = 1
return rc
Loading

0 comments on commit a3cf492

Please sign in to comment.