Created
September 9, 2011 11:53
-
-
Save timkuijsten/1206023 to your computer and use it in GitHub Desktop.
os x ssh proxy
This file contains hidden or 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
#!/bin/sh | |
# | |
# Copyright (c) 2011 Netsend | |
# Released under the MIT license. | |
# | |
### | |
# create a local ssh SOCKS proxy to RHOST and update OS X proxy settings. | |
# Tip: make your programs use the default OS X proxy. | |
##### | |
RHOST=shell.server.com | |
LPORT=9052 | |
INTERACTIVE=1 | |
echo=/bin/echo | |
usage() { | |
$echo "Setup an ssh proxy" | |
$echo "" | |
$echo "usage: `basename $0` [hostname]" | |
$echo "" | |
$echo "hostname remote ssh host" | |
$echo "" | |
} | |
PIDS=$(ps auxw | grep '[s]sh -2a' | awk '{ print $2}') | |
if [[ "$PIDS" != "" ]]; then | |
kill $PIDS | |
fi | |
if [ ! -z $1 ]; then | |
RHOST=$1 | |
fi | |
set -e | |
ssh -2a -D127.0.0.1:$LPORT -NnqTxy $RHOST & | |
sleep 1 | |
PID=$(lsof -tsTCP:LISTEN [email protected]:$LPORT) | |
# suppress "/usr/local/bin/tunnel: line 50: kill: ($PID) - No such process" | |
trap 'kill $PID 2>/dev/null; sudo networksetup -setsocksfirewallproxystate Ethernet off; sudo networksetup -setsocksfirewallproxystate AirPort off; exit $?' INT TERM EXIT | |
# update any changes to the local proxy port | |
sudo networksetup -setsocksfirewallproxy Ethernet 127.0.0.1 $LPORT off | |
sudo networksetup -setsocksfirewallproxy AirPort 127.0.0.1 $LPORT off | |
# turn on the proxy | |
sudo networksetup -setsocksfirewallproxystate Ethernet on | |
sudo networksetup -setsocksfirewallproxystate AirPort on | |
# stay open if interactive | |
if [ "$INTERACTIVE" -eq 1 ]; then | |
echo PRESS CTRL-C to abort | |
cat | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tested on Snow Leopard, for Lion do s/AirPort/Wi-Fi/