Skip to content

Instantly share code, notes, and snippets.

@tytydraco
Last active June 18, 2021 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tytydraco/38b20d1606b62d76a7f4740424c58df5 to your computer and use it in GitHub Desktop.
Save tytydraco/38b20d1606b62d76a7f4740424c58df5 to your computer and use it in GitHub Desktop.
Open an ADB shell session on an Android system via netcat
#!/system/bin/sh
LOCAL=false
PORT=65432
usage() {
echo "Usage: $0 [-h] [-l] [-k] [-p PORT]
-h Show this screen
-l Only allow localhost connections
-k Kill any open netcat sessions
-p PORT Port to listen for connections on (default: $PORT)"
}
while getopts ":lhkp:" opt
do
case "$opt" in
h)
usage
exit 0
;;
l)
LOCAL=true
;;
k)
pkill netcat
exit 0
;;
p)
PORT="$OPTARG"
;;
*)
usage
exit 1
;;
esac
done
ARGS=()
[[ "$LOCAL" == true ]] && ARGS+=("-s localhost")
# shellcheck disable=SC2068
setsid netcat -p "$PORT" -L ${ARGS[@]} sh &
echo -e "Done! Use: \e[1mnc localhost $PORT\e[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment