BugTraq
Flaw in commonly used bash random seed method Apr 02 2006 03:12AM
coderpunk (coderpunk gmail com) (1 replies)
I think I just discovered a flaw in what appears to be a common way to
see bash's $RANDOM function. bash provides a pseudo-random number,
from 0-32767, using the $RANDOM function. You can seed this by setting
RANDOM=42 or some other number. Otherwise it is seeded by the process
id and time.

There are a plethora of usenet and web posts that suggest using the
following to seed the function:
SEED=$(head -1 /dev/urandom | od -N 1 | awk '{ print $2 }')

But look at the output, and the manpage for od. All this is doing is
reading 1 line of /dev/urandom (a binary stream), passing it to od
which is taking 1 byte and converting it to octal and printing it with
awk. What's wrong with this picture? You've just taken a random source
and turned it into a number from 0-255!

I hope you haven't been generating your password lists with any of the
scripts using that seed method.

Here is a better way:

SEED=$(head -c4 /dev/urandom | od -t u4 | awk '{ print $2 }')

This reads 4 bytes from /dev/urandom, passed it to od which converts
it into a unsigned 4 byte integer and prints it. This should have a
range of 2**32 (4294967296L) which is a bit more secure than 0-255.

.cp

[ reply ]
Re: Flaw in commonly used bash random seed method Apr 03 2006 07:56PM
Matthijs (thotter gmail com) (2 replies)
Re: Flaw in commonly used bash random seed method Apr 04 2006 01:22PM
Dave Korn (davek_throwaway hotmail com) (1 replies)
Re: Flaw in commonly used bash random seed method Apr 05 2006 05:32PM
Steve VanDevender (stevev hexadecimal uoregon edu)
Re: Flaw in commonly used bash random seed method Apr 04 2006 08:21AM
Dave English (dave english thus net) (1 replies)
Re: Flaw in commonly used bash random seed method Apr 04 2006 02:47PM
Matthijs (thotter gmail com)


 

Privacy Statement
Copyright 2010, SecurityFocus