Fail2Ban 日志文件中的“发现”是什么?

nma*_*max 22 ssh lamp logging fail2ban

我在 /var/log/fail2ban.log 中有多个类似以下的实例:

2015-12-27 14:31:21,949 fail2ban.filter         [1020]: INFO    [sshd] Found ###.###.###.###
Run Code Online (Sandbox Code Playgroud)

(其中 # 替代了多种 IP 地址。)

这个日志条目的确切含义是什么?特别是,Found表示什么?

我在这里和http://www.fail2ban.org搜索了日志文件的解释。如果我错过了这个问题的明显信息来源,我很抱歉 - 请指出正确的方向。

这是 /etc/fail2ban/filter.d/sshd.config 中 FailRegex 的配置:

failregex = ^%(__prefix_line)s(?:error: PAM: )?[aA]uthentication (?:failure|error) for .* from <HOST>( via \S+)?\s*$
        ^%(__prefix_line)s(?:error: PAM: )?User not known to the underlying authentication module for .* from <HOST>\s*$
        ^%(__prefix_line)sFailed \S+ for .*? from <HOST>(?: port \d*)?(?: ssh\d*)?(: (ruser .*|(\S+ ID \S+ \(serial \d+\) CA )?\S+ %(__md5hex)s(,$
        ^%(__prefix_line)sROOT LOGIN REFUSED.* FROM <HOST>\s*$
        ^%(__prefix_line)s[iI](?:llegal|nvalid) user .* from <HOST>\s*$
        ^%(__prefix_line)sUser .+ from <HOST> not allowed because not listed in AllowUsers\s*$
        ^%(__prefix_line)sUser .+ from <HOST> not allowed because listed in DenyUsers\s*$
        ^%(__prefix_line)sUser .+ from <HOST> not allowed because not in any group\s*$
        ^%(__prefix_line)srefused connect from \S+ \(<HOST>\)\s*$
        ^%(__prefix_line)sReceived disconnect from <HOST>: 3: \S+: Auth fail$
        ^%(__prefix_line)sUser .+ from <HOST> not allowed because a group is listed in DenyGroups\s*$
        ^%(__prefix_line)sUser .+ from <HOST> not allowed because none of user's groups are listed in AllowGroups\s*$
        ^(?P<__prefix>%(__prefix_line)s)User .+ not allowed because account is locked<SKIPLINES>(?P=__prefix)(?:error: )?Received disconnect from$
        ^(?P<__prefix>%(__prefix_line)s)Disconnecting: Too many authentication failures for .+? \[preauth\]<SKIPLINES>(?P=__prefix)(?:error: )?Co$
        ^(?P<__prefix>%(__prefix_line)s)Connection from <HOST> port \d+(?: on \S+ port \d+)?<SKIPLINES>(?P=__prefix)Disconnecting: Too many authe$
        ^%(__prefix_line)spam_unix\(sshd:auth\):\s+authentication failure;\s*logname=\S*\s*uid=\d*\s*euid=\d*\s*tty=\S*\s*ruser=\S*\s*rhost=<HOST$
Run Code Online (Sandbox Code Playgroud)

小智 20

Found xxx.xxx.xxx.xxx消息意味着,fail2ban 过滤器在给定的过滤器/监狱日志文件中找到了与 failregex 匹配的行。

例如,如果日志显示

2016-03-16 15:35:51,527 fail2ban.filter         [1986]: INFO    [sshd] Found 1.2.3.4
2016-03-16 15:35:51,817 fail2ban.filter         [1986]: INFO    [sshd] Found 1.2.3.4
2016-03-16 15:35:52,537 fail2ban.actions        [1986]: NOTICE  [sshd] Ban 1.2.3.4
Run Code Online (Sandbox Code Playgroud)

前两个Found意味着,IP 地址 1.2.3.4 在给定的 sshd 日志(例如 /var/log/auth.log)中被发现 2 次,并且日志文件中的条目在failregex过滤器中匹配/etc/fail2ban/filter.d/sshd.conf

由于我已配置为在 2 次失败的 ssh-attemtps 后禁止,因此第 3 行显示,在发现 2 次后,IP 1.2.3.4 已被禁止。

我是如何发现这一点的:

在fail2ban 的python 源代码中(在Debian 中,这是在 中/usr/lib/python3/dist-packages/fail2ban/)执行以下操作:

cd /usr/lib/python3/dist-packages/fail2ban/

grep -r "\[%s\] Found" *
Run Code Online (Sandbox Code Playgroud)

在第 937 行的 python 文件“server/filter.py”中,您可以找到相应的日志函数:

def processLineAndAdd(self, line, date=None):
  [..]
  logSys.info("[%s] Found %s" % (self.jail.name, ip))
  [..]
Run Code Online (Sandbox Code Playgroud)