Created
April 10, 2020 08:52
-
-
Save BruceZhang1993/9f914ad4545e4c90c5051f35702df858 to your computer and use it in GitHub Desktop.
Helper script for Android to automate packet capture procedure (BurpSuite, Charles, etc)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Network presets | |
declare -A address="" | |
declare -A proxy="" | |
adb_connect() { | |
adb start-server | |
connected_devices=$(($(adb devices | wc -l)-2)) | |
if [ $connected_devices = "0" ]; | |
then | |
try_wireless_adb | |
connected_devices=$(($(adb devices | wc -l)-2)) | |
fi | |
if [ $connected_devices = "0" ]; | |
then | |
exit 1; | |
fi | |
} | |
try_wireless_adb() { | |
if [ -z "$address" ]; then | |
echo -n "Wireless ADB Address: " | |
read address | |
fi | |
adb connect "${address#\n}" | |
} | |
proxy_status() { | |
adb_connect | |
echo "== ADB Devices ==" | |
adb devices | |
echo "== Proxy Settings ==" | |
setting=$(adb shell settings get global http_proxy) | |
echo -n "$setting" | |
if [ "$setting" = ":0" ] || [ "$setting" = "null" ]; | |
then | |
echo " (Off)" | |
else | |
echo " (On)" | |
fi | |
echo "" | |
echo "== VPN Status ==" | |
adb shell ifconfig tun0 >/dev/null 2>&1 | |
if [ "$?" = 0 ]; | |
then | |
echo "On" | |
else | |
echo "Off" | |
fi | |
} | |
proxy_start() { | |
adb_connect | |
if [ -z "$proxy" ]; then | |
echo -n "Proxy: " | |
read proxy | |
fi | |
adb shell settings put global http_proxy $proxy | |
adb shell ifconfig tun0 >/dev/null 2>&1 | |
if [ "$?" = 0 ]; | |
then | |
echo -n "Stop shadowsocks now?(Y/n):" | |
read ssoff | |
case "${ssoff#\n}" in | |
"" | Y | y ) | |
adb shell am start -n com.github.shadowsocks/.QuickToggleShortcut; | |
sleep 2;; | |
esac | |
fi | |
proxy_status | |
} | |
proxy_stop() { | |
adb_connect | |
adb shell settings put global http_proxy :0 | |
adb shell ifconfig tun0 >/dev/null 2>&1 | |
if [ "$?" != 0 ]; | |
then | |
echo -n "Start shadowsocks now?(Y/n):" | |
read ssoff | |
case "${ssoff#\n}" in | |
"" | Y | y ) | |
adb shell am start -n com.github.shadowsocks/.QuickToggleShortcut; | |
sleep 2;; | |
esac | |
fi | |
proxy_status | |
} | |
case "$1" in | |
status) | |
proxy_status;; | |
start) | |
proxy_start;; | |
stop) | |
proxy_stop;; | |
*) | |
echo "Usage: proxy-helper [status|start|stop]";; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment