Advertisement
BaSs_HaXoR

How to block Tor exit nodes from accessing your website

Jul 31st, 2016
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. //SRC: http://mikhailian.mova.org/node/194
  2.  
  3. Internet trolls are using Tor nowadays to avoid bans by IP. However, banning Tor exit nodes is just slightly more complex. The Tor Project provides a regularly updated list of exit nodes that can access your IP here:
  4. (https://check.torproject.org/cgi-bin/TorBulkExitList.py).
  5.  
  6. As there may be many hundreds or even thousands of nodes, adding them to iptables can hurt your server's network performance. Enter ipset(http://ipset.netfilter.org/), a user-space hash table for iptables:
  7.  
  8. x----x----x----x_____________________________________x----x_____________________________________x----x----x----x
  9. # create a new set for individual IP addresses
  10. ipset -N tor iphash
  11. # get a list of Tor exit nodes that can access $YOUR_IP, skip the comments and read line by line
  12. wget -q https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$YOUR_IP -O -|sed '/^#/d' |while read IP
  13. do
  14. # add each IP address to the new set, silencing the warnings for IPs that have already been added
  15. ipset -q -A tor $IP
  16. done
  17. # filter our new set in iptables
  18. iptables -A INPUT -m set --match-set tor src -j DROP
  19. x----x----x----x_____________________________________x----x_____________________________________x----x----x----x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement