Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is using microtime() to generate password-reset tokens bad practice

In PHP I've noticed some frameworks make use of the microtime() function to generate password reset tokens as in:

  $token = md5(microtime());

Is this a security issue? If the attacker is able to synchronize the clocks with the server to a degree of accuracy they could brute force the token. 1sec synchronization will only require 1,000,000 tries and this is not too crazy of an issue.

How likely is this attack to succeed? Should one be generating tokens with /dev/urandom or openssl_pseudo_bytes() instead? Is microtime() bad practice?

like image 597
user2072710 Avatar asked Mar 20 '13 15:03

user2072710


1 Answers

Yes it is a security issue! Generating tokens with time is a very bad practice. Burp Suite makes it trivial for an attacker to brute force tokens that are predictable, and tokens based on time are very predictable. Burp allows someone to easily gather tokens and perform statistical analysis on them to determine entropy. Using this info you can easily predict future tokens.

Remember, the attacker only needs to get it right once. Getting it wrong millions of times makes no difference.

Here is a useful (and recent) StackOverflow post about token generation that may be helpful to you: REST Web Service authentication token implementation

like image 163
Freedom_Ben Avatar answered Nov 01 '22 21:11

Freedom_Ben