Guest User

anonymous version 1.3

a guest
Oct 17th, 2019
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.76 KB | None | 0 0
  1. #!/bin/bash
  2. # anonymous version 1.3
  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.  
  8. PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"
  9. TABLES="nat mangle raw security"; CHAINS="PREROUTING INPUT FORWARD OUTPUT POSTROUTING"
  10. 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"
  11.  
  12. [ $EUID != 0 ] && echo "please run as root" && exit 1
  13.  
  14. stop() {
  15.     /etc/init.d/tor stop
  16.     [ -f ./torrc ] && cp ./torrc /etc/tor/torrc && sleep 1 && rm ./torrc
  17.     [ -f ./iptables-rules ] && iptables-restore < ./iptables-rules && sleep 1 && rm ./iptables-rules
  18.     [ -f ./ip6tables-rules ] && ip6tables-restore < ./ip6tables-rules && sleep 1 && rm ./ip6tables-rules
  19. }
  20.  
  21. start() {
  22.     uid_owner_tor=${1:-tor}; id $uid_owner_tor || return 2
  23.  
  24.     [ ! -f ./torrc ] && cp /etc/tor/torrc ./torrc
  25.     [ ! -f ./iptables-rules ] && iptables-save > ./iptables-rules
  26.     [ ! -f ./ip6tables-rules ] && ip6tables-save > ./ip6tables-rules
  27.  
  28.     iptables -F; iptables -X; iptables -P INPUT DROP; iptables -P FORWARD DROP; iptables -P OUTPUT DROP
  29.     ip6tables -F; ip6tables -X; ip6tables -P INPUT DROP; ip6tables -P FORWARD DROP; ip6tables -P OUTPUT DROP
  30.     {
  31.         for table in $TABLES; do
  32.             iptables -t $table -F; iptables -t $table -X
  33.             ip6tables -t $table -F; ip6tables -t $table -X
  34.             for chain in $CHAINS; do
  35.                 iptables -t $table -P $chain ACCEPT
  36.                 ip6tables -t $table -P $chain ACCEPT
  37.             done
  38.         done
  39.     } 2> /dev/null
  40.  
  41.     iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
  42.     iptables -A INPUT -i lo -j ACCEPT
  43.     iptables -A INPUT -j DROP
  44.  
  45.     iptables -A FORWARD -j DROP
  46.  
  47.     iptables -A OUTPUT -p udp -d 127.0.0.1 --dport 9053 -j ACCEPT
  48.     iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 9053 -j ACCEPT
  49.  
  50.     iptables -A OUTPUT -p icmp -d 127.0.0.1 -j ACCEPT
  51.     iptables -A OUTPUT -p udp -d 127.0.0.1 --dport 9040 -j ACCEPT
  52.     iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 9040 -j ACCEPT
  53.  
  54.     iptables -A OUTPUT -p tcp --syn -m owner --uid-owner $uid_owner_tor -j ACCEPT
  55.     iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
  56.     iptables -A OUTPUT -o lo -j ACCEPT
  57.  
  58.     for iptables_special_addr in $IPTABLES_SPECIAL_ADDRS; do
  59.         iptables -A OUTPUT -d $iptables_special_addr -j DROP
  60.     done
  61.  
  62.     iptables -A OUTPUT -j DROP
  63.  
  64.     ip6tables -A INPUT -j DROP
  65.  
  66.     ip6tables -A FORWARD -j DROP
  67.  
  68.     ip6tables -A OUTPUT -j DROP
  69.  
  70.     iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-port 9053
  71.     iptables -t nat -A OUTPUT -p tcp --dport 53 -j REDIRECT --to-port 9053
  72.     iptables -t nat -A OUTPUT -p udp -d 10.192.0.0/10 -j REDIRECT --to-port 9040
  73.     iptables -t nat -A OUTPUT -p tcp -d 10.192.0.0/10 -j REDIRECT --to-port 9040
  74.  
  75.     iptables -t nat -A OUTPUT -m owner --uid-owner $uid_owner_tor -j RETURN
  76.     iptables -t nat -A OUTPUT -o lo -j RETURN
  77.  
  78.     for iptables_special_addr in $IPTABLES_SPECIAL_ADDRS; do
  79.         iptables -t nat -A OUTPUT -d $iptables_special_addr -j RETURN
  80.     done
  81.  
  82.     iptables -t nat -A OUTPUT -p icmp -j REDIRECT --to-port 9040
  83.     iptables -t nat -A OUTPUT -p udp -j REDIRECT --to-port 9040
  84.     iptables -t nat -A OUTPUT -p tcp -j REDIRECT --to-port 9040
  85.  
  86.     {
  87.         echo "DNSPort 127.0.0.1:9053"
  88.         echo "AutomapHostsOnResolve 1"
  89.         echo "AutomapHostsSuffixes .onion"
  90.         echo
  91.         echo "TransPort 127.0.0.1:9040"
  92.         echo "VirtualAddrNetwork 10.192.0.0/10"
  93.         echo
  94.         echo "User $uid_owner_tor"
  95.         echo "PIDFile /var/run/tor/tor.pid"
  96.         echo "DataDirectory /var/lib/tor/data/"
  97.     } > /etc/tor/torrc
  98.     /etc/init.d/tor restart && echo "tcp: ok, udp: ok, icmp: ok, webrtc: ng"
  99. }
  100.  
  101. case $1 in
  102.     stop)
  103.         stop
  104.     ;;
  105.     start)
  106.         start $2
  107.     ;;
  108.     *)
  109.         echo "$0 stop"
  110.         echo "$0 start [debian-]tor"
  111.     ;;
  112. esac
Advertisement
Add Comment
Please, Sign In to add comment