From b8344fc62e4dd9221ab0bdffecd101aef05f464e Mon Sep 17 00:00:00 2001 From: Edu4rdSHL Date: Fri, 1 Jun 2018 04:02:58 -0500 Subject: [PATCH] Files uploaded --- files/tor-router | 22 +++++++++++++++++ files/tor-router.service | 13 ++++++++++ install.sh | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100755 files/tor-router create mode 100644 files/tor-router.service create mode 100755 install.sh diff --git a/files/tor-router b/files/tor-router new file mode 100755 index 0000000..7fc6a11 --- /dev/null +++ b/files/tor-router @@ -0,0 +1,22 @@ +#!/bin/bash +# 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" +# the UID Tor runs as, change this accordingly for your OS +TOR_UID="43" +# Tor's TransPort +TRANS_PORT="9040" +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 +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 -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 REJECT diff --git a/files/tor-router.service b/files/tor-router.service new file mode 100644 index 0000000..8491889 --- /dev/null +++ b/files/tor-router.service @@ -0,0 +1,13 @@ +[Unit] + Description=Start rules for transparent tor proxy + After=network-online.target + +[Service] + Type=simple + ExecStart=/usr/bin/tor-router + TimeoutStopSec=180 + KillMode=process + KillSignal=SIGINT + +[Install] + WantedBy=multi-user.target diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..3b1aa1a --- /dev/null +++ b/install.sh @@ -0,0 +1,52 @@ +#!/usr/bin/bash +# Script that automate the procces for setting up TOR as a tranparent proxy +# Autor: Edu4rdSHL @edu4rdshl + +#Defining variables +istor="/usr/bin/tor" +torconfig="/etc/tor/torrc" +torconfigbackup="/etc/tor/torrc.backup" +issystemd="/usr/bin/systemctl" +executablerules="./files/tor-router" +servicefile="./files/tor-router.service" +iscurl="/usr/bin/curl" + +#Check if the current user have root privileges +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 [ -f "$istor" ] && [ -f "$torconfig" ] && [ -f "$issystemd" ] ; then + echo -e "\nAll fundamentals tools are installed, proceding..." + echo -e "\nPLEASE, RUN IT SCRIPT ONLY A TIME, IF YOU RUN IT TWO OR MORE TIMES WILL CAUSE ISSUES WITH YOUR $torconfig FILE!" + 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 for transparent proxy\nVirtualAddrNetwork 10.192.0.0/10\nAutomapHostsOnResolve 1\nTransPort 9040\nDNSPort 5353" >> "$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 + echo -e "Checking if all are working..." + if [ -f "$iscurl" ] ; then + curl https://check.torproject.org/ | grep "Congratulations." + 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." + exit + fi + else + echo -e "\nYou haven't curl installed, try opening https://check.torproject.org/ in your browser and look for 'Congratulations.'" + fi + else + echo -e "\nAn error as ocurrer, please open a issue in https://github.com/Edu4rdSHL/tor-router/issues including log info and your Linux distribution." + fi +else + echo -e "Systemd or TOR are not installed, the script dont work." + exit +fi