Plik /etc/fail2ban/jail.local:
Kod: Zaznacz cały
[DEFAULT]
bantime = 300
findtime = 600
maxretry = 4
backend = auto
usedns = warn
destemail = moj.adres@gmail.com
banaction = iptables-multiport
mta = sendmail
protocol = tcp
chain = INPUT
(...)
action = %(action_mw)s
(...)
[ssh]
enabled = true
port = anyport
filter = sshd
logpath = /var/log/auth.log
maxretry = 4
Kod: Zaznacz cały
enabled = false
W pliku mam ustawione, że powinno mnie banować po 4 próbach, tymczasem wyrzuca mnie dopiero po 6, ale nie banuje. Oto jak zapisało się takich 6 nieudanych prób logowania w /var/log/auth.log (chyba prawidłowo):
Kod: Zaznacz cały
Jul 8 09:51:09 nazwaserwera sshd[1798]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=abod34.neoplus.adsl.tpnet.pl user=my-admin
Jul 8 09:51:10 nazwaserwera sshd[1798]: Failed password for my-admin from 83.8.19.34 port 56451 ssh2
Jul 8 09:51:27 nazwaserwera sshd[1798]: message repeated 5 times: [ Failed password for my-admin from 83.8.19.34 port 56451 ssh2]
Jul 8 09:51:27 nazwaserwera sshd[1798]: Disconnecting: Too many authentication failures for my-admin [preauth]
Jul 8 09:51:27 nazwaserwera sshd[1798]: PAM 5 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=abod34.neoplus.adsl.tpnet.pl user=my-admin
- używam niestandardowego portu do łączenia się przez SSH, więc w pliku /etc/ssh/sshd_conf ustawiłem:
Kod: Zaznacz cały
Port 4444
- co ciekawe Fail2Ban przysyła mi maile na wskazany adres, ale tylko informujące, że usługa fail2ban została zatrzymana/uruchomiona
A oto wyjście po wpisaniu polecenia sudo iptables -L
Kod: Zaznacz cały
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain fail2ban-ssh (0 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Nie wiem czy to ma jakieś znaczenie, ale w logu /var/log/fail2ban.log po restarcie fail2ban zapisują się następujące informacje:
Kod: Zaznacz cały
2014-07-08 11:26:12,538 fail2ban.server : INFO Stopping all jails
2014-07-08 11:26:13,141 fail2ban.jail : INFO Jail 'ssh' stopped
2014-07-08 11:26:13,142 fail2ban.server : INFO Exiting Fail2ban
2014-07-08 11:26:16,825 fail2ban.server : INFO Changed logging target to /var/log/fail2ban.log for Fail2ban v0.8.11
2014-07-08 11:26:16,826 fail2ban.jail : INFO Creating new jail 'ssh'
2014-07-08 11:26:17,024 fail2ban.jail : INFO Jail 'ssh' uses pyinotify
2014-07-08 11:26:17,141 fail2ban.jail : INFO Initiated 'pyinotify' backend
2014-07-08 11:26:17,142 fail2ban.filter : INFO Added logfile = /var/log/auth.log
2014-07-08 11:26:17,144 fail2ban.filter : INFO Set maxRetry = 4
2014-07-08 11:26:17,145 fail2ban.filter : INFO Set findtime = 600
2014-07-08 11:26:17,145 fail2ban.actions: INFO Set banTime = 300
2014-07-08 11:26:17,438 fail2ban.jail : INFO Jail 'ssh' started
2014-07-08 11:26:17,619 fail2ban.actions.action: ERROR iptables -N fail2ban-ssh
iptables -A fail2ban-ssh -j RETURN
iptables -I INPUT -p tcp -m multiport --dports anyport -j fail2ban-ssh returned 200