Live data from Hacker News

Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

spideroak.com

21–30 of 40 posts

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#21
A PRNG based on RC4 should be very fast but much more secure than a MT or a LCG.

EDIT: also it is very important to seed with care if you are interested in security. Even a strong PRNG seeded with seed_prng(time(NULL)) will be an easy target for brute force attacks.

At least /dev/urandom should be used for seeding purposes in applications where you need an unguessable PRNG.

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#22
post #13

This is a pretty great post. We need lots more posts on practical exploit development for RNG flaws, because there are a lot of bad random number generators out there. I want to respond to this headline, though. Use of MT as a CSPRNG is very, very common in PHP applications. And it's also true that MT is the algorithm used by Ruby for it's "rand". But this is not a very common Ruby flaw, at least not like it is in PH…

Is there any advice you're able to give on how to distinguish situations where you need secure RNG from those that don't matter?

For instance, you definitely need it in poker hand generation - would you need it for random loot generation in an MMO?

Also by "secure" you mean /dev/random, and /dev/urandom is used as if it was rand()?

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#23
post #22
post #13

This is a pretty great post. We need lots more posts on practical exploit development for RNG flaws, because there are a lot of bad random number generators out there. I want to respond to this headline, though. Use of MT as a CSPRNG is very, very common in PHP applications. And it's also true that MT is the algorithm used by Ruby for it's "rand". But this is not a very common Ruby flaw, at least not like it is in PH…

Is there any advice you're able to give on how to distinguish situations where you need secure RNG from those that don't matter? For instance, you definitely need it in poker hand generation - would you need it for random loot generation in an MMO? Also by "secure" you mean /dev/random, and /dev/urandom is used as if it was rand()?

You should pretty much just default to secure random.

/dev/urandom is fine; in Ruby apps, I'd use OpenSSL::Random.random_bytes or ActiveSupport::SecureRandom.random_number.

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#24
post #21

A PRNG based on RC4 should be very fast but much more secure than a MT or a LCG. EDIT: also it is very important to seed with care if you are interested in security. Even a strong PRNG seeded with seed_prng(time(NULL)) will be an easy target for brute force attacks. At least /dev/urandom should be used for seeding purposes in applications where you need an unguessable PRNG.

RC4-based CSPRNGs were an OpenBSD idiom. But you should use your OS's or your framework's secure random number generator in preference to arc4random(), because there's more to the security of a good CSPRNG than just the algorithm it to jumble up its internal state.

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#25
post #21

A PRNG based on RC4 should be very fast but much more secure than a MT or a LCG. EDIT: also it is very important to seed with care if you are interested in security. Even a strong PRNG seeded with seed_prng(time(NULL)) will be an easy target for brute force attacks. At least /dev/urandom should be used for seeding purposes in applications where you need an unguessable PRNG.

> At least /dev/urandom should be used for seeding purposes in applications where you need an unguessable PRNG.

I usually consume /dev/urandom and convert it to the base I require, using that directly as my random number. When you say you should use it for seeding purposes, are you referring to using /dev/urandom as a seed for something like PHP's rand(), or do you mean something else?

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#26
post #19
post #6

Indeed as the author rightfully mentioned in his article this method is not designed for crypto purpose. One can use the following Python method instead random.SystemRandom().randint(...)

SystemRandom uses the system's urandom, which may not be ideal, either. (The man page for urandom mentions theoretical problems when system entropy pools are depleted.) The PyCrypto.Random.random option mentioned in another thread by wulczer might be better... but would love an authoritative recommendation from an expert.

You should probably use your system urandom/random in preference to any application-layer CSPRNG. Your OS developers are charged with maintaining a high-profile high-value CSPRNG used for most applications on the system, and vulnerabilities in it are a hair-on-fire problem. The same is not true of application-layer replacements. The kernel RNG is also in a privileged position to collect entropy.

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#27
post #21

A PRNG based on RC4 should be very fast but much more secure than a MT or a LCG. EDIT: also it is very important to seed with care if you are interested in security. Even a strong PRNG seeded with seed_prng(time(NULL)) will be an easy target for brute force attacks. At least /dev/urandom should be used for seeding purposes in applications where you need an unguessable PRNG.

> At least /dev/urandom should be used for seeding purposes in applications where you need an unguessable PRNG. I usually consume /dev/urandom and convert it to the base I require, using that directly as my random number. When you say you should use it for seeding purposes, are you referring to using /dev/urandom as a seed for something like PHP's rand(), or do you mean something else?

Seeding is largely a problem you have if you're building (or retrofitting in) your own CSPRNG, which you shouldn't do. The random/urandom interface Unixes provide will allow you to shovel in high-entropy data, but I think you're more likely to do harm than good (it's a marginal impact in either direction, though).

You're doing the right thing already.

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#28
post #11

http://news.ycombinator.com/item?id=639976

That post, which is great, is the normal way bad RNGs are broken by attackers: you trace down how they're seeded and then brute force the seed values.

What's great about this blog post is that it attacks the underlying algorithm; the post you linked to is more fun, but this post is a little more useful.

In either case: just use random/urandom and this stuff is taken care of for you.

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#29
post #13

This is a pretty great post. We need lots more posts on practical exploit development for RNG flaws, because there are a lot of bad random number generators out there. I want to respond to this headline, though. Use of MT as a CSPRNG is very, very common in PHP applications. And it's also true that MT is the algorithm used by Ruby for it's "rand". But this is not a very common Ruby flaw, at least not like it is in PH…

In Python os.urandom provides random string suitable for cryptographic use.

Re: Exploit Information Leaks in Random Numbers from Python, Ruby and PHP

#30
post #23
post #22

Earlier quoted context omitted.

Is there any advice you're able to give on how to distinguish situations where you need secure RNG from those that don't matter? For instance, you definitely need it in poker hand generation - would you need it for random loot generation in an MMO? Also by "secure" you mean /dev/random, and /dev/urandom is used as if it was rand()?

You should pretty much just default to secure random. /dev/urandom is fine; in Ruby apps, I'd use OpenSSL::Random.random_bytes or ActiveSupport::SecureRandom.random_number.

What cases do you reserve /dev/random for? SSH keygen?

Do those functions just read from /dev/urandom?

Post reply on HN