Despite being set-up correctly as far as I can see, CSF is neither temporarily nor permanently blocking any repeat offender IPs recorded by ModSec in the server's main error_log
I can see lots of IP entries and rules matches in WHM > ModSecurity > Tools so I know ModSec is working. Corresponding entries are appearing in /usr/local/apache/logs/error_log like this example:
Code: Select all
[Thu Jan 23 20:58:01.284592 2025] [security2:error] [pid 467219:tid 467338] [remote 66.220.149.4:40698] [client 66.220.149.4] ModSecurity: Access denied with code 406 (phase2). Matched phrase "Meta-ExternalAgent" at REQUEST_HEADERS:User-Agent. [file "/etc/apache2/conf.d/modsec/modsec2.user.conf"] [line "15"] [id "350001"] [rev "1"] [msg "BAD BOT - Detected and Blocked."] [severity "CRITICAL"] [hostname "www.somewebsite.com"] [uri "/products/2421/"] [unique_id "Z5KtWZfRiCZ-raqc1k6EFgAAwQw"]
LF_MODSEC = "5"
LF_MODSEC_PERM = "1"
HTACCESS_LOG = "/usr/local/apache/logs/error_log"
MODSEC_LOG = "/usr/local/apache/logs/error_log"
As a last resort before posting here I have tried adding the following to regex.custom.pm:
Code: Select all
if (($config{LF_MODSEC}) and ($globlogs{MODSEC_LOG}{$lgfile}) and ($line =~ /^\[\S+ \S+ \S+ \S+ \S+\] \[(\w*)?:error\] (\[pid \d+(:tid \d+)\]) \[(client|remote) \S+:\S+\] \[client (\S+)\] ModSecurity:(( \[[^\]]+\])*)? Access denied/)) {
my $ip = $4;
$ip =~ s/^::ffff://;
if (split(/:/,$ip) == 2) {$ip =~ s/:\d+$//}
my $ruleid = "unknown";
if ($line =~ /\[id "(\d+)"\]/) {$ruleid = $1}
if (checkip(\$ip)) {return ("mod_security (id:$ruleid) triggered by","$ip","mod_security-custom","4","80,443","1")} else {return}
}