Original link
This is the first attack method that scares me so far. It covers a wide range and is difficult to defend against, and the attack effect is immediate. A large number of websites and web interfaces are not protected against Hash collision attacks.
With the popularity of RESTful-style interfaces, programmers will use json as the data transfer method by default. The json format has less data redundancy and high compatibility. It has been widely used since it was proposed and can be said to have become a standard on the Web. No matter what language we use on the server side, after we get the data in json format, we need to do jsonDecode() to convert the json string into a json object. The object will be stored in the Hash Table by default, and the Hash Table is easily vulnerable to collision attacks. As long as I put the attack data in json, the server program will be infected when doing jsonDecode(). After being infected, the CPU will immediately surge to 100%. With a 16-core CPU, 16 requests can achieve the purpose of DoS.
All test programs are conducted under Mac Pro. For the convenience of testing, I only constructed 65536 json key-value pairs. When actually launching an attack, hundreds of thousands or even millions of data can be constructed.
I have converted the attack data to json format
//只需要一行代码就能看到效果var jsonSrc = '这里输入json数据';
Through the task manager that comes with Chrome, you can see that the CPU immediately rises to 100%, and it takes nearly 1 minute to complete the execution, while ordinary data can be completed in a few milliseconds;
$json = file_get_contents("https://raw.githubusercontent.com/laynefyc/php_thread_demo/master/hashNomal.json"); $startTime = microtime(true); $arr = json_decode($json,true); $endTime = microtime(true); echo "Nomal:".($endTime - $startTime)."\r\n"; $json = file_get_contents("https://raw.githubusercontent.com/laynefyc/php_thread_demo/master/hash.json"); $startTime = microtime(true); $arr = json_decode($json,true); $endTime = microtime(true); echo "Attack:".($endTime - $startTime)."\r\n";
public String index(){String jsonStr = "";try { FileReader fr = new FileReader("t.log");//需要读取的文件路径BufferedReader br = new BufferedReader(fr); jsonStr = br.readLine(); br.close(); fr.close(); //关闭文件流 }catch(IOException e) { System.out.println("指定文件不存在");//处理异常 } Map<String, Object> map = new HashMap<String, Object>();map = JSONObject.fromObject(jsonStr);return "Hash Collision ~"; }
After the server gets the data, it will store all parameters in the Hash Table ($_POST), the attack can be easily implemented in this way. But now this method does not work, because we can easily limit the number and size of HTTP request parameters at the Nginx layer and PHP layer. PHP only allows 1000 parameters by default, which has no impact on the server at all. Now is 2017, json format and RESTful style interface have become very popular. While bringing us convenient coding, it also provides a new way for Hash Collision Dos. Now many RESTful style interfaces are as follows:Post Data: k1=0&k2=0&k3=0...k999998=0&k999999=0
As shown in the above interface, we directly put the attack data into the data parameter. After receiving the data, the server will definitely do jsonDecode(), which easily achieves the purpose of the attack. How to defendTo defend against Hash Collision Dos attacks, there are already many mature solutions in the industry, but they all recommend changing the language or rewriting the HashTable. Here we only talk about the current json format parsing issues. First, we need to add permission verification to reject illegal users as much as possible before jsonDecode(). Secondly, perform data size and parameter whitelist verification before jsonDecode(). If the cost of transformation and maintenance of old projects is high, it is recommended to rewrite the jsonDecode() method yourselfData: {"action":"create-account","data":""}
The above is the detailed content of An advanced DoS attack-Hash collision attack. For more information, please follow other related articles on the PHP Chinese website!