You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.8 KiB
68 lines
1.8 KiB
9 months ago
|
#!/usr/bin/env bash
|
||
|
|
||
|
choice(){
|
||
|
local prompt=${1:-"Please make a selection"}
|
||
|
local choices="$(cat)"
|
||
|
local x=1
|
||
|
local selection
|
||
|
echo "$choices" | while read line; do
|
||
|
echo "$x: $line" | column -t -s $'\t' > /dev/tty
|
||
|
x=$((x+1))
|
||
|
done
|
||
|
echo -n "$prompt " > /dev/tty
|
||
|
read selection < /dev/tty
|
||
|
echo "$choices" | sed -n "$selection p" | cut -d $'\t' -f 1
|
||
|
}
|
||
|
|
||
|
print_help(){
|
||
|
echo "$0 This helps with generating ssh tunnels"
|
||
|
echo " -h||--help show this help"
|
||
|
exit 0
|
||
|
}
|
||
|
|
||
|
dryrun="false"
|
||
|
|
||
|
while [[ $1 = -?* ]]; do
|
||
|
case $1 in
|
||
|
-h|--help) print_help >&2 ;;
|
||
|
*) echo "Unknown option $1"; print_help >&2 ;;
|
||
|
esac
|
||
|
shift
|
||
|
done
|
||
|
|
||
|
forwardtype="$(
|
||
|
(
|
||
|
echo -e "local\tAccess on local machine something that is accessible on remote"
|
||
|
echo -e "remote\tAccess on remote machine something that is accessible on local"
|
||
|
echo -e "dynamic\tSimilar to local but creates a socks proxy"
|
||
|
) | choice "Forward Type:" )"
|
||
|
|
||
|
case "$forwardtype" in
|
||
|
"local")
|
||
|
echo "How would you access the resource if on the remote machine?"
|
||
|
echo "e.g. localhost:8834 if nessus is hosted on the remote machine"
|
||
|
echo -n "> "
|
||
|
read remote < /dev/tty
|
||
|
echo "Which local port would you like to listen on?"
|
||
|
echo -n "> "
|
||
|
read localport < /dev/tty
|
||
|
echo "ssh -L ${localport}:${remote} <server>"
|
||
|
;;
|
||
|
"remote")
|
||
|
echo "How would you access the resource if on the local machine?"
|
||
|
echo "e.g. internal-intranet:443 if there was an internal resource you wanted to get access to"
|
||
|
echo -n "> "
|
||
|
read localresource < /dev/tty
|
||
|
echo "Which remote port would you like to listen on the remote server (that you're sshing into)?"
|
||
|
echo -n "> "
|
||
|
read remoteport < /dev/tty
|
||
|
echo "ssh -R ${remoteport}:${localresource} <server>"
|
||
|
;;
|
||
|
"dynamic")
|
||
|
echo "Which local port would you like to listen on?"
|
||
|
echo -n "> "
|
||
|
read localport < /dev/tty
|
||
|
echo "ssh -D ${localport} <server>"
|
||
|
;;
|
||
|
esac
|