2017-09-25 69 views
0

我们正在使用Suse Linux Enterprise Server 12.我们需要阻止并发IP地址,这些IP地址每秒触发我们的Web服务器超过50次,并阻止该IP地址持续10分钟。它也应该永远区分攻击者和真正的流量并阻止攻击者的IP。我们目前使用iptables阻止,下面是规则。IPTables脚本阻止并发连接

iptables -I INPUT -p tcp --dport 443 -i eth0 -m state --state NEW -m recent --set 
iptables -I INPUT -p tcp --dport 443 -i eth0 -m state --state NEW -m recent --update --seconds 1 --hitcount 50 -j DROP 

它只会阻止IPAddress超过50个连接,但不会将IPAddress黑名单。请让我们知道,如果我们有一个脚本,将符合上面提到的所有情况。请帮忙。

+0

如果请求(SYN)在1秒内超过50,您写入的规则将阻止来自同一IP地址的新连接。如果有,它会阻止IP地址1秒。你可以找到很多关于如何完成任务的例子。请注意,像这样的自动化IP黑名单的任何实施都容易通过欺骗源IP来拒绝服务。如果有人浏览器进入循环,无意中阻塞也会发生。 fail2ban是一个很好的工具,旨在解决您的问题。 –

回答

0

我测试了这个,它工作非常好。如果检测到该行为,则将IP保持10分钟并记录下来。您可以通过观看这些文件来验证它的操作。/proc/net/xt_recent/NICE,/ proc/net/xt_recent/NAUGHTY。您需要构建一个脚本来解析日志中的错误IP,并将它们提交给启动时加载到iptables中的文件,如果要永久性列入黑名单。这个概念已经很清楚了,所以我不需要包括它。

#flush and clear 
iptables -F -t nat 
iptables -F 
iptables -X 

#this is where naughty kids go 
iptables -N GETCAUGHT 

#you got added to the naughty list 
iptables -A GETCAUGHT -m recent --name NAUGHTY --set     #everyone here is bad 
iptables -A GETCAUGHT -j LOG --log-prefix "iwasbad: " --log-level 4 #and it goes on your permanent record 

#if you are on the NAUGHTY list you get a lump of coal         
iptables -A INPUT -i eth0 -m recent --name NAUGHTY --rcheck --seconds 600 -j DROP  #check everyone at the door 

#though everyone starts out on the NICE list 
iptables -A INPUT -i eth0 -p tcp --dport 443 -m conntrack --ctstate NEW -m recent --name NICE --set  #you seem nice 

#but if you GETCAUGHT doing this you are naughty 
iptables -A INPUT -i eth0 -p tcp --dport 443 -m conntrack --ctstate NEW -m recent --name NICE --seconds 1 --hitcount 50 --update -j GETCAUGHT #that wasn't nice 
+0

上面的脚本进行了一些更改。谢谢。 – user2693302

+0

命令“iptables -F”将刷新您的INPUT链。这是UFW和Fail2Ban存储他们的规则的地方 - 这样会破坏你的防火墙。即使你不使用UFW和Fail2Ban,大多数同等的服务也以同样的方式使用iptables。你可以在不调用iptables -F和iptables -X的情况下添加你的规则。我没有足够的知识来评论“iptables -F -t nat”,但会提供更多的研究和警告。 –