In fail2ban I have a filter with three regex.
I configure them to fit three different codes.
As soon as one of them is hit, the rest are ignored.
I want all hits to count.
How can I force the others to count as well?
Use regex101.com for help. Here is a regex code in Spamassassin that looks for all 3 words. They must all be there to be matched. If one of the words is missing then the condition is not found. GL.
I’m looking for the opposite.
A filter with 3-4 different regex
When the log shows 3 lines of content that trigger regex 1, 2 and 3
Then I want to get 3 hits so that the IP address is blocked.
Agreed. Anyone not in your IP range whitelisted that posts xmprpc is banned. That’s what I do. The other tests are not required. Anyone can try to login to wp or get a 503 and it doesn’t mean anything bad. XMLRPC is a good reason to ban and then increase it with repeated attempts.
There is no ban because it triggered fake1 only one time and maxretry is three times. Your settings require 3 times within 3 minutes. You could ban after 1 try for 10 minute ban then increase the next fails to a day then month then 12 weeks, for example. They won’t come back.
I saw a similar article that gave me the confidence to use xlmrpc to ban immediately for a week. I haven’t yet investigated the increasing ban time setup.
I plan to look for blocks of IPs then ban them permanently at the router.
Thanks a lot all. @ID10T I don´t dare to do that. I think it will block almost all since I have many jails. @paulM Good suggestion. I now ban after 1 try and then increase. Works!! @stefan1959 I have disabled it in Apache. All gets 403 @Randomz I now also look for blocks of IPs that are banned for xlmrpc and ban them permanently.
Back to this original question: How to have multiple tests in f2b filter. There is a provision to do this. It uses the parameter SKIPLINES. The discussion is on github for f2b and that is the best place where the developers talk about ways to use f2b.
SKIPLINES tells F2b to find a match then skip lines and look for another match. The total maximum line to match is specified. You would write:
condition1 <SKIPLINES> condition2 <SKIPLINES>...
and the conditions must occur within the max number of lines you wish to search for. If the conditions match then F2B would trigger for that IP. I used it for spamd where a spammer connects but then doesn’t provide credentials a few lines later and disconnects.
# Fail2Ban filter unknown disconnects postfix/smtpd using multiple lines
# Catches Spamd IP and bans
[INCLUDES]
before = common.conf
[Init]
maxlines = 10
[Definition]
_daemon = postfix/smtpd
failregex = ^.*: connect from .*\[<HOST>\]<SKIPLINES>^.*: client=unknown\[<HOST>\]$
ignoreregex =^.*: connect from yourserver.net\[<HOST>\]$
You test this using the fail2ban-regex CLI on a test.log to make sure it works then implement.
Some examples of skiplines are in the discussion on github which is the best place to get help with f2b. github f2b skiplines discussion