我在添加针对暴力 SSH 攻击的规则时遇到问题。我尝试通过以下方式做到这一点:
iptables -F
iptables -L
iptables -N SSHATTACK
iptables -A SSHATTACK -j LOG --log-prefix "Possible SSH attack! " --log-level 7
iptables -A SSHATTACK -j DROP
#Block each IP address for 120 seconds which establishe more than three connections within 120 seconds. In case of the forth connection attempt, the request gets delegated to the SSHATTACK chain, which is responsible for logging the possible ssh attack and finally drops the request.
iptables -A INPUT -i venet0 -p tcp -m state --dport 22 --state NEW -m recent --set
iptables -A INPUT -i venet0 -p tcp -m state --dport 22 --state NEW -m recent --update --seconds 120 --hitcount 4 -j SSHATTACK
但我对这两行有一个问题:
iptables -A INPUT -i venet0 -p tcp -m state --dport 22 --state NEW -m recent --set
iptables -A INPUT -i venet0 -p tcp -m state --dport 22 --state NEW -m recent --update --seconds 120 --hitcount 4 -j SSHATTACK
该命令后的输出是
iptables: No chain/target/match by that name.
iptables -L
给出以下输出:
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain SSHATTACK (0 references)
target prot opt source destination
LOG all -- anywhere anywhere LOG level debug prefix `Possible SSH attack! '
DROP all -- anywhere anywhere
并iptables -S
给出:
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N SSHATTACK
-A SSHATTACK -j LOG --log-prefix "Possible SSH attack! " --log-level 7
-A SSHATTACK -j DROP
ip add
给出(我用“?”隐藏了 IP 地址):
1 lo LOOPBACK,UP,LOWER_UP mtu 65536 qdisc noqueue state UNKNOWN
linkloopback 000000000000 brd 000000000000
inet 127.0.0.18 scope host lo
inet6 1128 scope host
valid_lft forever preferred_lft forever
2 venet0 BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP mtu 1500 qdisc noqueue state UNKNOWN
linkvoid
inet 127.0.0.132 scope host venet0
inet ?.?.?.24820 brd ?.?.?.255 scope global venet00
我可以做什么来添加此规则?我缺少什么?
答案1
这是一个旧线程,但如果有人到达这里,这可能会有所帮助(为我解决)。
问题是缺少内核驱动程序。添加后
CONFIG_NETFILTER_XT_MATCH_RECENT=y
修改内核配置并重新编译,问题解决。您还可以将其添加为模块 (=m) 并在运行时对其进行 insmod
祝你好运!
答案2
该--dport
参数不属于state
匹配项。尝试:
iptables -A INPUT -i venet0 -p tcp --dport 22 -m state --state NEW -m recent --set