DDoS Protection Guide
Information
This is a guide on how to protect your site from getting DDoS'ed by specific methods like cache busting or just the basic flood. All the methods used below are methods discovered by either me, an old friend called null or have been heavily modified and credited.Requirements
1.2.
3.
4.
Nginx Optimizations
First lets start by optimizing the Nginx config. Go ahead and go toInspection
Alright so in this guide we are going to discover the issues or methods used by a lot of DDoS Tools and or "Stressers" as some people call them. Down below you can see the first solution that works to defeat some small DDoS Tools.Rate Limiting
This example down below shows how you can limit your requests to 10 requests a minute per-ip. This method is using Cloudflare as a reverse proxy to hide my servers ip.If you need some more understanding please click here.
Cache Busting
Down below you can see quite a few examples on what ive previously described as cache busting. Now cache busting is a very weird one when it comes to protecting your website. Cache busting can use many different methods from just numbers to even some letters inside the parameters. Now ill show you how to prevent a simplistic one.Now keep in mind the methods described above for the cache busting prevention can change depending on the situation you may need. And how you serve your files.
Bogus Http Refers
This one is one of the most obvious methods to tell if its a DDos Attack or not. Most of your requests will either be refered by google, yahoo, bing or no refer at all (direct link type). But ive seen plently of requests that get sent with refers like these below.Now this will block a lot of things that refer anything above and will block some crawlers meaning your website will not appear on google's search, bings, or even yahoos. This could lead to problems if you use any of the things above for either caching, verification checking, or anything else you may need to modify it to suit your needs.
Access.log Parsing
In this section we will go over parsing the Nginx Access.log file to display how many times a ip has reached our Nginx server. Down below is a example command to parse the log file and show how many hits or requests per ip actually hit the server.Now when running the command above will print a output inside your console like this image below.
Now lets look a bit deeper into this. Lets go over to ipinfo.io and see if this if one of the ips above is a hosting provider.
Cloudflare Setup
Alright now that youve done the above things. Lets get on to the easy side of things. Now lets first navigate to cloudflare and locate the WAF area on your websites panel.Bad Actors
In this section we will go over my Bad Actors WAF rule. In this rule it does many things that will stop quite a few attacks just by itself and requires almost no modifying.Now to actually put this onto your website. Create a new rule and click Edit Expression then paste the expression from down below inside this area. Feel free to name it whatever.
ASN Blocking
Alright so say in theory you're getting a lot of requests sent to your server from a OVH vps. What you could do to prevent this entirely is setup the Cloudflares WAF to block any ip address that is inside their ASN. To do this you can copy the expression from down below.Now the only issue that will and could occur while blocking ASN's is that if you just block a ASN without checking if they are a hosting provider or not could block legitimate users from accessing your site. To check if the ip is from a hosting company I like to use ipinfo.io to check if its from a business or hosting companys.
If you want a ASN database that has quite a few malicious ips. You can click the link below to view a database "NullifiedCode" has gathered.
ASN List