-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtor-remote
111 lines (96 loc) · 3.45 KB
/
tor-remote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# Copyright (c) 2022 by Philip Collier, github.com/AB9IL
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version. There is NO warranty; not even for
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Encoding=UTF-8
# config file format: standard openssh config syntax. Use the
# actual file ~/.ssh/config or a different one in the same format.
CONFIGFILE="$HOME/.ssh/config"
ROFI_COMMAND1='rofi -dmenu -p Select -lines 3'
FZF_COMMAND1='fzf --layout=reverse --header=Select:'
ROFI_COMMAND2='rofi -dmenu -p Select'
FZF_COMMAND2='fzf --layout=reverse --header=Select:'
FZF_COMMAND3="vim $CONFIGFILE"
ROFI_COMMAND3="x-terminal-emulator -e vim $CONFIGFILE"
edit_data(){
$COMMAND3
}
showhelp(){
echo -e "\nRemote Tor connection manager.
Connect to a remote Tor instance through an SSH tunnel.
Note 1: You MUST set up key based logins on the servers
AND have Tor installed on the server.
Note 2: Use proxychains to wrap your internet-using apps.
(This is already set up for firefox if using
the Firefox-with-proxy script.
Usage: $0 <option>
Options: gui Graphical user interface.
--help This help screen.\n"
}
start_tor_connection(){
sudo sed -i 's/^### FZPROXY.*/### FZPROXY\nsocks5 127.0.0.1 9050/;' /etc/proxychains4.conf
export https_proxy="https://127.0.0.1:9050"
export HTTPS_PROXY="https://127.0.0.1:9050"
export http_proxy="http://127.0.0.1:9050"
export HTTP_PROXY="http://127.0.0.1:9050"
export socks4_proxy="http://127.0.0.1:9050"
export SOCKS4_PROXY="http://127.0.0.1:9050"
export socks5_proxy="http://127.0.0.1:9050"
export SOCKS5_PROXY="http://127.0.0.1:9050"
export NO_PROXY='localhost, 127.0.0.1'
export no_proxy='localhost, 127.0.0.1'
export CHOICE="$(grep -E '^Host \w' $CONFIGFILE | awk '{print $2}' | $COMMAND2 )"
[[ -z "$CHOICE" ]] && echo "No selection..." && stop_tor_connection && exit 1
# set the proxy flag if a choice is made
[[ -z "$CHOICE" ]] || echo "$CHOICE" > /tmp/proxyflag && \
while ! ssh -L 9050:127.0.0.1:9050 -t -t $CHOICE; do sleep; done
stop_tor_connection
exit 0
}
stop_tor_connection(){
sudo sed -i '/^### FZPROXY.*/q;' /etc/proxychains4.conf
export https_proxy=
export HTTPS_PROXY=
export http_proxy=
export HTTP_PROXY=
export socks4_proxy=
export SOCKS4_PROXY=
export socks5_proxy=
export SOCKS5_PROXY=
export NO_PROXY=
export no_proxy=
k="$(pgrep "ssh")"
#read -r SERVER < /tmp/proxyflag
for process in ${k[@]};do
#sudo pkill -f "ssh -L 9050:127.0.0.1:9050 -t -t $SERVER"
sudo killall -g ssh
done
rm /tmp/proxyflag
exit 0
}
case "$1" in
"")
COMMAND1=$FZF_COMMAND1
COMMAND2=$FZF_COMMAND2
COMMAND3=$FZF_COMMAND3
;;
"gui")
COMMAND1=$ROFI_COMMAND1
COMMAND2=$ROFI_COMMAND2
COMMAND3=$ROFI_COMMAND3
;;
*)
showhelp
;;
esac
OPTIONS="Connect Tor Remote
Edit your server data
Disconnect Tor Remote"
# Take the choice; exit if no answer matches options.
REPLY="$(echo -e "$OPTIONS" | $COMMAND1 )"
[[ "$REPLY" == "Connect Tor Remote" ]] && start_tor_connection
[[ "$REPLY" == "Edit your server data" ]] && edit_data
[[ "$REPLY" == "Disconnect Tor Remote" ]] && stop_tor_connection