Guest User

anonymous version 2.0

a guest
Oct 22nd, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.29 KB | None | 0 0
  1. #!/bin/bash
  2. # anonymous version 2.0
  3. # version 1.0: release
  4. # version 1.1: -p tcp --syn
  5. # version 1.2: sleep 1 * 3
  6. # version 1.3: export delete
  7. # version 1.4: ESTABLISHED top
  8. # version 1.5: disable-ipv6.conf
  9. # version 1.6: sleep 1 * 3 delete
  10. # version 1.7: type
  11. # version 1.8: check exit
  12. # version 1.9: check delete
  13. # version 2.0: systemctl base
  14.  
  15. PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"
  16. TABLES="nat mangle raw security"; CHAINS="PREROUTING INPUT FORWARD OUTPUT POSTROUTING"
  17. IPTABLES_SPECIAL_ADDRS="255.255.255.255 240.0.0.0/4 224.0.0.0/4 203.0.113.0/24 198.51.100.0/24 198.18.0.0/15 192.168.0.0/16 192.88.99.0/24 192.0.2.0/24 192.0.0.0/24 172.16.0.0/12 169.254.0.0/16 127.0.0.0/8 100.64.0.0/10 10.0.0.0/8 0.0.0.0/8"
  18.  
  19. type cp rm tor bash sysctl iptables ip6tables iptables-save ip6tables-save iptables-restore ip6tables-restore || exit 1
  20. [ $EUID != 0 ] && echo "please run as root" && exit 2
  21.  
  22. stop() {
  23.     [ -f ./torrc ] && cp ./torrc /etc/tor/torrc && rm ./torrc
  24.     [ -f ./iptables-rules ] && iptables-restore < ./iptables-rules && rm ./iptables-rules
  25.     [ -f ./ip6tables-rules ] && ip6tables-restore < ./ip6tables-rules && rm ./ip6tables-rules
  26.     [ -f /etc/sysctl.d/disable-ipv6.conf ] && rm /etc/sysctl.d/disable-ipv6.conf && sysctl --system; systemctl stop tor
  27. }
  28.  
  29. start() {
  30.     uid_owner_tor=${1:-tor}; id $uid_owner_tor || return 3
  31.  
  32.     [ ! -f ./torrc ] && cp /etc/tor/torrc ./torrc
  33.     [ ! -f ./iptables-rules ] && iptables-save > ./iptables-rules
  34.     [ ! -f ./ip6tables-rules ] && ip6tables-save > ./ip6tables-rules
  35.  
  36.     iptables -F; iptables -X; iptables -P INPUT DROP; iptables -P FORWARD DROP; iptables -P OUTPUT DROP
  37.     ip6tables -F; ip6tables -X; ip6tables -P INPUT DROP; ip6tables -P FORWARD DROP; ip6tables -P OUTPUT DROP
  38.     {
  39.         for table in $TABLES; do
  40.             iptables -t $table -F; iptables -t $table -X
  41.             ip6tables -t $table -F; ip6tables -t $table -X
  42.             for chain in $CHAINS; do
  43.                 iptables -t $table -P $chain ACCEPT
  44.                 ip6tables -t $table -P $chain ACCEPT
  45.             done
  46.         done
  47.     } 2> /dev/null
  48.  
  49.     iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
  50.     iptables -A INPUT -i lo -j ACCEPT
  51.     iptables -A INPUT -j DROP
  52.  
  53.     iptables -A FORWARD -j DROP
  54.  
  55.     iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
  56.  
  57.     iptables -A OUTPUT -p udp -d 127.0.0.1 --dport 9053 -j ACCEPT
  58.     iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 9053 -j ACCEPT
  59.  
  60.     iptables -A OUTPUT -p icmp -d 127.0.0.1 -j ACCEPT
  61.     iptables -A OUTPUT -p udp -d 127.0.0.1 --dport 9040 -j ACCEPT
  62.     iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 9040 -j ACCEPT
  63.  
  64.     iptables -A OUTPUT -p tcp --syn -m owner --uid-owner $uid_owner_tor -j ACCEPT
  65.     iptables -A OUTPUT -o lo -j ACCEPT
  66.  
  67.     for iptables_special_addr in $IPTABLES_SPECIAL_ADDRS; do
  68.         iptables -A OUTPUT -d $iptables_special_addr -j DROP
  69.     done
  70.  
  71.     iptables -A OUTPUT -j DROP
  72.  
  73.     ip6tables -A INPUT -j DROP
  74.  
  75.     ip6tables -A FORWARD -j DROP
  76.  
  77.     ip6tables -A OUTPUT -j DROP
  78.  
  79.     iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-port 9053
  80.     iptables -t nat -A OUTPUT -p tcp --dport 53 -j REDIRECT --to-port 9053
  81.     iptables -t nat -A OUTPUT -p udp -d 10.192.0.0/10 -j REDIRECT --to-port 9040
  82.     iptables -t nat -A OUTPUT -p tcp -d 10.192.0.0/10 -j REDIRECT --to-port 9040
  83.  
  84.     iptables -t nat -A OUTPUT -m owner --uid-owner $uid_owner_tor -j RETURN
  85.     iptables -t nat -A OUTPUT -o lo -j RETURN
  86.  
  87.     for iptables_special_addr in $IPTABLES_SPECIAL_ADDRS; do
  88.         iptables -t nat -A OUTPUT -d $iptables_special_addr -j RETURN
  89.     done
  90.  
  91.     iptables -t nat -A OUTPUT -p icmp -j REDIRECT --to-port 9040
  92.     iptables -t nat -A OUTPUT -p udp -j REDIRECT --to-port 9040
  93.     iptables -t nat -A OUTPUT -p tcp -j REDIRECT --to-port 9040
  94.  
  95.     {
  96.         echo "DNSPort 127.0.0.1:9053"
  97.         echo "AutomapHostsOnResolve 1"
  98.         echo "AutomapHostsSuffixes .onion"
  99.         echo
  100.         echo "TransPort 127.0.0.1:9040"
  101.         echo "VirtualAddrNetwork 10.192.0.0/10"
  102.         echo
  103.         echo "User $uid_owner_tor"
  104.         echo "PIDFile /var/run/tor/tor.pid"
  105.         echo "DataDirectory /var/lib/tor/data/"
  106.     } > /etc/tor/torrc
  107.     {
  108.         echo "net.ipv6.conf.all.disable_ipv6=1"
  109.         echo "net.ipv6.conf.default.disable_ipv6=1"
  110.     } > /etc/sysctl.d/disable-ipv6.conf; sysctl --system
  111.     systemctl restart tor && echo "tcp: ok, udp: ok, icmp: ok, webrtc: ng"
  112. }
  113.  
  114. case $1 in
  115.     stop)
  116.         stop
  117.     ;;
  118.     start)
  119.         start $2
  120.     ;;
  121.     *)
  122.         echo "$0 stop"
  123.         echo "$0 start [debian-]tor"
  124.     ;;
  125. esac
Add Comment
Please, Sign In to add comment