TARPIT可以用来浪费攻击者的资源,从而减缓攻击速度,降低攻击其他主机的能力……看起来不错。
它作为Netfilter 插件提供 ,可以像其他任何IPTables目标一样使用。
在处理(D)DoS的方法中是否存在缺点或漏洞?
我曾经认为这是一个好主意。 但现在我知道这是一个非常糟糕的主意,不幸的是。
你有没有运行一个像Apache Bench一样的http基准testing程序。 在一台机器上,您可以将其设置为每秒创build数百个连接到目标服务器。 让一些运行并连接到服务器的客户端启用tarpitting,我想你会看到一个问题。
考虑如果每个连接被困在一个tarpit中,如何每秒创build数千个连接到服务器的连接将会影响服务器。
您的服务器将快速使用所有可用的资源(或文件句柄),以便不允许有更多的连接。 这比closures连接更糟糕。 暂时放弃罪犯比试图绑定他的资源更好。 这是fail2ban实现的脚本。
另外,你永远不会希望你的普通用户被困在塔楼。 至less用于交互式会话。 你如何决定谁被允许,谁不是前期? 对于一些协议,你不能。 例如,HTTPstream量。 你必须假设一个客户是确定的,直到你从他们那里得到了另外的告诉你的活动。 那么你可以决定把它看成是坏的,下一次就会被困在油jar里。 这似乎是好的,除了这些攻击中的许多可能来自dynamic的adsl用户等谁刚刚得到了最新的蠕虫病毒。
由于蠕虫病毒在PC上发生了很多攻击,用户甚至无法知道并使用dynamic地址,最终可能会build立一个容易过时的黑名单。 你开始看到一些问题吗?
在通用服务器上运行tarpit确实会带来风险。 如果你知道什么风险,你可以缓解他们,这取决于你的舒适程度。
谢天谢地,这都是可能的,而且使用普通的iptables和ipset很容易。
您可以使用iptables来限制您使用TARPIT的主机数量,而无需使用太多的系统资源。 看下面的例子。 这包括networking带宽,系统内存,状态稳定条目和其他系统资源。 得到太多的tarpitted连接,开始忽略它们。 如果按照正确的顺序组织规则集,则没有任何一个tarpitted连接会在状态表中结束。 另外请确保你不logging,除非你正在做一些类似自定义ulog的实时统计 – 直接iptables tarpit日志可以快速填满磁盘。
根据我的经验,我现在的主机可以容易地在一个tarpit中容纳200多个主机,对内存使用量,stream量使用率或CPU使用率没有明显的影响。 可能我可以进一步推动这一点,但目前为止,平均而言,我只能在任何特定时刻捕捉到130个主机。
我之所以实行这个限制,是因为另一个build议,因为我的第一个临时主机被淹了。 这是一个微不足道的解决方法。 我从此没有问题。
ipset是一个很棒的小工具,可以让你创build一些在iptables规则中使用的对象。 不仅如此,而且由于它可以将对象保存在散列表中,因此ipset与等同的线性iptables规则集相比速度越快。
除此之外,这些列表还可以包括计数器(数据包/字节),超时和每个对象的排除。
你可以添加/删除ipset与大多数程序自动阻止,如fail2ban,ossec,等等。 因为您可以设置默认超时,所以无论程序如何设置条目,都可以确保条目已过期。
以下是一个基于我在我pipe理的服务器上使用的示例,可以减轻上面列出的风险:
### Note: This does not account for all possible traffic you might need or want ### This is only an example of mitigating common risks of using a tarpit ### Use at your own risk
# Create the ipset blacklist # options: # - create : create a new ipset # - blacklist : Name of the ipset we'll reference in the iptables rule # - hash:net : Make blacklist type hash to hold network (ip/mask) data # - family inet : This is for IPv4 data (inet6 for IPv6) # - counters : We want packet/byte stats counted for each entry # - comment : So we can add a comment with each entry (handy) # - timeout 604800 : Set a default timeout of 604800 seconds (1 week) for each new entry # - nomatch : Allow us to enter exclusion entries (never match an entry) ipset create blacklist hash:net family inet counters comment timeout 604800 nomatch # Create an entry to never blacklist a trusted network # options: # - timeout 0 : entry never expires # - nomatch : Tells IPset to never match this entry (whitelist, in our usage) ipset add blacklist 123.45.67.0/24 comment "Trusted subnet, causes breakage if blocked" timeout 0 nomatch # Example to blacklist hosts # no netmask implies /32 (or /128 for ipv6) ipset add blacklist 34.56.78.90 comment "SSH Bruteforce" ipset add blacklist 23.45.67.89 comment "SQL Injection" timeout 12345 # etc...
# Flush the input table iptables -F INPUT # Drop the custom flow TAR iptables -X TAR # Set default INPUT policy to DROP iptables -P INPUT DROP # Create the chain TAR iptables -N TAR # Send all blacklisted hosts to the tarpit iptables -A INPUT -m set --match-set blacklist src -j TAR # Allow established connections # Note: after the blacklist so newly blacklisted threats are immediately ignored # Yes, that will cause the server to hold the state open until it times out. # Would you rather have a malicious host continuing its attack? iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # Allow the services we want # Note: These create new state table entries/use up memory # Note: We do not account for synflood prevention in this example iptables -A INPUT -p tcp -m multiport --dports 22,80,443 -m tcp --syn -m conntrack --ctstate NEW -j ACCEPT iptables -A INPUT -p icmp -m icmp --icmp-type 8 -m conntrack --ctstate NEW -j ACCEPT # Send everything else to tarpit chain iptables -A INPUT -j TAR # This is the tarpit chain # Tarpit up to 10 unique connections a second, any more, and pass to next rule # Note: 10/s limit is arbitrary, adjust to your preference (experiment) iptables -A TAR -p tcp -m limit --limit 10/sec -j TARPIT --tarpit # Drop everything else that makes it this far # You can also set to REJECT which will immediately tell all connections to buzz off iptables -A TAR -j DROP
$ sudo tcpdump -npi eth0 'src YOUR.HOST.IP and (tcp[14] = 0 && tcp[15] = 0)'