Skip to content

Commit

Permalink
Update script.
Browse files Browse the repository at this point in the history
Fix #11
  • Loading branch information
Edu4rdSHL committed Jan 18, 2024
1 parent 290d0b1 commit 5b79c1c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
17 changes: 10 additions & 7 deletions files/tor-router
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ start)
echo "$RULES exists. Either delete it, or stop tor-router first."
exit 1
else
iptables-save >$RULES
# Executable file to create rules for transparent proxy
# 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.
if command -v pacman >/dev/null; then
TOR_UID=$(id -u tor)
Expand All @@ -37,41 +36,45 @@ start)
echo "You need to install the iptables package."
exit 1
else
# Only save the rules when we are sure that everything is working
iptables-save >$RULES

iptables -F
iptables -t nat -F
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 5353
iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 6669

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
done

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

for NET in $NON_TOR 127.0.0.0/8; do
iptables -A OUTPUT -d "$NET" -j ACCEPT
done

iptables -A OUTPUT -m owner --uid-owner "$TOR_UID" -j ACCEPT
iptables -A OUTPUT -j ACCEPT
fi
fi
;;

stop)
if test -f "$RULES"; then
echo "Restoring previous rules from $RULES"
iptables -t nat -F
iptables -F
iptables-restore <"$RULES"
rm "$RULES"
else
echo "$RULES does not exist. Not doing anything."
exit
fi
;;

restart)
stop
sleep 2
sleep 1
start
;;
*)
Expand Down
22 changes: 10 additions & 12 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# Script that automate the procces for setting up TOR as a tranparent proxy
# Autor: Edu4rdSHL @edu4rdshl

Expand All @@ -9,33 +9,31 @@ executablerules="$PWD/files/tor-router"
servicefile="$PWD/files/tor-router.service"

#Check if the current user have root privileges
if [ "$UID" -ne "0" ] ; then
echo -e "\nYou need root permisions to run it script."
exit
if [ "$UID" -ne "0" ]; then
echo -e "\nYou need root permisions to run it script."
exit
fi

echo -e "Checking if TOR and Systemd are installed..."
if command -v tor >/dev/null && command -v systemctl > /dev/null ; then
if grep -iq "# Seting up TOR transparent proxy for tor-router" "$torconfig" ; then
if command -v tor >/dev/null && command -v systemctl >/dev/null; then
if grep -iq "# Seting up TOR transparent proxy for tor-router" "$torconfig"; then
echo -e "\ntor-router is already configured in $torconfig"
else
echo -e "\nAll fundamentals tools are installed, proceding..."
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"
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..."
cp "$executablerules" "/usr/bin/"
chmod +x "/usr/bin/tor-router"
cp "$servicefile" "/etc/systemd/system/"
systemctl enable tor-router.service && systemctl start tor-router.service
echo -e "\nEnabling and restarting the TOR daemon using systemctl..."
systemctl enable tor && systemctl restart tor
if [ "$?" == 0 ] ; then
if systemctl enable tor && systemctl restart tor; then
echo -e "Checking if all are working..."
if command -v curl >/dev/null ; then
curl https://check.torproject.org/ | grep "Congratulations."
if [ "$?" == 0 ] ; then
if command -v curl >/dev/null; then
if curl https://check.torproject.org/ | grep "Congratulations."; 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."
exit
fi
Expand Down

0 comments on commit 5b79c1c

Please sign in to comment.