Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timing causing ban to fail? #2332

Closed
codeFarmerJ opened this issue Feb 5, 2019 · 14 comments
Closed

Timing causing ban to fail? #2332

codeFarmerJ opened this issue Feb 5, 2019 · 14 comments

Comments

@codeFarmerJ
Copy link

codeFarmerJ commented Feb 5, 2019

I've been successfully using fail2ban for years on my Debian 7 Apache server to screen out all 404's. Most commonly the block takes effect after the first 404 hit. Some are slower with multiple 404s in the first 4-6 seconds. But in the last few months, my log records 100 or more hits before the IP block takes effect. Or maybe it never takes effect? Is something holding my log file open so it can't be read? Or what is going on? TIA

I did add mod_evasive (which delays multiple hits from the same source) to my apache server and it seems to be working (except in this case). Most 404 are still being caught quickly, but a few are not and I can't figure out why.

334 lines with GET or POST - all returning 404
sample log:

103.100.60.15 - - [01/Jan/2019:05:01:43 -1000] "PROPFIND / HTTP/1.1" 200 10319 "-" "-" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:44 -1000] "GET /webdav/ HTTP/1.1" 404 488 "-" "Mozilla/5.0" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:45 -1000] "GET /help.php HTTP/1.1" 404 526 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:45 -1000] "GET /java.php HTTP/1.1" 404 525 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:45 -1000] "GET /_query.php HTTP/1.1" 404 527 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:45 -1000] "GET /test.php HTTP/1.1" 404 525 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:46 -1000] "GET /db_cts.php HTTP/1.1" 404 527 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:46 -1000] "GET /db_pma.php HTTP/1.1" 404 527 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:46 -1000] "GET /logon.php HTTP/1.1" 404 526 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36" myserver.net:80

<snip>

103.100.60.15 - - [01/Jan/2019:05:01:58 -1000] "POST /m.php?pbid=open HTTP/1.1" 404 522 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:58 -1000] "POST /db_dataml.php HTTP/1.1" 404 530 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:58 -1000] "POST /db_desql.php HTTP/1.1" 404 529 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:59 -1000] "POST /mx.php HTTP/1.1" 404 523 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:59 -1000] "POST /wshell.php HTTP/1.1" 404 527 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:59 -1000] "POST /xshell.php HTTP/1.1" 404 527 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:01:59 -1000] "POST /qq.php HTTP/1.1" 404 523 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:00 -1000] "POST /conflg.php HTTP/1.1" 404 527 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:00 -1000] "POST /conflg.php HTTP/1.1" 404 527 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:00 -1000] "POST /lindex.php HTTP/1.1" 404 527 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:00 -1000] "POST /phpstudy.php HTTP/1.1" 404 529 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:00 -1000] "POST /phpStudy.php HTTP/1.1" 404 529 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:01 -1000] "POST /weixiao.php HTTP/1.1" 404 528 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:01 -1000] "POST /feixiang.php HTTP/1.1" 404 529 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:01 -1000] "POST /ak47.php HTTP/1.1" 404 525 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:01 -1000] "POST /ak48.php HTTP/1.1" 404 525 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:01 -1000] "POST /xiao.php HTTP/1.1" 404 525 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
103.100.60.15 - - [01/Jan/2019:05:02:02 -1000] "POST /yao.php HTTP/1.1" 404 524 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
@fail2ban fail2ban deleted a comment from codeFarmerJ Feb 5, 2019
@sebres
Copy link
Contributor

sebres commented Feb 5, 2019

Neither mod_evasive tell me something, nor I understand what you trying to describe resp. what issue is exactly (e. g. which filter/jail is used and what exactly does not work).

As for the subject "Timing causing ban to fail", you should read wiki :: How fail2ban works where it is pretty good described.

Shortly, the combination maxretry/findtime decides who and when will be banned.
Proper filter (or failregex) is responsible for failure recognition.

Closed until more info provided.

@sebres sebres closed this as completed Feb 5, 2019
@sebres sebres added the moreinfo label Feb 5, 2019
@evilplan
Copy link

evilplan commented Feb 5, 2019

I completely understand what he's trying to report to you.

I have experienced this issue dozens of times, but I do not know how to explain it properly. That is why I understand it:

Fail2Ban is working. It is banning IPs. But sometimes, items are added to log files faster than Fail2Ban can process them.

Usually fail2an takes action after 'maxretry' times, but sometimes the IP address is attacking you so often, Fail2Ban never gets time to actually take any action.

It can happen with any jail and any filter.

If I have maxretry=1 then I will expect my log to show something like:
2019-02-05 10:32:38,876 fail2ban.filter [4547]: INFO [crawlers] Found 34.73.237.101 - 2019-02-05 10:32:38
2019-02-05 10:32:39,494 fail2ban.actions [4547]: NOTICE [crawlers] Ban 34.73.237.101

I do not know how Fail2Ban performs its magic. But I think probably something like this happens:

  1. The monitoring/notifying system wakes up at 10:32:38,876 and says "oh hello, we've got activity in crawler.log - please fire up the filter system to check".
  2. the filter checks and sees that the regex has matched
  3. the rest of the system does its work, the IP is banned etc.

But sometimes something odd happens 🔽. I'm making up the times; they are there as an example. The key thing to understand is that the log entries are being added in real time - my system clock shows that it's 10:32:39. This is not a set of log entries that happened earlier.

2019-02-05 10:32:38,935 fail2ban.filter [4547]: INFO [crawlers] Found 34.73.237.101 - 2019-02-05 10:32:39
2019-02-05 10:32:39,216 fail2ban.filter [4547]: INFO [crawlers] Found 34.73.237.101 - 2019-02-05 10:32:39
2019-02-05 10:32:39,645 fail2ban.filter [4547]: INFO [crawlers] Found 34.73.237.101 - 2019-02-05 10:32:39
2019-02-05 10:32:39,911 fail2ban.filter [4547]: INFO [crawlers] Found 34.73.237.101 - 2019-02-05 10:32:39
2019-02-05 10:32:39,645 fail2ban.filter [4547]: INFO [crawlers] Found 34.73.237.101 - 2019-02-05 10:32:39
2019-02-05 10:32:40,221 fail2ban.filter [4547]: INFO [crawlers] Found 34.73.237.101 - 2019-02-05 10:32:40
2019-02-05 10:32:40,620 fail2ban.filter [4547]: INFO [crawlers] Found 34.73.237.101 - 2019-02-05 10:32:40
~~maybe 20, 30, 40 more log entries, happening in real time
2019-02-05 10:32:40,881 fail2ban.actions [4547]: NOTICE [crawlers] Ban 34.73.237.101

I think I know the reason for this.

In the example above, the notifying system says "hey please look at crawlers.log"

So, because this single IP address is generating a log item several times a second, Fail2Ban thinks it is still checking through the log file at the request of the original notifying task.

At 10:32:39, the notifier said "crawlers.log has been modified - please check it"

While Fail2Ban is noting down these changes, further entries are being added. Fail2Ban thinks these additions are from the original task that ran - the "crawlers.log has been modified" notifier.

Fail2Ban continues to add these to the queue of actions to take. Even though maxretry=1 for this jail, the reason this IP address is not banned is because Fail2Ban isn't even reaching the "action" stage. It still keeps monitoring the log file because it thinks these are part of the initial task that ran at 10:32:39

The system is working exactly as it was designed to work. But sometimes there is this odd condition where a repeated attack doesn't lead to an immediate ban, because Fail2Ban never reaches the end of the "monitor the current changes" task.

I've never reported this because - as I hope is clear now - it is hard to even explain the problem, let alone give you steps you can use to reproduce it. I don't think it's a bug - I think it's a design choice :-)

I hope this makes sense. As soon as I read the email I know exactly what he was talking about. It's a real issue :-)

In case you're wondering why have not attached any real logs of this issue, it's because I stopped looking for them because I don't know how to describe the issue :-)

@sebres
Copy link
Contributor

sebres commented Feb 5, 2019

So your assumption is fail2ban filter finds failures "endless" and therefore never gets time to notify fail-manager (and hereafter ban-manager) about new tickets (and bans).
Note that both are two different workers (threads), so only one bottleneck they have together are the queues.

If so, then it should be obsolete in my opinion (I made several preventive measures to avoid this).

If exactly this situation is still occurred with 0.10 or 0.11, please provide which backend is used.
In my opinion pyinotify, polling and systemd should be not affected anymore (I'm not sure about gamin, but it is anyway the slowest backend at all and should be avoided).

BTW, I don't think @codeFarmerJ mean exactly this, because in the log excerpt some intervals between failures are second long... (with other words 5-6 failures per second is nothing for jails normally, at least for fail2ban >= v.0.10).
So I still think, it is either the wrong filter/failregex or too large maxretry resp. too short findtime.

Furthermore note that if you have some unsafe failregex (e. g. containing something like non-greedy catch-all's like .*?), that could indeed freeze on some long lines (see #1173) due to regex-related issues like multiple look-behind of some large branches in the RE-engine.

The solution here may be:

  • rewrite failregex to work more effective;
  • pre-filter log-output (e. g. using prefregex in order to shorten the log-messages);
  • generate fewer parasite traffic into log-output - fewer unneeded details and/or only failure lines, e. g. in nginx it would be a location for 404 with special log in minimalist format).

@sebres
Copy link
Contributor

sebres commented Feb 5, 2019

@codeFarmerJ :

  1. do we understand correctly:
    • the ban occurs, just it is delayed? or it does not affect some IPs at all?
    • the messages (from your excerpt) will be found with your filter (what fail2ban-regex says about this)?
  2. which fail2ban version do you use?
  3. which backend (if it is auto, what do you see by this jail in fail2ban.log if it goes start)?
  4. can you provide the filter/regex that is used here?

@evilplan
Copy link

evilplan commented Feb 5, 2019

Thank you. I am away from home for a few days so I need some time to gather the information you've asked for when I get back.

If I have misunderstood the original issue, do you want me to open a new issue once I am back home and have the information?

@sebres
Copy link
Contributor

sebres commented Feb 5, 2019

Sure.
(neither we are in the mode of "count each open issue", nor I need to report for someone the relation between closed/open issues, just I close some of that sometimes to make it easier to me to find important open things later and to stop flooding by some invalid/not-precise/irrelevant issues)

@codeFarmerJ
Copy link
Author

codeFarmerJ commented Feb 6, 2019

I probably should not have said the ban fails. In a few cases the ban is so slow as to be ineffective. I have no evidence that fail2ban is not operating properly. 95% of the time it executes the ban in a timely manner. But there are now a few cases where a huge number of hits get through to my Apache server. I assume this blast must be doing something different, but what? Could it somehow be slowing my machine so that the log file cannot be read timely? This appears to me be a scripted attack which I began experiencing near the end of Oct 2018 (from looking at my log file history). I can provide a large number of log files, but doubt they will add clarity. I'm including my filter and jail which I've used for many years, so doubt that will explain this new challenge.

I've noticed that many of these attacks begin with a valid request which returns 200:

103.212.33.27 - - [02/Jan/2019:02:52:59 -1000] "PROPFIND / HTTP/1.1" 200 10022 "-" "-"

before the ensuing 100-400 invalid 404 requests. Is this a clue?

Filter:

[Definition]
failregex = ^<HOST> -.*GET.* 40[0-9] . 
            ^<HOST> -.*POST.* 40[0-9] .
	    ^<HOST> -.*HEAD.* 40[0-9] . 

ignoreregex = ^.*favicon\.ico .

Local Jail section:

[apache-404-vhosts]
enabled  = true
port     = http,https
filter   = apache-404
logpath  = /var/log/apache2/other_vhosts_access.log
maxretry = 1

@codeFarmerJ
Copy link
Author

codeFarmerJ commented Feb 6, 2019

In the last week I have had 56 successful bans, and 1 that was not.
Here it is. I've altered only my server name.
srvLog.txt

@codeFarmerJ
Copy link
Author

codeFarmerJ commented Feb 6, 2019

Neither mod_evasive tell me something...

I was assuming the attack was successful because it was so fast. In my attempt to slow it down I configured Apache mod-evasive, which introduces a pause from too many hits too quickly. I believe this is working correctly because I often experience it myself. However it has not stopped the attacks.

@sebres
Copy link
Contributor

sebres commented Feb 6, 2019

Still again which fail2ban version it is?
If it is 0.9 simply switch to 0.10.

I configured Apache mod-evasive, which introduces a pause from too many hits too quickly.

So you has intentionally slowing down the logging of such requests too. What do you expect then?
Does your apache write now some (previously registered) entries after ban for IP is occurred?
In this case I don't know what we could do for you.

Now to your filter... As I wrote above some regex (developed by someone from the internet, but some of stock-fail2ban too) are worse and extremely vulnerable (at least as regards the performance). And it is definitely the case here too.
So please rewrite it to something like this:

failregex = ^<HOST>\s+\S+\s+\S+\s+(?:\[\])?\s*"(?:GET|POST|HEAD)\s\S+\s[A-Z]+/\d+.\d+" 40\d
# _ignore_uri = favicon\.ico|robot\.txt
_ignore_uri = favicon\.ico
ignoreregex = ^<HOST>\s+\S+\s+\S+\s+(?:\[\])?\s*"[A-Z]+\s\S*/(?:%(_ignore_url)s)\s[A-Z]+/\d+.\d+"

Please note that fail2ban is as fast as your filter is, so each additional possibly not optimal regex (or ignore) will slow it down. Especially if you have large parasite log "traffic" that does not match (e. g. all 200 requests etc), because fail2ban tries each failregex for each line.
In this case pre-filtering or writing of 40x requests into separate log (to observe it in fail2ban) may help (and will extremely speed up the failure recognition).

Also note that fail2ban (alone) is not really a tool to protect you from DDOS-similar attacks (especially if it is wrong configured). You can use it in combination with other prevention tools, but sometimes also special measures are necessary (like special filter, shorting of log-messages/format with special logger, progressive rate limiting, etc).

@codeFarmerJ
Copy link
Author

Sergey - First thank you for taking the time and effort for trying to understand and help me resolve this problem. I do appreciated it. Also I realize that I have used fail2ban for many years and not contributed. I have just now corrected that situation with a donation.

I found that I had been using ver. 0.8.6. It had worked well for me for so long, I didn't realize how old it was. I have now updated to the stable ver. 0.9.4 Maybe this alone will fix my problem?

My logic was that if the hits to my server were coming too fast, maybe fail2ban could not keep up with them. So, yes, my goal was to slow down the rapid fire hits so that fail2ban could have time to read the logs. Why is this poor reasoning?

I will update my filter as you recommend. Can you help understand why your regex is superior? Mine is certainly easier to read . What would I use to "pre-filter" my log? I'm not sure I know how to do this.

I don't think I have experienced a DDoS attack, but would guess that the request hits are all very similar, which is not my case. I think my logs show more of an attempt to probe my server for weakness.

Again thank you for your time & help.

@sebres
Copy link
Contributor

sebres commented Feb 8, 2019

I have just now corrected that situation with a donation.

Thank you! (it is not under my control, so I cannot see this), but it is really exemplary action.

I have now updated to the stable ver. 0.9.4 Maybe this alone will fix my problem?

I don't think so (this version is also too old). Fail2ban >= 0.10 would be your friend (or still better 0.11 with progressive ban time increment) in order to solve all the performance issues.

my goal was to slow down the rapid fire hits so that fail2ban could have time to read the logs.
Why is this poor reasoning?

It is not at all. Just because I don't know how exactly it works, I can imagine many situations caused with delayed logging, for example:

Click here for details
BeforeAfter
AttemptLogActionAttemptLogAction
1404 for 1Found 11404 for 1Found
2404 for 2Found 22404 for 2Found
3404 for 3Found 33- (delayed)-
4404 for 4Found 44- (delayed)-
5404 for 5Found 5, Ban5- (delayed)-
...
-404 for 3Found 3
6404 for 4Found 4
7404 for 5Found 5, No ban*
8404 for 6Found 6
9404 for 7Found 7, Ban**
...
-404 for 8Found 8, Already banned
-404 for 8Found 9, Already banned

* no ban, because time between Found 1 and Found 5 exceeds findtime.
** ban, because maxretry reached now in findtime
Note, that if it goes banned earlier, some entries (like attempts 8 and 9) could be logged anyway hereafter (just because such attempts are really occurred, just "delayed" in mod).

As already said I don't know it, so...


So I just intended recommend you to check this is really affected and to correct/change it in the configuration - for example if mod_evasive could write separate log-file which summarized all intruder attempts - this log (instead of the access-log) would be a right candidate for monitoring via fail2ban.
Or increase findtime (decrease maxretry) or even something else...

Can you help understand why your regex is superior?

Firstly think about the log you observing is an access log, so it has many "parasite" log-messages in sense of fail2ban (all success entries with 20x-30x codes for example).

  1. It is exactly 1 regex instead of 3 in your case, where for each not matched (20x - 30x) log entry will be searched 3 times, before it is understood as good (not recognized as failure).
  2. Your each regex (e. g. ^<HOST> -.*GET.* 40[0-9] .) is many times slower, because of both catch-all's .* each know branch (here GET or 40 with 10 "sub-branches" 0..9) inside regex will be scanned inside complete string. Furthermore because this regex is basically greedy, it will prefer longest string so your catch-all's allow the RE-engine scan this string to the end, this this example:
$ msg='IP - this is example string 1 with GET and 401 but somewhere at end it has still one 409 so it will be found';
$ python -c "import re; print(re.search('^\w+ -.*GET.* (40[0-9]) .', '$msg').groups())"
('409',)
  1. Because the catch-all's covering everything, your RE scan each log-message (no matter it matches or not) up to the end, where my RE stops already on first chars, that are not matched.
    And this exactly 3 times in your case.
  2. Because of too many other things I cannot explain you, without knowledge of your skill.

Mine is certainly easier to read.

All that glitters is not gold, at least not in case of regex. RE-engine is finite automaton and doing basically not "just take a look for some string" (also if it easy and you could read a "simple" RE this way).

What would I use to "pre-filter" my log?

  1. As already said, in nginx I would create a special location that logs 40x-requests into a separate log-file/journal. See for example this botsearch filter for nginx #1962 (comment).
    I don't use apache so I cannot help you here.
  2. Minimize "parasite" logging by monitoring, so any way to split 20x-30x and 40x requests in two different logs would help too.
  3. If you can change log-format, you could move all need data to begin of log message (so your RE would differentiate between failure and legitimate attempt much faster) as well as you could shorten it a bit. For example if you rewrite it as following log-format, your RE would have all needed info (up to 404) without necessity to bypass user foreign data like URL, which could be long:
- 103.100.60.15 - - [01/Jan/2019:05:01:58 -1000] "POST /m.php?pbid=open HTTP/1.1" 404 522 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" myserver.net:80
+ [01/Jan/2019:05:01:58 -1000] 103.100.60.15 404 "POST /m.php?pbid=open HTTP/1.1" 522
  1. for fail2ban >= 0.10 you can use parameter prefregex in filter to do pre-filtering (usable for multiple failregex that could be then shorten to scan only variate part of messages).

Anyway for multiple failregex is also valid #2170 (comment) (as short summary for best practice).
We have to take it in our wiki (just no time to do it).

@equipematou
Copy link

Rather than create a new thread, I thought to continue this one so the discussion is all in one place. I have been seeing exactly this problem for some time.

The fail2ban version is 11.2, on a Centos 7 system. The block method is firewalld, which is working; I have verified that many times.

fail2ban-0.11.2-3.el7.noarch

As an example, yesterday there were a series of 17 accesses to varients of the following URL that took place over 17 seconds, all from the same ip, between 23:39:40 and 23:39:57. The variants were different paths between /path/.../wp-includes/.

GET /path/wp-includes/wlwmanifest.xml

The filter regex is this, to match the wp-includes component.

failregex = (?i)^.(GET|POST|HEAD) [^"]?/wp-(config|content|includes|login)

The fail2ban.log entries are below.

According to the log the ip was immediately banned, but additional accesses continued over the next 17 seconds. The accesses were not all at once, so a delay due to server loading do not seem plausible.

I see this delay quite often with accesses to similar URLs including wp-include, often trying to find wlwmanifest.xml.

What could explain the delay in the ban actually activating? Thanks....

2022-01-25 23:39:40,979 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:40
2022-01-25 23:39:41,643 fail2ban.actions [8516]: NOTICE [bots] Ban 13.234.110.168
2022-01-25 23:39:41,835 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:41
2022-01-25 23:39:43,674 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:43
2022-01-25 23:39:43,930 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:44,622 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:44
2022-01-25 23:39:45,133 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:45,622 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:45
2022-01-25 23:39:45,698 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:46,582 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:46
2022-01-25 23:39:46,900 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:47,552 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:47
2022-01-25 23:39:48,103 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:48,513 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:48
2022-01-25 23:39:48,704 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:49,471 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:49
2022-01-25 23:39:49,865 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:50,417 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:49
2022-01-25 23:39:50,467 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:51,379 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:50
2022-01-25 23:39:51,669 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:52,346 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:51
2022-01-25 23:39:52,871 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:53,345 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:52
2022-01-25 23:39:53,439 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:54,294 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:53
2022-01-25 23:39:54,641 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:55,284 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:54
2022-01-25 23:39:55,846 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:56,330 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:55
2022-01-25 23:39:56,447 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:57,313 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:56
2022-01-25 23:39:57,599 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned
2022-01-25 23:39:58,263 fail2ban.filter [8516]: INFO [bots] Found 13.234.110.168 - 2022-01-25 23:39:57
2022-01-25 23:39:58,801 fail2ban.actions [8516]: NOTICE [bots] 13.234.110.168 already banned

@sebres
Copy link
Contributor

sebres commented Jan 27, 2022

Already answered in #3209 (as already said it looks like not working action, so this has nothing to do with this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants