让 fail2ban 向被禁方发送通知

让 fail2ban 向被禁方发送通知

我有失败2ban在某些 CentOS 5 和 6 服务器上配置,每当 IP 被禁止时,它都会向我发送一封包含该 IP 的 whois 的电子邮件。是否可以配置 fail2ban 以从 whois 报告向电子邮件发送通知?

这是我的监狱配置:

# /etc/fail2ban/jail.conf    

[ssh-iptables]

enabled  = true
filter   = sshd
action   = iptables-allports[name=SSH, protocol=all]
           sendmail-whois[name=SSH, [email protected], sender=fail2ban]
logpath  = /var/log/secure
maxretry = 3

是否有某种变量我可以将其dest=发送到 whois 电子邮件?

答案1

看起来 fail2ban 中有一个叫做 的操作complain。请注意以下行complain[logpath=/var/log/secure]

# /etc/fail2ban/jail.conf    

[ssh-iptables]

enabled  = true
filter   = sshd
action   = iptables-allports[name=SSH, protocol=all]
           sendmail-whois[name=SSH, [email protected], sender=fail2ban]
           complain[logpath=/var/log/secure]
logpath  = /var/log/secure
maxretry = 3

添加该行并重新启动 fail2ban 服务。操作配置文件是 /etc/fail2ban/action.d/complain.conf。简要说明:

向 whois 记录中列出的违规 IP 地址的地址发送投诉电子邮件。

答案2

这是有可能的。(这取决于你如何严格地定义“让 fail2ban 做这件事”。)不过,在我看来这并不是特别浪费时间。

基本上,您需要whois联系域名所有者,并向 abuse@[domain].[tld] 发送电子邮件,让他们知道他们的某个主机上的某个人正在试图未经授权访问您的系统,并附上日志。(您也可以按照您的建议向 whois 中的电子邮件发送一封邮件,但这更不可能到达关心或可以做些什么的人。)您必须希望:

  1. abuse是正确的地址(您可以尝试其他地址,但这是目前最常见的地址)并且受到监控。(与 whois 中列出的电子邮件地址相同 - 如果它无效或不受监控,那么您就是在浪费时间。)
  2. 主持人很在意。
  3. 主持人不参与其中。
  4. 主持人有充足的空闲时间来追踪这个顽皮的用户。
  5. 主持人拥有追踪违规用户的技术能力。
  6. 不守规矩的用户不会立即切换主机/受感染的系统并继续畅通无阻。

如果其中任何一个条件为假,那么你就完全是在浪费时间,而且根据我的经验,2、4、5 和 6 几乎总是假的,所以你所做的完全是在浪费时间,除非你想将此作为学习经验,从而成为一个更好的脚本编写者。

答案3

添加到@Banjer 的答案(这是正确的):如果您正确配置了操作“投诉”,那么您实际上并不需要同时执行操作“sendmail-whois”和“投诉”:

# /etc/fail2ban/jail.conf    
[ssh-iptables]
enabled  = true
filter   = sshd
action   = iptables-allports[name=SSH, protocol=all]
           complain[logpath=/var/log/secure]
logpath  = /var/log/secure
maxretry = 3

和:

# /etc/fail2ban/action.d/complain.conf
[Init]
message = <insert body-text here>\n\nWhois information about $IP:\n`/usr/bin/whois $IP`\n
logpath = /dev/null
mailcmd = mail -s
mailargs = -c <insert your e-mailaddress here> -- -f root@<insert your domain here>

这样,管理违规 IP 地址的互联网服务提供商将自动被联系,并且您将收到电子邮件的副本,抄送地址为:(mailargs 变量的“-c”选项)。

我还将 WHOIS 信息添加到消息变量中,这不是 Debian 配置中的默认设置,但在我看来,这是默认消息的一个不错的附加组件。

相关内容