#!/bin/bash # # An SSH ProxyCommand to use a SOCKS Proxy server # You can also use this command using ssh's own built in SOCKS ( -D param ) # to tunnel addtitional SSH connections over the first one, eg: # # First SSH: # ssh -D 8080 user@host # # Second (tunneled) SSH: # # ssh -oProxyCommand=./this.sh user@host # # The second ssh will use the SOCKS proxy established by the first SSH # to connect. # # Tue Feb 20 15:58:19 GMT 2007 - Robert McKay # # If you like this, perhaps you'll like http://wari.mckay.com/~rm/proxy2ssh/ # configuration section HOST=192.75.95.75 # If you have SOCKSv4a then you can use hostnames #HOST=chebucto.ns.ca PORT=22 PROXY=localhost PROXY_PORT=8080 PROXY_PROTO="v4" # Use "v4a" or "v4" # End of config section. function dec2hex { printf "\\\x%.2x" "$1" } if [ "${PROXY_PROTO}X" == "v4X" ]; then OIFS=$IFS IFS="." hexhost= for part in $HOST; do hexhost="${hexhost}$(dec2hex ${part})" done IFS=$OIFS fi # echo -en "\xC0\x4B\x5F\x4B" # SOCKSv4 preamble ( echo -en "\x04" # Protocol version 4 echo -en "\x01" # TCP (UDP or "bind" in 4a) is \x02) echo -en "\x00\x16" # Port 22 if [ "${PROXY_PROTO}X" == "v4X" ]; then echo -en $hexhost echo -en "na\x00" # username / not required else echo -en "\x00\x00\x00\xFF" echo -en "na\x00" # username / not required echo -en "${HOST}.\x00" fi cat - ) | nc ${PROXY} ${PROXY_PORT} | ( head -c8 >/dev/null; cat )