LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-27-2024, 12:34 AM   #1
Jason.nix
Member
 
Registered: Feb 2023
Posts: 565

Rep: Reputation: 10
Post A few questions about configuring Fail2Ban


Hello,
I have a few questions about configuring Fail2Ban:

1- The following options exist in two sections of Fail2Ban. One under [DEFAULT] section and another under the service configuration section:
Code:
maxretry  = 3
findtime  = 1d
bantime   = 4w
Why?

2- If I set the value of findtime to 1d, that means the number of times that the wrong password is entered must happen during a day? For example, 3 times in one day.

3- What is the best value of findtime to avoid brute-force attack?

Thank you.
 
Old 02-27-2024, 03:41 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by Jason.nix View Post
Hello,
I have a few questions about configuring Fail2Ban:

1- The following options exist in two sections of Fail2Ban. One under [DEFAULT] section and another under the service configuration section:

Why?
So that different services can have different configurations but if one isn't specified then the default will be used.
Quote:
Originally Posted by Jason.nix View Post
2- If I set the value of findtime to 1d, that means the number of times that the wrong password is entered must happen during a day? For example, 3 times in one day.
Pretty much. However 3 / 1d is crazy unless you've other mitigating factors to stop legitimate users getting locked out. Brute force attacks work by sending a lot of requests in rapid succession, so a smaller findtime is more appropriate.
Quote:
Originally Posted by Jason.nix View Post
3- What is the best value of findtime to avoid brute-force attack?
Your favorite search engine should be your friend: https://www.linode.com/docs/guides/h...ce-protection/
 
1 members found this post helpful.
Old 02-27-2024, 08:28 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,341
Blog Entries: 28

Rep: Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145Reputation: 6145
For what it's worth, I've found the default settings to be quite acceptable.
 
Old 02-28-2024, 12:51 AM   #4
Jason.nix
Member
 
Registered: Feb 2023
Posts: 565

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by TenTenths View Post
So that different services can have different configurations but if one isn't specified then the default will be used.
Pretty much. However 3 / 1d is crazy unless you've other mitigating factors to stop legitimate users getting locked out. Brute force attacks work by sending a lot of requests in rapid succession, so a smaller findtime is more appropriate.

Your favorite search engine should be your friend: https://www.linode.com/docs/guides/h...ce-protection/
Hello,
Thank you so much for your reply.
If you define findtime = 10s and maxretry = 3, then the hacker enters the password twice under 10 seconds and enters the third time in 11 seconds, then will he\she be blocked?
 
Old 02-28-2024, 04:23 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by Jason.nix View Post
If you define findtime = 10s and maxretry = 3, then the hacker enters the password twice under 10 seconds and enters the third time in 11 seconds, then will he\she be blocked?
Why would you want to have findtime set so crazy low? Remember there's "reaction time" involved here, which is the delay between sshd writing the failed attempt to the logs and Fail2Ban reading the logs. In general this will be low, but on a heavily loaded system there may be a reaction delay.

If you're looking to stop bad actors attempting to access / brute force your system, a bit of research, even reading your own log files would show that the typical attack vector is an attempt every few seconds. A typical pattern is also to try a single password and if that fails to "back off" for a few seconds then try again.

From experience I find the default values are sufficient to discourage automated attempts.
 
Old 03-02-2024, 01:22 AM   #6
Jason.nix
Member
 
Registered: Feb 2023
Posts: 565

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by TenTenths View Post
Why would you want to have findtime set so crazy low? Remember there's "reaction time" involved here, which is the delay between sshd writing the failed attempt to the logs and Fail2Ban reading the logs. In general this will be low, but on a heavily loaded system there may be a reaction delay.

If you're looking to stop bad actors attempting to access / brute force your system, a bit of research, even reading your own log files would show that the typical attack vector is an attempt every few seconds. A typical pattern is also to try a single password and if that fails to "back off" for a few seconds then try again.

From experience I find the default values are sufficient to discourage automated attempts.
Hello,
Thanks again.
I think to prevent brute-force attack, findtime value should be 1s, but as you said, the best option is to look at the SSH logs to determine the best value.
How can I tell Fail2Ban to block an IP address if it enters the wrong password 3 times regardless of the time interval?

Last edited by Jason.nix; 03-02-2024 at 04:42 AM.
 
Old 03-03-2024, 09:38 AM   #7
elgrandeperro
Member
 
Registered: Apr 2021
Posts: 415
Blog Entries: 2

Rep: Reputation: Disabled
I believe it is bantime = -1. If you actually uses password only, then short findtime will ban your users often simply because they think they type in the wrong password and they will ask but you to unban them all the time. I find setting it to a few minutes suffices. Remember, this is for brute force /well known account and passwords. It is better to just use public keys auth, or integrate one time passwords using gauth or security devices. That way, no one has a "real" password.
 
Old 03-04-2024, 05:28 AM   #8
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by Jason.nix View Post
I think to prevent brute-force attack, findtime value should be 1s, but as you said, the best option is to look at the SSH logs to determine the best value.
So how do you know it's a brute-force attack if you're only looking at 1s? The signature of brute force is prolonged multiple password attempts. Many skript kiddy scripts will back off slight or attempt to randomize time between tries.
Quote:
Originally Posted by Jason.nix View Post
How can I tell Fail2Ban to block an IP address if it enters the wrong password 3 times regardless of the time interval?
Depending on how your regular users interact with the system this isn't a particularly clever thing to do as it doesn't allow for things like regular user errors. Say I enter my password wrong because I used an old one, then enter the right one, then do the same thing a couple of times over the next few days, I'd get banned. Now maybe that's the behavior you want, but it will really annoy your regular users.
 
Old 03-05-2024, 12:39 AM   #9
Jason.nix
Member
 
Registered: Feb 2023
Posts: 565

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by TenTenths View Post
So how do you know it's a brute-force attack if you're only looking at 1s? The signature of brute force is prolonged multiple password attempts. Many skript kiddy scripts will back off slight or attempt to randomize time between tries.
Depending on how your regular users interact with the system this isn't a particularly clever thing to do as it doesn't allow for things like regular user errors. Say I enter my password wrong because I used an old one, then enter the right one, then do the same thing a couple of times over the next few days, I'd get banned. Now maybe that's the behavior you want, but it will really annoy your regular users.
Hello,
Thank you so much for your reply.
1- So what settings do you recommend to protect against brute-force attacks?

2- I want to be blocked for one day if a person enters wrong password three times during the day. Is it possible?
 
Old 03-05-2024, 03:28 AM   #10
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by Jason.nix View Post
1- So what settings do you recommend to protect against brute-force attacks?
You've already been told twice!
Post #3
Quote:
Originally Posted by frankbell View Post
For what it's worth, I've found the default settings to be quite acceptable.
Post #5
Quote:
Originally Posted by TenTenths View Post
From experience I find the default values are sufficient to discourage automated attempts.
Quote:
Originally Posted by Jason.nix View Post
2- I want to be blocked for one day if a person enters wrong password three times during the day. Is it possible?
Yes.

Last edited by TenTenths; 03-05-2024 at 03:30 AM.
 
Old 03-05-2024, 03:54 AM   #11
Jason.nix
Member
 
Registered: Feb 2023
Posts: 565

Original Poster
Rep: Reputation: 10
Quote:
Originally Posted by TenTenths View Post
You've already been told twice!
Post #3
Post #5

Yes.
Hi,
Thanks.
Can you tell me how can I block someone who has entered the wrong password three times in any given time period?
 
Old 03-05-2024, 03:57 AM   #12
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Quote:
Originally Posted by Jason.nix View Post
Can you tell me how can I block someone who has entered the wrong password three times in any given time period?
RTFM
 
Old 03-05-2024, 11:26 AM   #13
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,129
Blog Entries: 2

Rep: Reputation: 260Reputation: 260Reputation: 260
These are the settings I use:
Code:
bantime  = 20m
bantime.increment = true
bantime.factor = 1
bantime.maxtime = 30d
findtime  = 20m
maxretry = 5
The person connecting gets 5 tries within 20 minutes. If they fail the 5 attempts, they start with a 20 minute ban. If they come back after the ban and fail again, the ban doubles, and will keep doubling after the failed attempts.

I also use a non-standard port so I'm not bombarded by bots.

I think in the years I've been running my server, only one person/bot was persistent enough to get a ban for several weeks before giving up.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Returning to Slackware after a few years, but I have a few questions pocker Slackware 14 04-19-2021 02:22 PM
[SOLVED] Configuring Conky to read log file entries - apache + fail2ban djsmiley2k Linux - Desktop 1 04-26-2010 04:29 AM
LXer: Configuring fail2ban With SquirrelMail On Debian Lenny 5.0/ISPConfig 3 LXer Syndicated Linux News 0 08-31-2009 10:40 AM
LXer: Configuring fail2ban With SquirrelMail On CentOS 5.3/ISPConfig 3 LXer Syndicated Linux News 0 08-12-2009 05:20 PM
A few configuring questions with regard to services like vsftpd davidstvz Linux - Newbie 6 08-20-2008 03:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 04:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration