4

通过构造Hash冲突实现各种语言的拒绝服务攻击

 2 years ago
source link: https://www.laruence.com/2011/12/29/2412.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

通过构造Hash冲突实现各种语言的拒绝服务攻击

上周的时候Dmitry突然在5.4发布在即的时候, 引入了一个新的配置项:

  1. Added max_input_vars directive to prevent attacks based on hash collisions

这个预防的攻击, 就是"通过调用Hash冲突实现各种语言的拒绝服务攻击漏洞"(multiple implementations denial-of-service via hash algorithm collision).
攻击的原理很简单, 目前很多语言, 使用hash来存储k-v数据, 包括常用的来自用户的POST数据, 攻击者可以通过构造请求头, 并伴随POST大量的特殊的"k"值(根据每个语言的Hash算法不同而定制), 使得语言底层保存POST数据的Hash表因为"冲突"(碰撞)而退化成链表.

这样一来, 如果数据量足够大, 那么就可以使得语言在计算, 查找, 插入的时候, 造成大量的CPU占用, 从而实现拒绝服务攻击.
PHP5.4是通过增加一个限制来尽量避免被此类攻击影响:

  1.   - max_input_vars - specifies how many GET/POST/COOKIE input variables may be
  2.     accepted. default value 1000.

目前已知的受影响的语言以及版本有::

Java, 所有版本

JRuby <= 1.6.5

PHP <= 5.3.8, <= 5.4.0RC3

Python, 所有版本

Rubinius, 所有版本

Ruby <= 1.8.7-p356

Apache Geronimo, 所有版本

Apache Tomcat <= 5.5.34, <= 6.0.34, <= 7.0.22

Oracle Glassfish <= 3.1.1

Jetty, 所有版本

Plone, 所有版本

Rack, 所有版本

V8 JavaScript Engine, 所有版本

不受此影响的语言或者修复版本的语言有::

PHP >= 5.3.9, >= 5.4.0RC4

JRuby >= 1.6.5.1

Ruby >= 1.8.7-p357, 1.9.x

Apache Tomcat >= 5.5.35, >= 6.0.35, >= 7.0.23

Oracle Glassfish, N/A (Oracle reports that the issue is fixed in the main codeline and scheduled for a future CPU)

CVE: CVE-2011-4885 (PHP), CVE-2011-4461 (Jetty), CVE-2011-4838 (JRuby), CVE-2011-4462 (Plone), CVE-2011-4815 (Ruby)

原文: http://www.ocert.org/advisories/ocert-2011-003.html

45 Comments

  1. infected days
    infected days February 14, 2022

    I like this post, And I guess they are happy to read this post, they will get a good site to generate information, thanks for sharing it with me.

  2. fnaf world
    fnaf world June 11, 2020

    The website has great content and lots of information. I would love to read your web articles.

  3. Yola Riri
    Yola Riri September 9, 2018

    This article will help the internet visitors for setting
    up new webpage or even a weblog from start to end.

  4. 网站架构
    网站架构 December 27, 2017

    昨天看有个php网站是5.3的

  5. Wow! After all I got a weblog from where I be capable of
    genuinely take helpful information concerning my study and knowledge.

  6. Mammie
    Mammie October 9, 2014

    I have been exploring for a little for any high-quality
    articles or weblog posts in this sort of house . Exploring in Yahoo I ultimately stumbled
    upon this web site. Studying this information So i’m satisfied to convey that I have a very excellent uncanny feeling I came upon just what I needed.
    I most indubitably will make sure to do not overlook this web site and give it a glance regularly.

  7. Connor
    Connor October 8, 2014

    This article will help the internet visitors for setting
    up new webpage or even a weblog from start to end.

  8. […] [3] 通过构造Hash冲突实现各种语言的拒绝服务攻击 […]

  9. […] 5.3.8 爆出了严重漏洞,5.3.9在修复这个漏洞的同时引入了新的漏洞。而Debian […]

  10. […] 前日有信息显示当前包括PHP、Java、Ruby在内的很多语言版本存在漏洞,PHP官方开发组成员Laruence(新浪微博)表示攻击者可以通过构造Hash冲突实现拒绝服务攻击,并提供了实例。这个攻击方法危害很高,攻击成本也很小,一个台式机可以轻松搞垮数十台、上百台服务器。 […]

  11. […] 通过构造Hash冲突实现各种语言的拒绝服务攻击 […]

  12. […] 还记得我之前说的PHP Hash Collisions Ddos漏洞吧? 最初的时候, 开发组给出的修复方案, 采用的是如果超过max_input_vars, 就报错(E_ERROR), 继而导致PHP出错结束. 而后来, 为了更加轻量级的解决这个问题, 我们又改善了一下, 变成了如果超过max_input_vars, 就发出警告, 并且不再往目的数组添加, 但是流程继续. 然后我们发布了5.3.9. […]

  13. […] 最近安全领域出了很多新闻,从CSDN密码外泄开始,接踵而至。其中通过构造HASH冲突来拒绝服务涉及了大部分WEB开发语言(具体可以看 Laruence的文章),所以有必要将PHP更新到最新版本(目前是5.3.10)。不过这个过程并不怎么顺利,记录一下。 […]

  14. […] hash碰撞原理: http://www.laruence.com/2011/12/29/2412.html […]

  15. […] PHP版本升级到5.3.9,建议没有升级的赶快升级,防止受到Hash冲突拒绝服务攻击,可以参考 http://www.laruence.com/2011/12/29/2412.html,不过这么小的个人站点应该没有人有兴趣攻击。 […]

  16. […] 前几天看到公司php群谈到这篇博文通过构造Hash冲突实现各种语言的拒绝服务攻击,说的是在PHP中,使用hash来存储k-v数据, 包括常用的来自用户的POST数据, 攻击者可以通过构造请求头, 并伴随POST大量的特殊的”k”值(根据每个语言的Hash算法不同而定制), 使得语言底层保存POST数据的Hash表因为”冲突”(碰撞)而退化成链表. 这样一来, 如果数据量足够大, 那么就可以使得语言在计算, 查找, 插入的时候, 造成大量的CPU占用, 从而实现拒绝服务攻击. 举个例子:如下代码中: 123456789101112131415161718192021222324252627<?php $size = pow(2, 16); // 16 is just an example, could also be 15 or 17 $startTime = microtime(true); $array = array(); for ($key = 0, $maxKey = ($size – 1) * $size; $key <= $maxKey; $key += $size) {         $array[$key] = 0; } $endTime = microtime(true); echo 'Inserting ', $size, ' evil elements took ', $endTime – $startTime, ' seconds', "n"; $startTime = microtime(true); $array = array(); for ($key = 0, $maxKey = $size – 1; $key <= $maxKey; ++$key) {         $array[$key] = 0; } $endTime = microtime(true); echo 'Inserting ', $size, ' good elements took ', $endTime – $startTime, ' seconds', "n"; //http://www.laruence.com/2011/12/30/2435.html ?> […]

  17. […] 前几天,各个主流语言都爆出来了大Bug:“通过调用Hash冲突实现各种语言的拒绝服务攻击漏洞”(multiple implementations denial-of-service via hash algorithm collisio)。《通过构造Hash冲突实现各种语言的拒绝服务攻击》这篇文章提到PHP里引入了新的配置项,来限制GET/POST/COOKIE输入变量来减少攻击的影响。 […]

  18. […] hash碰撞原理: http://www.laruence.com/2011/12/29/2412.html […]

  19. fare
    fare January 6, 2012

    彻底的修改方法,就是改一下hash函数,在编译安装的时候,自动生成一个随机的p,hash的时候带上这个p,就很难构造退化的链表了。

  20. […] Laruence 的翻疑问 […]

  21. […] collision theory: http://www.laruence.com/2011/12/29/2412.html […]

  22. Joey Yin
    Joey Yin January 5, 2012

    JAVA下hash冲突生成代码请参考:http://www.unclejoey.com/?p=554

  23. hoho
    hoho January 4, 2012

    alert(‘test’)

  24. '
    ' January 4, 2012
  25. […] 年末传出动态语言大范围的 Hash DOS […]

  26. tanglei
    tanglei January 3, 2012

    这个,java怎么中招啊?
    求解释。
    java中的数组不会支持很大,受内存限制吧。
    不过在hashmap中,有类似的影响。不过相差不大。

  27. yc2266
    yc2266 January 2, 2012

    这个问题 百度可以共享一下 hi 空间里面的博文链接key 计算方式:
    http://hi.baidu.com/baidu/blog/item/b95bb39997ebc2166f068cec.html
    b95bb39997ebc2166f068cec 这个key的计算方式能保证在多少范围内不产生碰撞!(具体多少我也不知道)保证这个算法在一定范围的稳定性!

  28. upsuper
    upsuper January 2, 2012

    Python 似乎受影响不大,首先 Python 本身不解析大量外部数据,所以不存在类似 PHP 那样针对语言层面的攻击,过滤过多参数只需要相关框架增加选项即可。其次 Python 的 Hash 算法似乎并不容易用来大规模构造冲撞数据,构造难度跟纯枚举差不多,所以短期内被攻击的可能性不大。

  29. […] 通过构造Hash冲突实现各种语言的拒绝服务攻击 PHP数组的Hash冲突实例 深入理解PHP之数组(遍历顺序) Supercolliding a PHP array 哈希表(HashTable) PHP的哈希表实现   If you enjoyed this article, please consider sharing it! […]

  30. […] 原理(详见:http://www.laruence.com/2011/12/29/2412.html) […]

  31. […] 高危安全:Hash冲突导致PHP/JAVA/PYTHON等DDOS攻击 作者: xiuwz 日期: 2011 年 12 月 30 日 发表评论 (0) 查看评论 (No Ratings Yet)  Loading … 分享到: 更多 国外目前报出“multiple implementations denial-of-service via hash algorithm collision”,该hash冲突漏洞对目前所有的WEB动态开发语言都有危害,导致一个用户可以轻松通过构造数据而造成任何网站拒绝服务,从而引发DDOS相关攻击。中文版介绍请参考http://www.laruence.com/2011/12/29/2412.html。 […]

  32. […] Posts:PHP数组的Hash冲突实例通过构造Hash冲突实现各种语言的拒绝服务攻击更简单的重现PHP Core的调用栈GBK编码PHP脚本导致语法错误(Zend […]

  33. jw
    jw December 30, 2011

    hi,niaoge
    为啥不在每个bucket中加个指针指向链表结尾来解决问题,而是采用限制输入长度的方案
    thx

  34. mahone
    mahone December 30, 2011

    max_input_vars – specifies how many GET/POST/COOKIE input variables may be
    accepted. default value 1000.
    这个1000,是get,post,cookie这种加起来一共1000?还是get1000,post1000,cookie1000?

  35. kim
    kim December 30, 2011

    这不是基本上全部中招?

  36. […] […]

  37. 雪候鸟
    雪候鸟 December 30, 2011

    @Ferrari 恩,是一样的事情, 🙂

  38. 神仙
    神仙 December 30, 2011

    如果是用的rbtree之类就不会有这麻烦了吧

  39. Ferrari
    Ferrari December 30, 2011

    請問這篇的作者解釋的是同一個問題嗎?
    http://nikic.github.com/2011/12/28/Supercolliding-a-PHP-array.html

  40. aries
    aries December 29, 2011

    这个,现在有可行的方法来构造大量hash值相同的不同原文?

  41. sunvince
    sunvince December 29, 2011

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment

Name*

Email*

Website

Save my name, email, and website in this browser for the next time I comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK