Apache Tomcat before 5.5.35, 6.x before 6.0.35, and 7.x before 7.0.23 computes hash values for form parameters without restricting the ability to trigger hash collisions predictably, which allows remote attackers to cause a denial of service (CPU consumption) by sending many crafted parameters.
下面截图来自洪教授的 PPT,但内容的具体来源不详了(尝试找了下,没找到),大家参考参考就好。
实现 hash 冲突 DoS 攻击所须带宽
左边表示用不同的语言(框架)实现这种攻击所需要的带宽,右边是攻击的 cpu 目标。可以看出,实施这种攻击成本其实挺低的(后文石头的试验也佐证了这一点)。
More than the maximum number of request parameters (GET plus POST) for a single request ([10,000]) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.
post参数数量被限制
一种方法当然是去修改这个请求参数个数的限制。另外其实可以尝试用 JDK 1.7 去验证,应该效果会更好(原因,聪明的读者你肯定知道吧?)。这里石头哥就懒得去折腾了,直接尝试以量来取胜,用前文说的 ab 进行并发提交请求,然后观察效果。
这是我用如下参数跑的压测结果:
ab -c 200 -n 100000 -p req.txt 'localhost:8080/hash'
压测的结果如图所示:
ab 压测 hash 冲突结果
然后我们来看看 CPU 的变化情况,特意录屏做了个动图,可以看出还是相对比较明显的。从基本不占用 cpu 到 39.6%,然后突然就涨到 158% 了。
Application vulnerability due to Non Random Hash Functions: https://stackoverflow.com/questions/8669946/application-vulnerability-due-to-non-random-hash-functions
[4]
Hash Collision DoS 问题: https://coolshell.cn/articles/6424.html