| Home | FAQ | Statistics | Various | Contact |
Sécurité : Linux : HTTP DDoS/flood attacks mitigation with ModSecurity
ModSecurity is a module most often used only for string/pattern matching. We will see that it can also do much more than that and be used, for instance, to mitigate or block HTTP floods in an even more effective manner than modules like mod_evasive.
To reject or blacklist IP's that have too many connection attempts, here are 5 actions and 1 variable needed for that purpose.
Instead of sending a HTTP error page and code (usually 403) just like does the deny action, drop is useful to save system resources and bandwidth by ignoring the request.
Remember, of course, to adapt this rule to your server (REQUEST_LINE and threshold limit).
this article deals only with HTTP D(D)oS, ie, multiple requests on one or more pages of your HTTP server. Regarding SYN flood attacks, please refer to Floodmon.
initcol:ip=%{REMOTE_ADDR}
setvar:ip.ddos=+1
deprecatevar:ip.ddos=100/10

We will use it for 'suspicious' IPs, that is those having a lot of connections but not enough to confirm that they are part of a flood, DoS or DDoS attack. This will prevent to blacklist by mistake a (nervous) user who is loading to many webpages from the website into a lot of different tabs with his browser. In our example, any single IP with more than 25 requests per 10 seconds will be dropped and, as seen with deprecatevar, its counter will be decremented by 100 units after that time, allowing this user to calm down a bit :
SecRule IP:DDOS "@gt 25" "nolog,drop"
Important :
- drop does not work with Windows versions of mod_security !
- it is better to use nolog here, otherwise every single drop action will be recorded and could flood the log files.
We can log that action without risking to flood the logs as the IP will be blocked almost right away with iptables.
SecRule IP:DDOS "@gt 50" "log,exec:/var/www/modsec2ipt.pl"
SecRule REQUEST_LINE "^GET (?:/|.+\.html|.+\.php|.+\.cgi|.+\.pl) HTTP"
Generic rule :
SecAction initcol:ip=%{REMOTE_ADDR},nolog
SecRule REQUEST_LINE "^GET (?:/|.+\.html|.+\.php|.+\.cgi|.+\.pl) HTTP" \
"nolog,setvar:ip.ddos=+1,deprecatevar:ip.ddos=100/10"
SecRule IP:DDOS "@gt 50" "log,exec:/var/www/modsec2ipt.pl"
SecRule IP:DDOS "@gt 25" "nolog,drop"
![]()