Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
fix: fixed, refactored and centralized launchers logic (closes evilso…
Browse files Browse the repository at this point in the history
  • Loading branch information
Simone Margaritelli committed Oct 31, 2019
1 parent 13cc8cb commit c8d0ccc
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 38 deletions.
16 changes: 6 additions & 10 deletions builder/data/usr/bin/bettercap-launcher
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/usr/bin/env bash
source /usr/bin/pwnlib

# start mon0
/usr/bin/monstart
start_monitor_interface

# if usb0 or eth0 are up
if [[ $(ifconfig | grep usb0 | grep RUNNING) ]] || [[ !$(grep '1' /sys/class/net/eth0/carrier) ]]; then
# if override file exists, go into auto mode
if [ -f /root/.pwnagotchi-auto ]; then
/usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0
else
/usr/bin/bettercap -no-colors -caplet pwnagotchi-manual -iface mon0
fi
else
if is_auto_mode; then
/usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0
else
/usr/bin/bettercap -no-colors -caplet pwnagotchi-manual -iface mon0
fi
10 changes: 0 additions & 10 deletions builder/data/usr/bin/bootblink

This file was deleted.

3 changes: 2 additions & 1 deletion builder/data/usr/bin/monstart
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env bash
iw phy phy0 interface add mon0 type monitor && ifconfig mon0 up
source /usr/bin/pwnlib
start_monitor_interface
3 changes: 2 additions & 1 deletion builder/data/usr/bin/monstop
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/usr/bin/env bash
ifconfig mon0 down && iw dev mon0 del
source /usr/bin/pwnlib
stop_monitor_interface
17 changes: 6 additions & 11 deletions builder/data/usr/bin/pwnagotchi-launcher
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
#!/usr/bin/env bash
source /usr/bin/pwnlib

# blink 10 times to signal ready state
/usr/bin/bootblink 10 &
blink_led 10 &

# if usb0 or eth0 are up
if [[ $(ifconfig | grep usb0 | grep RUNNING) ]] || [[ !$(grep '1' /sys/class/net/eth0/carrier) ]]; then
# if override file exists, go into auto mode
if [ -f /root/.pwnagotchi-auto ]; then
rm /root/.pwnagotchi-auto
/usr/local/bin/pwnagotchi
else
/usr/local/bin/pwnagotchi --manual
fi
else
if is_auto_mode; then
/usr/local/bin/pwnagotchi
else
/usr/local/bin/pwnagotchi --manual
fi
54 changes: 54 additions & 0 deletions builder/data/usr/bin/pwnlib
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

# well ... it blinks the led
blink_led() {
for i in $(seq 1 "$1"); do
echo 0 >/sys/class/leds/led0/brightness
sleep 0.3
echo 1 >/sys/class/leds/led0/brightness
sleep 0.3
done
echo 0 >/sys/class/leds/led0/brightness
sleep 0.3
}

# starts mon0
start_monitor_interface() {
iw phy phy0 interface add mon0 type monitor && ifconfig mon0 up
}

# stops mon0
stop_monitor_interface() {
ifconfig mon0 down && iw dev mon0 del
}

# returns 0 if the specificed network interface is up
is_interface_up() {
if grep -qi 'up' /sys/class/net/$1/operstate; then
return 0
fi
return 1
}

# returns 0 if conditions for AUTO mode are met
is_auto_mode() {
# check override file first
if [ -f /root/.pwnagotchi-auto ]; then
# remove the override file if found
rm -rf /root/.pwnagotchi-auto
return 0
fi

# if usb0 is up, we're in MANU
if is_interface_up usb0; then
return 1
fi

# if eth0 is up (for other boards), we're in MANU
if is_interface_up eth0; then
return 1
fi

# no override, but none of the interfaces is up -> AUTO
return 0
}
10 changes: 5 additions & 5 deletions builder/pwnagotchi.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"apt-get install -y ansible"
]
},
{
"type": "file",
"source": "data/usr/bin/pwnlib",
"destination": "/usr/bin/pwnlib"
},
{
"type": "file",
"source": "data/usr/bin/bettercap-launcher",
Expand All @@ -34,11 +39,6 @@
"source": "data/usr/bin/monstop",
"destination": "/usr/bin/monstop"
},
{
"type": "file",
"source": "data/usr/bin/bootblink",
"destination": "/usr/bin/bootblink"
},
{
"type": "file",
"source": "data/usr/bin/monstart",
Expand Down

0 comments on commit c8d0ccc

Please sign in to comment.