-
Notifications
You must be signed in to change notification settings - Fork 21
/
torproxy
executable file
·126 lines (109 loc) · 2.52 KB
/
torproxy
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
set -e
torproxy="torproxy_module"
torprocess="tor"
# check if tor is running
tor_running(){
if pgrep -x "$torprocess" >> /dev/null
then
echo 1
else
echo 0
fi
return 0
}
# checks if tor module already loaded
module_loaded(){
while read -r line
do
module=$(echo "$line"|cut -d' ' -f1)
if [ $module = $torproxy ]; then
echo 1
return 0
fi
done <<< "$(lsmod)"
echo 0
return 0
}
# removes tor module
remove_tor_module(){
local mod_loaded=$(module_loaded)
if [ $mod_loaded = 1 ]; then
rmmod ${torproxy}
echo "[-] torproxy module removed"
else
echo "[-] torproxy module is not loaded"
fi
}
# inserts necceasry kernel modules
insert_module(){
local tor_is_running=$(tor_running)
if [ $tor_is_running = 0 ] ; then
echo "[*] Could not find running Tor process"
exit
fi
# ensure necessary netfilter modules are loaded
modprobe -a nf_conntrack nf_conntrack_ipv4 nf_nat nf_nat_ipv4 x_tables ip_tables iptable_nat xt_REDIRECT
local mod_loaded=$(module_loaded)
if [ $mod_loaded = 0 ] ; then
insmod build/kernel_module/${torproxy}.ko
echo "[+] torproxy module inserted"
echo "[+] Remember to remove module using '-r' option to allow regular internet access"
fi
}
# starts the proxy
start_torproxy(){
./relay_pop
echo "[*] All network traffic now being routed through Tor network"
exit
}
# Displays usage
usage(){
echo " _______ _____ "
echo " |__ __| | __ \ "
echo " | | ___ _ __| |__) | __ _____ ___ _ "
echo " | |/ _ \| '__| ___/ '__/ _ \ \/ / | | |"
echo " | | (_) | | | | | | | (_) > <| |_| |"
echo " |_|\___/|_| |_| |_| \___/_/\_\\__, |"
echo " __/ |"
echo " |___/ "
echo ""
echo "Uses netfilter hooks to route all network traffic through tor network"
echo "options:"
echo " -s insert module and start proxy"
echo " -i insert torproxy kernel module"
echo " -r remove torproxy kernel module"
echo " -t refresh tor relays table"
echo ""
}
# Check root
if (( $EUID != 0 )); then
echo "must run as root!"
exit
fi
while getopts "hsirt" opt; do
case $opt in
h)
usage
;;
s)
insert_module
start_torproxy
;;
i)
insert_module
;;
r)
remove_tor_module
;;
t)
./relay_pop
;;
\?)
echo "Invalid option: -$OPTARG"
;;
esac
done
if [ $OPTIND = 1 ]; then
usage
fi