Score:0

fail2ban regex failing to work

ke flag

I am trying to create a regex for my fail2ban filter to block all IPs that get a incorrect login on a web application. The way I distinguish this is that each login generates a GET request in the access log with this thing "?&err=1".

This is an example log line from the Apache access log:

XX.XX.XX.XX - - [14/Mar/2023:00:51:56 +0200] "GET /index.html?&err=1 HTTP/1.1" 200 37613

I tried this as regexes:

[[]client <HOST>[]] - - "?&err=1"

and

client <HOST> - - * "GET * err=1 *

but they don't block anything. What would be the correct regex here?

Thanks in advance for any help.

Update as of 19/04/2023:

I edited my web application to print following error line in error_log: [Wed Apr 19 00:40:10 2023] [error] [client 8.8.8.8] Selecting user ERROR!, referer: https://example.net/

Following fail2ban regexes don't work:

1. failregex = ^\[client <HOST>\] Selecting user ERROR! 

2. failregex =  ^\[client <HOST>\] Selecting user ERROR!, referer: 

3. failregex = ^\[\w{3} \w{3} \d{2} \d{2}:\d{2}:\d{2} \d{4}\] \[error\] \[client <HOST>\] Selecting user ERROR!, referer: https:\/\/example\.net\/

Any ideas where I am wrong?

Gilles Quenot avatar
cn flag
Use code blocks to format code
jp flag
These doesn't look like correct regexps. You probably want to test them with something like https://regex101.com/ and then with `fail2ban-regex`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.