Last active
September 19, 2018 06:53
-
-
Save allen-munsch/63c2071103cbb04cbd82d10a47baf67e to your computer and use it in GitHub Desktop.
ssh socks forward proxy with firefox
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/bash | |
# usage: chmod +x ./foxinsock.sh && ./foxinsock.sh 123.456.789.012 | |
export PROXY=$1 | |
# assumes 1 default profile "*.default" | |
if [[ "$OSTYPE" == "darwin"* ]]; then | |
export FFPROFILE=/Users/$USER/Library/Application\ Support/Firefox/Profiles/*.default/ | |
else | |
export FFPROFILE=$HOME/.mozilla/firefox/profiles/*.default | |
fi | |
export CURRENTIP=$(curl ifconfig.co) | |
echo current $CURRENTIP | |
# setup route on forward machine | |
ssh -t root@$PROXY "sudo iptables -A INPUT --src $CURRENTIP --protocol tcp --dport 8500 -j ACCEPT" | |
# update firefox profile connection settings | |
sed -i 's/user_pref("network.proxy.socks", ".*");/user_pref("network.proxy.socks", "localhost");/g' $FFPROFILE/prefs.js | |
sed -i 's/user_pref("network.proxy.socks_port", .*);/user_pref("network.proxy.socks_port", 8500);/g' $FFPROFILE/prefs.js | |
sed -i 's/user_pref("network.proxy.type", .*);/user_pref("network.proxy.type", 1);/g' $FFPROFILE/prefs.js | |
# setup tunnel | |
ssh -D 8500 -f -C -q -N root@$PROXY & | |
export PROXYIP=$(curl ifconfig.co -x localhost:8500) | |
echo proxy $PROXYIP | |
if command -v firefox;then | |
export FF=$(command -v firefox) | |
else | |
export FF=/Applications/Firefox.app/Contents/MacOS/firefox | |
fi | |
# open firefox with profile | |
$FF --profile $FFPROFILE |
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/bash | |
ssh -t root@$PROXY "sudo iptables -D INPUT --src $CURRENTIP --protocol tcp --dport 8500 -j ACCEPT" | |
sed -i 's/user_pref("network.proxy.type", .*);/user_pref("network.proxy.type", 0);/g' $FFPROFILE/prefs.js | |
kill $(ps aux | grep ssh | grep 8500 | awk '{ print $2 }') | |
export PROXYIP=$(curl ifconfig.co -x localhost:8500) | |
echo proxy $PROXYIP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment