Užitečné programy – fail2ban
Dalším dobrým pomocníkem je balíček fail2ban. Nainstalujete jej pomocí:
yum -y install fail2ban chkconfig fail2ban on
Tento balíček běží na pozadí jako daemon kdy kontroluje systémové logy a vyhodnocuje podle zadaných pravidel zda se jedná o útok na server atd.
fail2ban používám pro služby ssh, ftp a postfix. Konfigurační soubor naleznete v /etc/fail2ban/fail2ban.conf a dalších souborech v /etc/fail2ban/ adresáři.
Můj jail.conf soubor obsahuje mimo jiné:
[ssh-iptables]
enabled = true
filter = sshd
action = iptables[name=SSH, port=2212, protocol=tcp]
sendmail-whois[name=SSH, dest=kontakt@server.com, sender=fail2ban@server.com]
logpath = /var/log/secure
maxretry = 3
[proftpd-iptables]
enabled = true
filter = pure-ftpd
action = iptables[name=pure-ftpd, port=ftp, protocol=tcp]
sendmail-whois[name=pure-ftpd, dest=kontakt@server.com]
logpath = /var/log/messages
maxretry = 5
[postfix-tcpwrapper]
enabled = true
filter = postfix
action = iptables[name=postfix, port=25, protocol=tcp]
logpath = /var/log/maillog
maxretry = 1
bantime = 600
Soubory v adresáři /etc/fail2ban/filter.d (..popisuji pouze mnou změněné soubory).
Soubor pure-ftpd.conf:
[Definition] __errmsg = (?:Authentication failed for user|Erreur d'authentification pour l'utilisateur) failregex = pure-ftpd(?:\[\d+\])?: (.+?@) \[WARNING\] %(__errmsg)s \[.+\]$ ignoreregex =
Soubor sshd.conf:
failregex = (?:error: PAM: )?Authentication failure for .* from\s*$ Failed [-/\w]+ for .* from (?: port \d*)?(?: ssh\d*)?\s*$ ROOT LOGIN REFUSED.* FROM \s*$ [iI](?:llegal|nvalid) user .* from \s*$ User .+ from not allowed because not listed in AllowUsers\s*$ User .+ from not allowed because none of user's groups are listed in AllowGroups\s*$ ignoreregex =
Soubor postfix.conf:
[Definition] failregex = reject: RCPT from (.*)\[\]: 554 reject: RCPT from (.*)\[ \]: 550 Blocked SPAM, \[ \] \[ ignoreregex =
fail2ban spouštíte příkazem:
service fail2ban start