• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Issue Fail2Ban is not banning IP addresses properly

Tonies

New Pleskian
  • OS: ‪CentOS Linux 7.4.1708 (Core)‬
  • Product: Plesk Onyx 17.5.3 Update #44
Hi,

I logged in to my server today as root there was a message "There were 4524 failed login attempts since the last successful login."

Fail2Ban jails are all enabled and green.

There is only one IP address banned in there at the moment.

Here are my settings for Fail2Ban:

2018-04-08_071238.jpg


Why has Fail2Ban not added the IPs which have made attempts to log in as root as there were over 4000 attempts to login between a space of a few hours logging in?

Can someone provide some information or a link to follow and troubleshoot this, please?

Thanks.
 
Last edited:
perhaps a good starting point is Protection Against Brute Force Attacks (Fail2Ban) & Fail2Ban Jails Management

For the Comunity it would be helpfull when you provide your OS & Plesk Version

Why has Fail2Ban not added the IPs which have made attempts to log in as root as there were over 4000 attempts to login between a space of a few hours logging in?

Because a) fail2ban / Jail is not working right, b) settings wrong c) it was a distributed attack with different IP´s....

Well based on the screenshot the global settings (and if you have not different settings for the relevant jail) would mean 2 attemps in 60 seconds from the same IP would be banned. Therefore you have to check the relevant logfile of this attack and the failed2ban logfile also.

If you are talking about failed ssh login attempts it would be depending on your OS /var/log/auth.log or /var/log/secure you have to identify the bad IP(s) and then check the fail2ban.log if this ip(s) was recognized by fail2ban.

you can test for example fail2ban jails & config on CLI like:
Code:
# fail2ban-regex --print-all-matched /path/to/logfile/xyz.log /etc/fail2ban/filter.d/xyz-jail.conf
 
Last edited:
Hi @Brujo

Thanks for the reply and sorry for not entering my OS and Plesk Version, I have now updated my original post to reflect this and will do so moving forward (Will also change my other posts with this information too).

Thanks for the links too, Fail2Ban Jails Management this one helped as I created a jail for SSHD based on the guide:

2018-04-08_115635.jpg


There is already one which exists for SSH:

2018-04-08_115653.jpg

I found the log that is used for my system and it is located here: /var/log/secure and also found a command to check failed attempts in SSH: egrep "Failed|Failure" /var/log/secure

The log is quite long.

2018-04-08_115535.jpg


Based on the SSH Fail2Ban jail, these IP's should have been blocked. I checked the Fail2Ban log in /var/log/fail2ban.log as suggested and found no trace of the above IP's in there.

I also ran the command as per your advice and got the following result:

Code:
fail2ban-regex --print-all-matched var/log/fail2ban.log /etc/fail2ban/filter.d/sshd.conf

2018-04-08_121113.jpg


No idea how to interpret this though.

Thanks in advance.
 
Based on the SSH Fail2Ban jail, these IP's should have been blocked. I checked the Fail2Ban log in /var/log/fail2ban.log as suggested and found no trace of the above IP's in there.
this would mean the fail2ban filter would not match the logentrys.

Sorry if I wrote not detailed enough about fail2ban-regex see: MANUAL 0 8 - Fail2ban (Section Testing)

the logfile in your case is /var/log/secure so the test should look like
Code:
fail2ban-regex --print-all-matched /var/log/secure /etc/fail2ban/filter.d/sshd.conf
 
Last edited:
this would mean the fail2ban filter would not match the logentrys.

Will check the filter based on the previous link documentation you have sent and hopefully resolve the issue as I still believe it is not working as it should.

Thanks for the updated command and I ran that command and got the same result as previously provided in my last message.

Thanks.
 
example output of an centos testserver

# grep Failed /var/log/secure
Apr 8 15:35:24 mail sshd[22704]: Failed password for root from 123.229.34.230 port 55401 ssh2
Apr 8 15:35:29 mail sshd[22704]: Failed password for root from 123.229.34.230 port 55401 ssh2
Apr 8 15:36:02 mail sshd[23126]: Failed password for root from 123.229.34.230 port 55401 ssh2

# fail2ban-regex --print-all-matched /var/log/secure /etc/fail2ban/filter.d/sshd.conf
Lines: 23 lines, 0 ignored, 4 matched, 19 missed
[processed in 0.02 sec]

|- Matched line(s):
| Apr 8 15:35:22 golum sshd[22704]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=someone user=root
| Apr 8 15:35:24 golum sshd[22704]: Failed password for root from 123.229.34.230 port 55401 ssh2
| Apr 8 15:35:29 golum sshd[22704]: Failed password for root from 123.229.34.230 port 55401 ssh2
| Apr 8 15:36:02 golum sshd[22704]: Failed password for root from 123.229.34.230 port 55401 ssh2

and in the fail2ban.log there are findings logged and in this case it was 3 times found and banned

# grep ssh /var/log/fail2ban.log
2018-04-08 15:35:24,892 fail2ban.filter [24678]: INFO [ssh] Found 123.229.34.230
2018-04-08 15:35:29,703 fail2ban.filter [24678]: INFO [ssh] Found 123.229.34.230
2018-04-08 15:36:02,537 fail2ban.filter [24678]: INFO [ssh] Found 123.229.34.230
2018-04-08 15:36:02,796 fail2ban.actions [24678]: NOTICE [ssh] Ban 123.229.34.230
 
Last edited:
Thanks for the response, I ran the command as you have suggested @Brujo

Code:
fail2ban-regex --print-all-matched /var/log/secure /etc/fail2ban/filter.d/sshd.conf

The output after starting the tests:

2018-04-08_172514.jpg


As can be seen, there have been 165651 attempts :( I had to remove the new Jail I created which I posted above as I realised it was already activated with the default ssh.

2018-04-08_173132.jpg


I have added the two troublesome IP's by activating firewall for now and hopefully, they cannot gain access to my site or attack my server until I get this Fail2Ban resolved somehow and for it to work. (Did not activate before as some of my website extension developers cannot access the sites and been trying to figure out how to give them access via firewall after activation for FTP SSH).

I am still searching for how to fix this Fail2Ban and if I find the cause then will report back but unfortunately until now, no joy.

Thanks for your help thus far, appreciate it much.
 
the relevant output of fail2ban-regex is "Lines: 23 lines, 0 ignored, 4 matched, 19 missed"
Lines = Total log entrys, matched = how many entrys are catched by the filter, missed = entrys which are not recogniced by the filter and perhaps fine

Well based on your screenshot you provided there are matched entrys, therefore it should be also an entry in fail2ban.log

whats the output of
# grep ssh /var/log/fail2ban.log or grep 213.136.74.205 /var/log/fail2ban.log
is there any Found or Ban like in my above example?
 
Last edited:
Hi @Brujo

After running command:

Code:
# grep ssh /var/log/fail2ban.log or grep 213.136.74.205 /var/log/fail2ban.log

I get the following:

2018-04-08_205152.jpg


I see that it states:

Code:
2018-04-08 11:11:46,001 fail2ban.actions        [3575]: ERROR   Failed to stop  j
2018-04-08 11:11:46,001 fail2ban.actions        [3575]: ERROR   Failed to stop jail 'ssh' action 'iptables-allports': Error stopping action

il 'ssh' action 'iptables-allports': Error stopping action

That must be the culprit, right?

Is it because of all ports setting in SSH jail? not sure.

Thanks.
 
Hey Tonies

did you get arround your issue and it is working now or you still struggle with it?
if so, how looks your filter for ssh now
 
Hi @Brujo

Thanks for catching up with me.

No, unfortunately, I have not. I found an article about fail2ban through google but was no help.

I ran these commands again:

Code:
grep ssh /var/log/fail2ban.log
and
Code:
grep 213.136.74.205 /var/log/fail2ban.log

Nothing came up for both commands, it just goes to a blank line, why does it not show anything?

2018-04-10_200245.jpg


Thanks in advance.
 
The Plesk Firewall and Fail2ban working good on my Server. I don't know why you have trouble with this.

Gesendet von meinem Pixel mit Tapatalk
 
Back
Top