How to make the perfect TOR VM in VirtualBox
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rules.v4 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. *nat
  2. :PREROUTING ACCEPT [0:0]
  3. :POSTROUTING ACCEPT [0:0]
  4. :OUTPUT ACCEPT [0:0]
  5. # Redirect any tcp that is not:
  6. # - tor client itself
  7. # - localhost traffic
  8. # - redsocks traffic to tor socks
  9. -A OUTPUT -m owner --uid-owner debian-tor -j RETURN
  10. -A OUTPUT -d 127.0.0.0/8 -j RETURN
  11. -A OUTPUT -m owner --uid-owner redsocks -p tcp -m tcp --dport 9040 -j RETURN
  12. -A OUTPUT ! -p tcp -j RETURN
  13. # redirect
  14. -A OUTPUT -p tcp -j MARK --set-mark 0x888
  15. -A OUTPUT -p tcp -j REDIRECT --to-port 9040
  16. COMMIT
  17. *filter
  18. :INPUT ACCEPT [0:0]
  19. :FORWARD ACCEPT [0:0]
  20. :OUTPUT ACCEPT [0:0]
  21. # allow inbound established or related traffic
  22. -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT
  23. -A INPUT -p udp -m state --state ESTABLISHED,RELATED -j ACCEPT
  24. # allow any traffic on loopback
  25. -A INPUT -i lo -j ACCEPT
  26. # log and drop anything else
  27. -A INPUT -j LOG --log-prefix "INPUT-DROP: "
  28. -A INPUT -j DROP
  29. -A FORWARD -j DROP
  30. # mark 0x127 - permitted local traffic
  31. # mark 0x666 - denied traffic
  32. # mark 0x777 - permitted traffic outside TOR (TOR itself)
  33. # mark 0x888 - permitted TCP traffic inside TOR (over redsocks)
  34. # mark 0x127 traffic to lo or localhost ip range
  35. -A OUTPUT -m mark --mark 0x0 -o lo -j MARK --set-mark 0x127
  36. -A OUTPUT -m mark --mark 0x0 -d 127.0.0.0/8 -j MARK --set-mark 0x127
  37. # mark DHCP
  38. -A OUTPUT -m mark --mark 0x0 -m owner --uid-owner root -p udp -m udp --sport 68 --dport 67 -d 255.255.255.255 -j MARK --set-mark 0x777
  39. -A OUTPUT -m mark --mark 0x0 -m owner --uid-owner root -p udp -m udp --sport 68 --dport 67 -d 10.0.0.0/8 -j MARK --set-mark 0x777
  40. -A OUTPUT -m mark --mark 0x0 -m owner --uid-owner root -p udp -m udp --sport 68 --dport 67 -d 192.168.0.0/16 -j MARK --set-mark 0x777
  41. -A OUTPUT -m mark --mark 0x0 -m owner --uid-owner root -p udp -m udp --sport 68 --dport 67 -d 172.16.0.0/12 -j MARK --set-mark 0x777
  42. # mark tor client traffic
  43. -A OUTPUT -m mark --mark 0x0 -m owner --uid-owner debian-tor -j MARK --set-mark 0x777
  44. # any other udp will be dropped
  45. -A OUTPUT -m mark --mark 0x0 -p udp -j MARK --set-mark 0x666
  46. # any other tcp will be redsock'ed
  47. -A OUTPUT -m mark --mark 0x0 -p tcp -j MARK --set-mark 0x888
  48. #-A OUTPUT -m mark --mark 0x666 -j LOG --log-prefix "0x666: "
  49. -A OUTPUT -m mark --mark 0x666 -j DROP
  50. #-A OUTPUT -m mark --mark 0x777 -j LOG --log-prefix "0x777: "
  51. -A OUTPUT -m mark --mark 0x777 -j ACCEPT
  52. #-A OUTPUT -m mark --mark 0x888 -j LOG --log-prefix "0x888: "
  53. -A OUTPUT -m mark --mark 0x888 -j ACCEPT
  54. #-A OUTPUT -m mark --mark 0x127 -j LOG --log-prefix "0x127: "
  55. -A OUTPUT -m mark --mark 0x127 -j ACCEPT
  56. -A OUTPUT -j LOG --log-prefix "OUTPUT-DROP: "
  57. -A OUTPUT -j DROP
  58. COMMIT