Guest User

core-v2

a guest
Sep 27th, 2024
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.10 KB | None | 0 0
  1. #!/bin/sh -eu
  2.  
  3. # core v2
  4. # The Unlicense
  5.  
  6. type tor || exit 1
  7. [ $(id -u) -ne 0 ] && echo 'run as root !' && exit 2
  8.  
  9. PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
  10. RESERVED_IP='255.255.255.255/32 240.0.0.0/4 233.252.0.0/24 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. # ---
  13.  
  14. iptables -t nat -F; iptables -t nat -X; iptables -t nat -Z
  15.  
  16. iptables -t nat -A OUTPUT -p udp --dport 53 -j REDIRECT --to-ports 9053
  17. iptables -t nat -A OUTPUT -p tcp -d 10.192.0.0/10 --syn -j REDIRECT --to-ports 9040
  18.  
  19. iptables -t nat -A OUTPUT -m owner --uid-owner debian-tor -j RETURN
  20. iptables -t nat -A OUTPUT -o lo -j RETURN
  21.  
  22. for reserved_ip in $RESERVED_IP; do
  23.   iptables -t nat -A OUTPUT -d $reserved_ip -j RETURN
  24. done
  25.  
  26. iptables -t nat -A OUTPUT -p tcp --syn -j REDIRECT --to-ports 9040
  27.  
  28. iptables -t nat -nvL
  29.  
  30. # ---
  31.  
  32. iptables -F; iptables -X; iptables -Z
  33.  
  34. iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
  35. iptables -A INPUT -i lo -j ACCEPT
  36. iptables -A INPUT -j DROP
  37. iptables -P INPUT DROP
  38.  
  39. # ---
  40.  
  41. iptables -A FORWARD -j DROP
  42. iptables -P FORWARD DROP
  43.  
  44. # ---
  45.  
  46. iptables -A OUTPUT -m state --state INVALID -j DROP
  47. iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
  48.  
  49. iptables -A OUTPUT -p udp -d 127.0.0.1 --dport 9053 -j ACCEPT
  50. iptables -A OUTPUT -p tcp -d 127.0.0.1 --dport 9040 --syn -j ACCEPT
  51.  
  52. iptables -A OUTPUT -p tcp -m owner --uid-owner debian-tor -m state --state NEW --syn -j ACCEPT
  53. iptables -A OUTPUT -d 127.0.0.1 -o lo -j ACCEPT
  54.  
  55. for reserved_ip in $RESERVED_IP; do
  56.   iptables -A OUTPUT -d $reserved_ip -j DROP
  57. done
  58.  
  59. iptables -A OUTPUT -j DROP
  60. iptables -P OUTPUT DROP
  61.  
  62. # ---
  63.  
  64. iptables -nvL
  65.  
  66. # ---
  67.  
  68. [ ! -e /etc/tor/torrc.bak ] && cp -v /etc/tor/torrc /etc/tor/torrc.bak
  69.  
  70. {
  71.   echo DNSPort 127.0.0.1:9053
  72.   echo AutomapHostsOnResolve 1
  73.   echo AutomapHostsSuffixes .onion
  74.   echo
  75.   echo TransPort 127.0.0.1:9040
  76.   echo VirtualAddrNetwork 10.192.0.0/10
  77. } > /etc/tor/torrc; cat /etc/tor/torrc; /etc/init.d/tor restart
Add Comment
Please, Sign In to add comment