简体   繁体   English

Python -R函数

[英]Python -R function

While scrolling through all python options, I found that python contains an option to "[turns] on hash randomization, so that the __hash__() values of str, bytes and datetime objects are “salted” with an unpredictable random value. Although they remain constant within an individual Python process, they are not predictable between repeated invocations of Python." 滚动浏览所有python选项时,我发现python包含一个选项,可以“ [turns]进行散列随机化”,这样str,bytes和datetime对象的__hash__()值会以不可预测的随机值“成盐”。在单个Python进程中保持不变,因此在重复调用Python之间无法预测它们。” (source) . (来源)

The official documents refer this document http://www.ocert.org/advisories/ocert-2011-003.html that is supposed to provide more information, however, it doesn't provide any information what such a "crafted HTTP requests" looks like. 正式文档参考该文档http://www.ocert.org/advisories/ocert-2011-003.html ,该文档应提供更多信息,但是,它不提供任何信息,例如“精心设计的HTTP请求”看起来像。 All relevant links on the site are dead. 该站点上的所有相关链接均已失效。 I know that this can be fixed by calling python -R , however, I'm more interested in the details. 我知道可以通过调用python -R来解决此问题,但是,我对细节更感兴趣。
How can one HTTP request make 100% of the server CPU for several hours and how can randomizing the hash value fix that? 一个HTTP请求如何在几个小时内占据100%的服务器CPU,如何将哈希值随机化可以解决此问题? Is it creating some kind of a dead lock? 它会造成某种死锁吗? (I know that a HTTP request can take long if the script is broken (infinity for/while loop, goto s) or is doing a very expensive task but I assume that this isn't the case). (我知道,如果脚本中断(无限for / while循环, goto s)或正在执行非常昂贵的任务,则HTTP请求可能会花费很长时间,但我认为情况并非如此。

Salting hash with an unpredictable salt is used to prevent collision attacks . 将盐与不可预测的盐混合使用以防止碰撞攻击

A collision attack, in one world, is an attack targeting the hash table algorithm, which normally operates in O(1), but can be tricked to operate in O(n). 在一个世界中,碰撞攻击是针对哈希表算法的攻击,该算法通常在O(1)中运行,但可以被欺骗以在O(n)中运行。

Tricking an hashtable algorithm is simple: An hashtable implementation is usually slower when storing objects having a common hashed value, it's named a collision. 欺骗哈希表算法很简单:在存储具有公共哈希值的对象(称为冲突)时,哈希表实现通常较慢。 It's slower because the two values are stored together, for exemple, in a linked list. 速度较慢,因为例如两个值存储在链接列表中。 So if you can produce a large quantity of keys that ALL collide, you're forcing the hashtable to store them all in a linked list, which is damn slow and eats a lot of CPU. 因此,如果您可以产生大量的所有键冲突的键,则您将强制哈希表将所有键存储在链接列表中,这真是太慢了,而且会占用大量CPU。

To exploit this, you have to know the hash algorithm, to be able to predict and generate conflicting keys. 要利用这一点,您必须了解哈希算法,以便能够预测并生成冲突的密钥。 If the hash is salted by a value you don't know, you'll not be able to generate colliding keys. 如果哈希值被您不知道的值加盐,则将无法生成冲突键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM