{"id":2216,"date":"2008-07-08T04:36:57","date_gmt":"2008-07-08T04:36:57","guid":{"rendered":"http:\/\/t.motd.kr\/articles\/2216\/using-fail2ban-to-refuse-brute-force-attacks"},"modified":"2022-12-28T01:45:44","modified_gmt":"2022-12-27T16:45:44","slug":"using-fail2ban-to-refuse-brute-force-attacks","status":"publish","type":"post","link":"https:\/\/vault.motd.kr\/wordpress\/posts\/2216\/using-fail2ban-to-refuse-brute-force-attacks\/","title":{"rendered":"Using Fail2Ban to refuse brute-force attacks"},"content":{"rendered":"\n
I have been using a quick and dirty shell script to update Most examples use Please note that I defined a new action called For more information, I\u2019d recommend you to read the Gentoo HOWTO<\/span> fail2ban<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" I have been using a quick and dirty shell script to update \/etc\/hosts.deny file when brute-force attack flows into my server. It was pretty effective but was not effective enough to block the break-in attempts immediately. Today, I found a better solution \u2013 Fail2Ban. It scans the system log files and bans brute-force attacks for… Continue reading \/etc\/hosts.deny<\/code> file when brute-force attack flows into my server. It was pretty effective but was not effective enough to block the break-in attempts immediately. Today, I found a better solution \u2013 Fail2Ban<\/a>. It scans the system log files and bans brute-force attacks for a certain period.<\/p>\n\n\n\n
iptables<\/code>, but I always prefer
\/etc\/hosts.deny<\/code> and I don\u2019t even care about unbanning once a host is banned. Therefore, I added the following to
\/etc\/fail2ban\/jail.conf<\/code>:<\/p>\n\n\n\n
[ssh-hostsdeny]\nenabled = true\nfilter = sshd\naction = hostsdeny-nounban\n mail-whois[name=SSH, dest=mail@example.com]\nlogpath = \/var\/log\/messages\n\n[ssh-ddos-hostsdeny]\nenabled = true\nfilter = sshd-ddos\naction = hostsdeny-nounban\n mail-whois[name=SSH-DDoS, dest=mail@example.com]\nlogpath = \/var\/log\/messages<\/code><\/pre>\n\n\n\n
hostsdeny-nounban<\/code>, which doesn\u2019t unban the attacker\u2019s IP address once banned It\u2019s
\/etc\/fail2ban\/action.d\/hostsdeny-nounban.conf<\/code>:<\/p>\n\n\n\n
[Definition]\nactionstart =\nactionstop =\nactioncheck =\nactionban = IP=<ip> && grep -q \"ALL: $IP\" <file> || echo \"ALL: $IP\" >> <file>\nactionunban =\n\n[Init]\nfile = \/etc\/hosts.deny<\/code><\/pre>\n\n\n\n