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,但內容的具體來源不詳了(嘗試找了下,沒找到),大家參考參考就好。實現(xiàn) hash 沖突 DoS 攻擊所須帶寬左邊表示用不同的語言(框架)實現(xiàn)這種攻擊所需要的帶寬,右邊是攻擊的 cpu 目標??梢钥闯?,實施這種攻擊成本其實挺低的(后文石頭的試驗也佐證了這一點)。不得不說 “PHP 是世界上最好的編程語言”(大家別打架),還是有一定道理的,哈哈哈哈哈哈 ?(一張圖還不夠,再加一張)上面的語言排序,不一定對,大家參考一下即可,不用糾結具體的準確性。其實要驗證,方法當然也相對簡單,只要找出產生沖突的不同字符串即可,具體語言可能不一樣。
具體生成過程本文不詳述了,感興趣可以看看 StackOverflow 上的這篇文章 Application vulnerability due to Non Random Hash Functions[3],或者參考耗子叔的這篇 Hash Collision DoS 問題[4]。然后我啟用一個 SpringBoot(2.2.2.RELEASE) 的 Web 服務,JDK 1.8(其實用 1.7 效果更明顯)。
先試水一把(如下圖),看看基本功能正常,用 curl 發(fā)送請求即可,然后將 post 的字段放在文件里面(太長也只能放文件中)。curl 實驗結果生成的字符串不夠的話,還可以增加并發(fā)請求,可以借用類似 “Apache Benchmarking” 壓測的工具發(fā)送請求,我之前也有一篇文章介紹了這個命令 性能測試工具 - ab 簡單應用,感興趣的可以參考一下。沖突的 hashcode 一樣打個斷點看看效果,如上圖所示,確實所有的 hash 值都是一樣的。不過一次請求好像并沒有影響我電腦 cpu 的明顯變化。我測試的字符串已經是 29859 個了,正準備生成更多的沖突的字符串進行嘗試時,結果仔細一看才發(fā)現(xiàn)請求被截斷了,請求返回的參數(shù) size 大小為 10000。原來 SpringBoot 內置的 tomcat 給做了手腳,看下圖,因為默認的請求的參數(shù)個數(shù)大小被限制成 10000 了。
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參數(shù)數(shù)量被限制一種方法當然是去修改這個請求參數(shù)個數(shù)的限制。另外其實可以嘗試用 JDK 1.7 去驗證,應該效果會更好(原因,聰明的讀者你肯定知道吧?)。這里石頭哥就懶得去折騰了,直接嘗試以量來取勝,用前文說的 ab 進行并發(fā)提交請求,然后觀察效果。這是我用如下參數(shù)跑的壓測結果:
[1]?oCERT-2011-003 multiple implementations denial-of-service via hash algorithm collision:?http://ocert.org/advisories/ocert-2011-003.html[2] CVE-2011-4858:?https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2011-4858[3] 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