Blocking Tor & AWS in Nginx

Don't let pesky bots and possible malicious traffic fuck your site up..

Posted by Nekunekus on 2021-09-18 15:00

A lot of malicious traffic sadly comes from AWS and Tor so I wrote a simple script to automatically block it in Nginx. While I don't like blocking Tor this is sadly needed when pedophiles don't understand they need help.

So let's begin shall we!

Make a file called with this:

wget && grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' exit-addresses > bitch && awk '{ printf "deny "; print }' bitch > bitch1 && awk '{print $0";"}' bitch1 > bitch2 && rm -rf bitch bitch1 exit-addresses && mv bitch2 tor_list.txt
wget && cat ip-ranges.json | jq --raw-output '.prefixes[] | .ip_prefix' > list.txt && awk '{ printf "deny "; print }' list.txt > list1.txt && awk '{print $0";"}' list1.txt > list2.txt && rm -rf list.txt && rm -rf list1.txt ip-ranges.json && mv list2.txt aws_list.txt
cat aws_list.txt >> tor_list.txt && mv tor_list.txt /etc/nginx/blockips.conf && service nginx reload && rm aws_list.txt

Add it to your crontab with root priviliges (sudo crontab -e) to run every 6 hours:

0 */6 * * * bash /home/whatever/

And finally include it in your nginx conf file:

include /etc/nginx/blockips.conf;

All done, I've based this on my Fuck-AWS-Tor script.