fail2ban规则导致“iptables返回200”错误消息

我只是试图添加一个新的fail2ban规则,该规则应该扫描Apache2错误日志以进行可疑的文件访问尝试(试图访问三个不存在的常见loginURL的用户通常没有良好的意图)。

为此,我在jail.local文件中添加了一条新规则:

[apache-suspiciousfiles] enabled = true port = http,https filter = apache-suspiciousfiles banaction = iptables-allports action = %(action_mwl)s logpath = /var/log/apache2/error*.log maxretry = 3 

但是 – 在我的日志中给了我一个意想不到的错误消息:

 2014-02-10 13:28:51,450 fail2ban.jail : INFO Jail 'apache-suspiciousfiles' started 2014-02-10 13:28:51,690 fail2ban.actions.action: ERROR iptables -N fail2ban-apache-suspiciousfiles iptables -A fail2ban-apache-suspiciousfiles -j RETURN iptables -I INPUT -p tcp -j fail2ban-apache-suspiciousfiles returned 200 

在此之前,我已经用fail2ban-regex检查了filter,所以我确信它不在那里。

(注:这是“200回”,很多人似乎有100个问题,但是这个是200左右)

我做了一个快速的谷歌search,没有任何答案似乎帮助我,所以我刚刚尝试了我脑海中的第一件事:

我重新命名了规则,并缩短了名字:

 [apache-suspicious] enabled = true port = http,https filter = apache-suspicious banaction = iptables-allports action = %(action_mwl)s logpath = /var/log/apache2/error*.log maxretry = 3 

(我把规则从apache-suspiciousfiles改名为apache-suspicious)

这实际上帮助了我。 现在一切都开始了,我的规则正在工作。

如果你的configuration同时产生“multiport”和“all”,也会发生这种情况('all'可以用来解决从tcp切换到udp的机器人,这些工具会以“WARNING:…已经被禁止”的方式填充日志)。

 $ sudo iptables -I INPUT -p all -m multiport --dports ssh -j fail2ban-ssh iptables: multiport needs `-p tcp', `-p udp', `-p udplite', `-p sctp' or `-p dccp' $ echo $? 2 $ cat fail2ban.log iptables -I INPUT -p all -m multiport --dports ssh -j fail2ban-ssh returned 200 

对我来说,200是因为发送到iptables的action.d规则无法parsing。

我的iptables action.d规则如下

 [Definition] actionstart = iptables -N fail2ban-<name> iptables -A fail2ban-<name> -j RETURN iptables -I INPUT -p <protocol> --dport <port> -j fail2ban-<name> ##comments and more actions removed for brevity [Init] name = default #port = ssh protocol = any 

注意我的端口variables是如何被注释掉的! 我不知道什么iptables会被喂食,我假设它是空白的。 不pipe它的价值如何,它不会成为iptables能够理解的已知端口。

我不得不编辑我的规则来删除–dport位,因为我实际上并不会传递一个端口,然后可以加载而不会导致它返回200。

今天我得到了同样的错误:

 2017-04-05 23:00:27,123 fail2ban.jail [501]: WARNING Jail name 'wordpress-404-scanner' might be too long and some commands (eg iptables) might not function correctly. Please shorten 2017-04-05 23:00:27,455 fail2ban.actions.action[501]: ERROR iptables -N fail2ban-wordpress-404-scanner iptables -A fail2ban-wordpress-404-scanner -j RETURN iptables -I INPUT -p tcp -j fail2ban-wordpress-404-scanner returned 200 

/etc/fail2ban/jail.local中replace是很明显的:

 action = iptables-allports[name=wordpress-404-scanner] 

有:

 action = iptables-allports[name=wordpress-404] 

现在它工作!