In the /usr/local/csf/lib/ConfigServer/RegexMain.pm file, I see that all Apache-related regex rules, except for the LF_HTACCESS regex rule, are looking just for the "client" tag while on current cPanel servers with Apache, the IP address is often logged in the "remote" tag. For example:
Code: Select all
[Wed Oct 23 13:02:14.726330 2024] [core:info] [pid 2707490:tid 2707492] [remote 12.34.56.78:17219] AH00128: File does not exist: /home/user/public_html/test123
The regex for LF_APACHE_404 is also looking for the wrong log level. Such errors are logged with the "info" level and not the "error" level.
Our solution was to correct the respective REGEX rules and build custom rules in regex.custom.pm, as follows:
Code: Select all
# BEGIN - Custom REGEX Rules
# mod_security v2 (Apache)
if (($config{LF_MODSEC}) and ($globlogs{MODSEC_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?error\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\]( \[client \S+\])? (\w+: )?ModSecurity:(( \[[^]]+\])*)? Access denied/)) {
my $ip = $5;
my $domain = "";
if ($line =~ /\] \[hostname "([^\"]+)"\] \[/) {$domain = $1}
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
my $ruleid = "unknown";
if ($line =~ /\[id "(\d+)"\]/) {$ruleid = $1}
if (checkip(\$ip)) {return ("mod_security (id:$ruleid) triggered by",$ip,"mod_security2",$config{LF_MODSEC},"80,443",$config{LF_MODSEC_PERM},"1");} else {return}
}
# Apache 404 errors
if (($config{LF_APACHE_404}) and ($globlogs{HTACCESS_LOG}{$lgfile}) and ($line =~ /^\[\S+\s+\S+\s+\S+\s+\S+\s+\S+\] \[(\S*:)?info\] (\[pid \d+(:tid \d+)?\] )?\[(client|remote) (\S+)\] (\w+: )?File does not exist\:/)) {
my $ip = $5;
$ip =~ s/^::ffff://;
if ($config{LF_APACHE_ERRPORT} == 2 and $ip =~ /(.*):\d+$/) {$ip = $1}
my $ruleid = "unknown";
if ($line =~ /\[id "(\d+)"\]/) {$ruleid = $1}
if (checkip(\$ip)) {return ("Excessive amount of 404 errors triggered by",$ip,"apache_404",$config{LF_APACHE_404},"80,443",$config{LF_APACHE_404_PERM},"1")} else {return}
}
# END - Custom REGEX Rules
It would be great if the ConfigServer team would review the regex rules and adapt them to the current Apache logs. This issue was noticed on an up-to-date CloudLinux 8 server with cPanel v124 and Apache 2.