mirror of
https://github.com/edu4rdshl/tor-router.git
synced 2026-07-17 23:24:48 +00:00
Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5b79c1ce49 | |||
| 290d0b1e29 | |||
| ab272cb25f | |||
| 2fdae488f9 |
3 changed files with 75 additions and 72 deletions
|
|
@ -9,12 +9,11 @@ case "$1" in
|
||||||
start)
|
start)
|
||||||
if test -f "$RULES"; then
|
if test -f "$RULES"; then
|
||||||
echo "$RULES exists. Either delete it, or stop tor-router first."
|
echo "$RULES exists. Either delete it, or stop tor-router first."
|
||||||
exit
|
exit 1
|
||||||
else
|
else
|
||||||
iptables-save > $RULES
|
|
||||||
# Executable file to create rules for transparent proxy
|
# Executable file to create rules for transparent proxy
|
||||||
# Destinations you do not want routed through Tor
|
# Destinations you do not want routed through Tor
|
||||||
NON_TOR="192.168.1.0/24 192.168.0.0/24"
|
NON_TOR="192.168.1.0/24 192.168.0.0/24 10.0.0.0/8"
|
||||||
# the UID Tor runs as, actually only support for Debian, ArchLinux and Fedora as been added.
|
# the UID Tor runs as, actually only support for Debian, ArchLinux and Fedora as been added.
|
||||||
if command -v pacman >/dev/null; then
|
if command -v pacman >/dev/null; then
|
||||||
TOR_UID=$(id -u tor)
|
TOR_UID=$(id -u tor)
|
||||||
|
|
@ -24,44 +23,47 @@ case "$1" in
|
||||||
TOR_UID=$(id -u toranon)
|
TOR_UID=$(id -u toranon)
|
||||||
else
|
else
|
||||||
echo "Unknown distro, please create report the issue to https://github.com/edu4rdshl/tor-router/issues"
|
echo "Unknown distro, please create report the issue to https://github.com/edu4rdshl/tor-router/issues"
|
||||||
exit
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v tor >/dev/null; then
|
if ! command -v tor >/dev/null; then
|
||||||
echo "You need to install the tor package."
|
echo "You need to install the tor package."
|
||||||
exit
|
exit 1
|
||||||
elif ! systemctl is-active tor.service >/dev/null; then
|
elif ! systemctl is-active tor.service >/dev/null; then
|
||||||
echo "The tor service is not active, please start the tor service before running the script."
|
echo "The tor service is not active, please start the tor service before running the script."
|
||||||
exit
|
exit 1
|
||||||
elif ! command -v iptables >/dev/null; then
|
elif ! command -v iptables >/dev/null; then
|
||||||
echo "You need to install the iptables package."
|
echo "You need to install the iptables package."
|
||||||
exit
|
exit 1
|
||||||
else
|
else
|
||||||
|
# Only save the rules when we are sure that everything is working
|
||||||
|
iptables-save >$RULES
|
||||||
|
|
||||||
iptables -F
|
iptables -F
|
||||||
iptables -t nat -F
|
iptables -t nat -A OUTPUT -m owner --uid-owner "$TOR_UID" -j RETURN
|
||||||
iptables -t nat -A OUTPUT -m owner --uid-owner $TOR_UID -j RETURN
|
iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 6669
|
||||||
iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 5353
|
|
||||||
|
|
||||||
for NET in $NON_TOR 127.0.0.0/9 127.128.0.0/10; do
|
for NET in $NON_TOR 127.0.0.0/9 127.128.0.0/10; do
|
||||||
iptables -t nat -A OUTPUT -d $NET -j RETURN
|
iptables -t nat -A OUTPUT -d "$NET" -j RETURN
|
||||||
done
|
done
|
||||||
|
|
||||||
iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $TRANS_PORT
|
iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports $TRANS_PORT
|
||||||
|
iptables -t nat -A OUTPUT -p udp -j REDIRECT --to-ports $TRANS_PORT
|
||||||
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||||
|
|
||||||
for NET in $NON_TOR 127.0.0.0/8; do
|
for NET in $NON_TOR 127.0.0.0/8; do
|
||||||
iptables -A OUTPUT -d $NET -j ACCEPT
|
iptables -A OUTPUT -d "$NET" -j ACCEPT
|
||||||
done
|
done
|
||||||
|
|
||||||
iptables -A OUTPUT -m owner --uid-owner $TOR_UID -j ACCEPT
|
iptables -A OUTPUT -m owner --uid-owner "$TOR_UID" -j ACCEPT
|
||||||
iptables -A OUTPUT -j ACCEPT
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
stop)
|
stop)
|
||||||
if test -f "$RULES"; then
|
if test -f "$RULES"; then
|
||||||
echo "Restoring previous rules from $RULES"
|
echo "Restoring previous rules from $RULES"
|
||||||
iptables -t nat -F
|
iptables -F
|
||||||
iptables-restore <"$RULES"
|
iptables-restore <"$RULES"
|
||||||
rm "$RULES"
|
rm "$RULES"
|
||||||
else
|
else
|
||||||
|
|
@ -69,11 +71,13 @@ case "$1" in
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
restart)
|
restart)
|
||||||
stop
|
stop
|
||||||
sleep 2
|
sleep 1
|
||||||
start
|
start
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: $0 {start|stop|restart}"
|
echo "Usage: $0 {start|stop|restart}"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Start rules for transparent tor proxy
|
Description=Start rules for transparent tor proxy
|
||||||
After=network-online.target tor.service
|
After=network-online.target tor.service
|
||||||
|
Requires=tor.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
|
|
|
||||||
10
install.sh
10
install.sh
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
# Script that automate the procces for setting up TOR as a tranparent proxy
|
# Script that automate the procces for setting up TOR as a tranparent proxy
|
||||||
# Autor: Edu4rdSHL @edu4rdshl
|
# Autor: Edu4rdSHL @edu4rdshl
|
||||||
|
|
||||||
|
|
@ -23,19 +23,17 @@ if command -v tor >/dev/null && command -v systemctl > /dev/null ; then
|
||||||
echo -e "\nMaking a backup of your torrc file, if you have problems with the new configuration, delete $torconfig and move $torconfigbackup to $torconfig"
|
echo -e "\nMaking a backup of your torrc file, if you have problems with the new configuration, delete $torconfig and move $torconfigbackup to $torconfig"
|
||||||
cp "$torconfig" "$torconfigbackup"
|
cp "$torconfig" "$torconfigbackup"
|
||||||
echo -e "\nConfiguring the torrc file to use TOR as a transparent proxy..."
|
echo -e "\nConfiguring the torrc file to use TOR as a transparent proxy..."
|
||||||
echo -e "\n# Seting up TOR transparent proxy for tor-router\nVirtualAddrNetwork 10.192.0.0/10\nAutomapHostsOnResolve 1\nTransPort 9040\nDNSPort 5353" >> "$torconfig"
|
echo -e "\n# Seting up TOR transparent proxy for tor-router\nVirtualAddrNetwork 10.192.0.0/10\nAutomapHostsOnResolve 1\nTransPort 9040\nDNSPort 6669" >>"$torconfig"
|
||||||
echo -e "\nCreating, enabling and starting the service file tor transparent proxy..."
|
echo -e "\nCreating, enabling and starting the service file tor transparent proxy..."
|
||||||
cp "$executablerules" "/usr/bin/"
|
cp "$executablerules" "/usr/bin/"
|
||||||
chmod +x "/usr/bin/tor-router"
|
chmod +x "/usr/bin/tor-router"
|
||||||
cp "$servicefile" "/etc/systemd/system/"
|
cp "$servicefile" "/etc/systemd/system/"
|
||||||
systemctl enable tor-router.service && systemctl start tor-router.service
|
systemctl enable tor-router.service && systemctl start tor-router.service
|
||||||
echo -e "\nEnabling and restarting the TOR daemon using systemctl..."
|
echo -e "\nEnabling and restarting the TOR daemon using systemctl..."
|
||||||
systemctl enable tor && systemctl restart tor
|
if systemctl enable tor && systemctl restart tor; then
|
||||||
if [ "$?" == 0 ] ; then
|
|
||||||
echo -e "Checking if all are working..."
|
echo -e "Checking if all are working..."
|
||||||
if command -v curl >/dev/null; then
|
if command -v curl >/dev/null; then
|
||||||
curl https://check.torproject.org/ | grep "Congratulations."
|
if curl https://check.torproject.org/ | grep "Congratulations."; then
|
||||||
if [ "$?" == 0 ] ; then
|
|
||||||
echo -e "\nAll is OK, from now on all your network traffic is under the TOR Network, look for your IP addres in your browser."
|
echo -e "\nAll is OK, from now on all your network traffic is under the TOR Network, look for your IP addres in your browser."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue