Recipe 14-3: Blocking the Client Source Address
This recipe shows you how to use ModSecurity to blacklist the client source address.
Ingredients
- jwall tools
- ModSecurity
- @rbl operator
- setvar action
Carefully consider whether you should blacklist the source IP address of an identified attacker. The downsides of this approach involve issues of accuracy and persistence. An IP address does not uniquely equate to a particular user. If you block a client IP address, you may inadvertently also block other innocent users who happen to be using that IP address too. In addition, this type of blocking is merely a speed bump for the attacker. He can simply change the path of his attack traffic to go through another compromised site or proxy server. In addition to evasions, blocking based solely on client IP addresses may also impact non-malicious users who happen to be sharing a proxy server. This technique, however, is not totally without value, because it does potentially buy you a bit of time to regroup. You can use a number of different methods to block a specific client IP address.
IP Blacklisting in ModSecurity
The easiest method of blocking an IP address within ModSecurity is to use the OWASP ModSecurity Core Rule Set and simply set a variable within the IP-based persistent collection. The following rules in the modsecurity_crs_10_setup.conf file initiate the per-IP/User-Agent combination persistent storage using the
initcol action:
# -- [[ Global ...