web-dev-qa-db-ja.com

fail2banのmaxretryは3ですが、認証の失敗が5回繰り返されています

Ufwを介してsshを有効にしてUbuntu16.04を実行し、最大3の[sshd]および[sshd-ddos]ジェイルを有効にするようにfail2banを構成しました(つまり、3回認証に失敗したipを禁止したい)。認証ログを見ると、5回認証に失敗したため、認証の失敗が多すぎて切断されたいくつかの異なるIPが表示されます。これらのIPが禁止されていないのはなぜですか? fail2banを誤って構成したか、意図した動作を誤解していることを完全に期待していますが、読んだチュートリアル(digitalocean、その他の検索結果)から、この構成は期待どおりに機能するはずです。また、fail2banログで禁止(および禁止解除)を確認できるため、fail2banが一部のIPを正常に禁止していることにも注意してください。

問題のあるIPアドレスの1つに関連するログ行は次のとおりです(IPとホストが編集されています)。

「/var/log/fail2ban.log」

2017-02-17 13:23:36,148 fail2ban.filter         [24793]: INFO    [sshd] Found [ip address]
2017-02-17 13:23:38,153 fail2ban.filter         [24793]: INFO    [sshd] Found [ip address]

「/var/log/auth.log」

Feb 17 13:23:36 [Host] sshd[15498]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=[ip address]  us
er=root
Feb 17 13:23:38 [Host] sshd[15498]: Failed password for root from [ip address] port 9498 ssh2
Feb 17 13:23:49 [Host] sshd[15498]: message repeated 5 times: [ Failed password for root from [ip address] port 9498 ssh2]
Feb 17 13:23:49 [Host] sshd[15498]: error: maximum authentication attempts exceeded for root from [ip address] port 9498 ssh2 [preauth]
Feb 17 13:23:49 [Host] sshd[15498]: Disconnecting: Too many authentication failures [preauth]
Feb 17 13:23:49 [Host] sshd[15498]: PAM 5 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=[ip address]  user=root
Feb 17 13:23:49 [Host] sshd[15498]: PAM service(sshd) ignoring max retries; 6 > 3

これが私のfail2ban設定からの関連する(コメントではない)行です。これはほとんどがjail.confからのストレートコピーであり、bantime、findtime、maxretryのデフォルトが変更され、[sshd]、[sshd-ddos]、[recidive] jailがあります。有効:

"/etc/fail2ban/jail.local"

[DEFAULT]

ignoreip = 127.0.0.1/8
bantime = 21600
findtime = 3600
maxretry = 3
backend = auto
usedns = warn
logencoding = auto
enabled = false
filter = %(__name__)s
destemail = root@localhost
sender = root@localhost
mta = sendmail
protocol = tcp
chain = INPUT
port = 0:65535
banaction = iptables-multiport
action_ = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
action_mw = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
            %(mta)s-whois[name=%(__name__)s, dest="%(destemail)s", protocol="%(protocol)s", chain="%(chain)s"]
action_mwl = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
action_xarf = %(banaction)s[name=%(__name__)s, bantime="%(bantime)s", port="%(port)s", protocol="%(protocol)s", chain="%(chain)s"]
             xarf-login-attack[service=%(__name__)s, sender="%(sender)s", logpath=%(logpath)s, port="%(port)s"]
action_cf_mwl = cloudflare[cfuser="%(cfemail)s", cftoken="%(cfapikey)s"]
                %(mta)s-whois-lines[name=%(__name__)s, dest="%(destemail)s", logpath=%(logpath)s, chain="%(chain)s"]
action_blocklist_de  = blocklist_de[email="%(sender)s", service=%(filter)s, apikey="%(blocklist_de_apikey)s"]
action_badips = badips.py[category="%(name)s", banaction="%(banaction)s"]

[sshd]

enabled = true
port    = ssh
logpath = %(sshd_log)s

[sshd-ddos]
# This jail corresponds to the standard configuration in Fail2ban.
# The mail-whois action send a notification e-mail with a whois request
# in the body.
enabled = true
port    = ssh
logpath = %(sshd_log)s

[recidive]

enabled  = true
logpath  = /var/log/fail2ban.log
banaction = iptables-allports
bantime  = 604800  ; 1 week
findtime = 86400   ; 1 day
maxretry = 5

さらなる調査:

Sudo fail2ban-regex /var/log/auth.log /etc/fail2ban/filter.d

ログファイルは/var/log/auth.logとして正しいです。行:1127行、0無視、125一致、1002欠落[1.77秒で処理]

sudo iptables -L -n | less

「Chainf2b-sshd(1references)」の下にいくつかの禁止されたips(REJECT付き)が表示されます。

2
Bucket Mouse

Fail2banは、標準形式のログのみを表示し、特定の時間枠内に表示されたログの数をカウントします。また、syslogは同じログを集約された形式にマージしているため、この解析はできません。

Feb 17 13:23:49 [Host] sshd[15498]: message repeated 5 times: [ Failed password for root from [ip address] port 9498 ssh2]

通常、認証の失敗は、認証に失敗した接続と見なされます。ただし、この単一の接続は、複数の「パスワード認証の試行」で構成されている可能性があります(その回数は、クライアントNumberOfPasswordPromptsとサーバーMaxAuthTriesの構成によって異なります)。

fail2banを設定するときは、物事がどのように回避されるかを知っておくとよいでしょう。そこでポリシーを設定するときは、それが何を意味するのかを知ってください。この場合、これは予想される動作であり、認証の試行をさらに制限する場合は、sshdの構成を調整する必要があります。

3
Jakuje