我在 /var/log/fail2ban.log 中有多个类似以下的情况:
2015-12-27 14:31:21,949 fail2ban.filter [1020]: INFO [sshd] Found ###.###.###.###
(其中 # 代表多种 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$
答案1
该Found xxx.xxx.xxx.xxx
消息意味着,fail2ban 过滤器在给定的过滤器/jail 日志文件中找到了与 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
前两个Found
表示在给定的 sshd 日志(例如 /var/log/auth.log)中发现了 2 次 IP 地址 1.2.3.4,并且日志文件中的条目与failregex
过滤器匹配/etc/fail2ban/filter.d/sshd.conf
由于我已配置在 2 次 ssh 尝试失败后禁止,因此第 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" *
在python文件“server/filter.py”的第937行可以找到相应的日志函数:
def processLineAndAdd(self, line, date=None):
[..]
logSys.info("[%s] Found %s" % (self.jail.name, ip))
[..]