We're using mod_security and we have currently issues with some bots.
I would like to block IP Address that visited 404 pages more than 10 times in a minute.
How can this be done? How can I poll the 404 return codes?
How can I count the error 404 return codes in phase 3?
RESPONSE_STATUS may not work as expected in embedded mode, as Apache sometimes handles certain requests differently, and without invoking ModSecurity (all other modules).
How can I get the RESPONSE_STATUS every time for sure? phase 5?
Mod_security should already come with some scripts, provided by the OWASP project, which block robots. Have you checked them out? You will have to enable modsecurity_crs_35_bad_robots.conf. You can download the file from the OWASP project site:
https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project
Instructions can be found there as well.
From README:
The hint to the core rule set is good, but the actual rule you should use is
This rule is especially for your case: protect certain url from being brute forced and block the IP that initiates this brute force attack. You can configure this rule in the setup file
In this setup file modify the variable
tx.brute_force_protected_urls
in rule 900014 with the urls you want to protect:The variable
tx.brute_force_burst_time_slice
specifies the amount of time in seconds within this a certain threshold has to be exceeded. As I understand your question right, use 60. The variabletx.brute_force_block_timeout
defines the time the IP of the brute forcer is blocked. The variabletx.brute_force_counter_threshold
is a bit tricky. It defines how often you can access an url before you get blocked. It is not the exact number, but with the value 2 or 3 you should get a quite good result for your block-after-10-request-rule.