Question Modsecurity in detection mode and fail2ban jail

gabriel.mstowski

New Pleskian
Server operating system version
Ubuntu 24.04
Plesk version and microupdate number
18.0.69
Hello, has anyone figured out how to properly configure the fail2ban-modsecurity jail to work correctly with ModSecurity when it's in detection mode? Despite setting ModSecurity to detection mode, Fail2Ban is still blocking requests cause it doesn't care about if ModSec is on or in detection mode.
 
Allow me :) So, like many of us, I have multiple servers each with multiple websites. The server-wide setting for ModSecurity is On (Enabled). The server-wide setting for fail2ban is checked for Enable intrusion detection with plesk-modsecurity jail Active.

I have a website that is having trouble with some false positives. So, in Plesk, I have gone to ModSecurity in that domain's card and selected Detection Only.

However, fail2ban's default ModSecurity jail filter appears so basic that it does not distinguish between sites that are Engine-Mode: "ENABLED" or Engine-Mode: "DETECTION_ONLY".

Code:
[Definition]
failregex = ^(?:\[.*?\]\s\S*)\s<HOST>\s
ignoreregex = ^\[.*?\]\s\S*\s<HOST>\s.*\s\1

If Plesk expects that ModSecurity should work in conjunction with fail2ban and vice versa, and in the UI it gives the option to make a ModSecurity custom change per domain, then it should also provide the ability to make a custom change per domain for fail2ban (e.g. disable jails per domain). If that is not possible, then it should at the very least inform the user of such a situation and strive to improve fail2ban's supplied ModSecurity jail filter to ignore sites in Detection Only mode.

Granted, /var/log/modsec_audit.log is a rather complex logfile to analyse and regex :eek:

Unless I'm mistaken, the only workaround at present seems to be to disable in fail2ban server-wide the ModSecurity jail or ease its ban period/attempts while you learn what one or two sites is triggering false positives :(

Plesk Obsidian 18.0.79
OS: various RHEL flavours and versions.
 
then it should at the very least inform the user of such a situation

Okay, my bad, it kinda does.

Detection only
Each incoming HTTP request and the related response are checked against a set of rules. If the check succeeds, the HTTP request is passed to website content. If the check fails, the event is logged and ModSecurity performs no other actions. Other services (for example, Fail2ban) can still perform their own actions on HTTP requests that failed the check.

And thinking about it some more, one could argue there's a case for server-wide running ModSecurity in Detection Only mode in conjunction with fail2ban if you want to give the attacker fewer clues as to how quickly or often they're going to become banned. For example, when they learn how many attempts it takes to see an Apache error code, they just rotate IPs until they find the sweet spot.

On
Each incoming HTTP request and the related response are checked against a set of rules. If the check succeeds, the HTTP request is passed to website content. If the check fails, the event is logged, a notification is sent, and the HTTP response is provided with an error code.
 
Back
Top