php - serious bug with random numbers -
php - serious bug with random numbers -
i create way reproduce bug having. when 2 or more users phone call page @ same sec modsecurity generates same sequence of random numbers (using rand() function php) both users.
here demonstration of bug:
http://quemfazsite.com.br/em_criacao/modelo9/teste.php
opening page, 2 iframes load , each 1 should generating random numbers independetly of each other both frames generating same sequence of random numbers! simple source code can seen below. if dont see same sequence inquire reload page few times till same number sequence.
edit: bug happens modsecurity active. if comment "loadmodule" line loads modsecurity bug wont happen!
<?php if (isset($_get["test"])) { $output= ""; ($i=0;$i<10;$i++) { $output.= rand(0,99999999) . "<br />"; } echo $output; exit(); } ?> <iframe src="put_the_same_name_of_this_file_here.php?test&953487"></iframe> <iframe src="put_the_same_name_of_this_file_here.php?test&234322"></iframe>
rand
not designed produce random numbers. purpose produce pseudorandom numbers distributed uniformly between given endpoints. if create histogram of numbers you've generated, you'll see indeed uniformly distributed.
the algorithm generates these numbers exclusively deterministic. if provide same seed (usually based on current time, in example) you'll same sequence of numbers. feature, not bug: allows exploit statistical properties of distribution while beingness able reproduce results afterwards reusing seed.
if need random numbers unpredictable, should using cryptographic rng.
if want robustly avoid clashes (caused colliding time-derived seeds), you'll have check against sort of cross-session storage ensure uniqueness (e.g. file or database). if application requires numbers unique, should doing anyway.
php apache
Comments
Post a Comment