In the ever-evolving landscape of cybersecurity, new tools and methods emerge regularly to counteract the growing number of threats. One such tool that has gained attention in recent years is Failtoban. This simple yet effective solution helps system administrators protect their servers and networks from brute force attacks by blocking malicious login attempts. While Failtoban may not be as widely recognized as some other cybersecurity tools, its functionality has made it a staple for many IT professionals looking to safeguard their systems.
What is Failtoban?
Failtoban is a security tool designed primarily to prevent unauthorized access to servers by detecting and blocking IP addresses that make repeated unsuccessful login attempts. These login failures often indicate brute-force attacks, where attackers try various password combinations to gain unauthorized access to an account. Failtoban enhances server security by analyzing log files for patterns of failed login attempts and then blacklisting the IP addresses responsible.
The tool is typically used in conjunction with SSH (Secure Shell) and other network services. It is a flexible solution that can be configured to block IP addresses for a predetermined amount of time, or in some cases, permanently, depending on the severity of the attack.
How Failtoban Works
Failtoban works by monitoring specific log files on a server (such as /var/log/auth.log on Linux systems) for failed login attempts. These log files record every instance when a login fails, along with the IP address of the attempted attacker. The Failtoban service regularly scans these logs to identify multiple failed attempts from the same IP address.
Once a threshold is reached—typically a set number of failed login attempts within a defined period—the offending IP address is automatically added to a blocklist. This means that the IP will be prevented from accessing the server for a defined period, ranging from minutes to hours or even days, depending on the configuration. In some cases, administrators can set Failtoban to block the IP address permanently.
Failtoban’s real power comes from its ability to adapt to different server environments. It can be configured to block various types of attacks, such as SSH, FTP, and HTTP brute-force attempts. Furthermore, Failtoban allows for customized actions, such as notifying system administrators when an attack is detected.
Setting up Failtoban
Install Fail2Ban: Fail2Ban is available in the default repositories of most Linux distributions, making it easy to install. Follow the instructions below based on your distribution:
# on debian/ubunutu
sudo apt install fail2ban
# On fedora
sudo dnf install fail2ban
Configuring Fail2Ban for SSH Protection: Fail2Ban is configured using two primary files:
- fail2ban.conf: The global configuration file.
- jail.conf: The file where you define rules for specific services.
The default configuration is located in /etc/fail2ban/jail.conf, but it’s recommended not to modify this file directly. Instead, you should create a local configuration file (jail.local) where you can override settings from jail.conf.
Modify the SSH Settings
Now, open the jail.local file for editing:
sudo nano /etc/fail2ban/jail.local
Modify the following parameters according to your requirement
bantime = 10m # length of time (in seconds) that the IP address will be banned. For example, 600 means 10 minutes. You can increase this for stricter protection or decrease it for temporary bans.
findtime: 10m #The time window (in seconds) in which the failed login attempts are counted. For instance, findtime = 600 means that the three failed attempts (as set by maxretry) must occur within 10 minutes.
maxretry = 5 # number of failures before a host get banned.
ignoreip = 127.0.0.1/8 ::1 # Fail2ban will not ban a host which matches an address in this list
Starting , enabling and printing status of failtoban service
sudo systemctl start fail2ban.service
sudo systemctl status fail2ban
sudo systemctl enable fail2ban
Verify Fail2Ban is Protecting SSH: To ensure that Fail2Ban is running and protecting SSH, you can check the status of the SSH jail:
# list all the jails
sudo fail2ban-client status
# This command will provide information about the current status of the SSH jail, including how many IPs are currently banned.
sudo fail2ban-client status sshd
Manually ban/unban ip
sudo fail2ban-client set sshd banip x.x.x.x
sudo fail2ban-client set sshd unbanip x.x.x.x
Conclusion
Failtoban is a powerful and effective tool for enhancing server security, particularly for systems that are vulnerable to brute-force login attacks. By automatically blocking IP addresses associated with multiple failed login attempts, Failtoban provides a proactive layer of protection for SSH, FTP, and other services. Its open-source nature, flexibility, and ease of use make it an excellent choice for system administrators seeking to secure their servers without incurring high costs. However, it is important to remember that Failtoban should be used as part of a broader security strategy, addressing additional threats like malware, network intrusions, and more.