Skip to content
Account takeover Disclosed report Intermediate

Authentication Bypass by abusing Insecure crypto tokens in /lib/OA/Dal/PasswordRecovery.php:

The password reset token is generated using PHP's uniqid(), which is predictable because it relies on the current time. An attacker who can guess the time of token generation can brute-force the token and reset an admin's password, leading to authentication bypass.

paulos__ Follow

Originally disclosed on HackerOne

  • Triaged in 3 hours
  • Fixed in 10 days
  • Disclosed after 11 days

Hi,

This is a fun bug I came across while doing a pentest for a client, after going through Revive Advserver's code for a few hours, I found this authentication bypass. This vulnerability seem to affect all versions, including the latest one, I was sent by one of your developers to report it here.

It goes like this:

In /lib/OA/Dal/PasswordRecovery.php:

PHP
50: function generateRecoveryId($userId)
{
$doPwdRecovery = OA_Dal::factoryDO('password_recovery');

    // Make sure that recoveryId is unique in password_recovery table
    do {
        $recoveryId = strtoupper(md5(uniqid('', true)));
        $recoveryId = substr(chunk_split($recoveryId, 8, '-'), -23, 22);
        $doPwdRecovery->recovery_id = $recoveryId;
        ....
 .....
....

That function is used to generate the password reset token used to create new password for admins. The token generated for changing password is insecure because it soley just relies on uniqid() which, according to PHP manual states:

"This function does not create random nor unpredictable string. This function must not be used for security purposes. Use cryptographically secure random function/generator and cryptographically secure hash functions to create unpredictable secure ID."

The reason being that the function does not generate cryptographically secure tokens, in fact without being passed any additional parameters the return value is little different from microtime(). If you need to generate cryptographically secure tokens use openssl_random_pseudo_bytes()

uniqid() is worse than the manual makes it out to be. An example return value is 58fc30c53db63 . Already, this is only <7 bytes of entropy. But it becomes worse, because without the more_entropy flag set, PHP only uses the current time to generate the return value, PHP code says:

C
sec = (int) tv.tv_sec;
usec = (int) (tv.tv_usec % 0x100000);
if (more_entropy) {
uniqid = strpprintf(0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg() * 10);
} else {
uniqid = strpprintf(0, "%s%08x%05x", prefix, sec, usec);
}

The first four bytes are the current UNIX timestamp, and the last 20 bits are derived from the current time in microseconds.

This gives a bit less than 2²⁰, or one million, possible results per given second. If you are able to predict when a new session key is generated for a user, you can guess their key with a decent number of requests, depending on how accurate your guess is. On a popular forum, you may not even need to target a specific user, as the number of users logging in at one time may be large enough.

And lucky for us, we can easily predict what Revive Adserver uses:

Ideally an attacker will look up the host IP of their target, locate the server's geoip and set their timezone similar to the server's timezone to make a more accurate prediction.

Making it more practical

When looking more closely I noticed, most servers that host Revive respond with the following headers:

HTTP/1.1 200 OK
Server: nginx
Date: Thu, 09 May 2019 21:26:20 GMT
Content-Type: application/x-javascript
Connection: close
Vary: Accept-Encoding
X-Cacheable: NO:Not Cacheable
Age: 0
X-Cache: MISS
X-Frame-Options: SAMEORIGIN
Content-Length: ...

Do you see it? It says Date: Thu, 09 May 2019 21:26:20 GMT -- so we can easily know what timezone the server syncs and uses (in this case GMT+0 as timezone) , all an attacker have to do is change their timezone to GMT, request a password reset token simultaneously as they they generate uniqid() from their side as well. All an attacker needs is the email address of the account they reset (which can be enumurated in numerous ways, including by abusing admin/password-recovery.php by sending some email addresses until it says Email Password Reset sent)

A PoC one would use can look like the following (except weaponized to request a password and generate the tokens simultaneously):

PHP
for($i=0;$i<=10000;$i++){

     $recoveryId = strtoupper(md5(uniqid('', true)));
     $recoveryId = substr(chunk_split($recoveryId, 8, '-'), -23, 22);

     print $recoveryId."</br>";

}

This generates 10,000 tokens we can try as a token to login as the admin by automating this with process with Burp Intruder.

You get the idea! :)

Suggested Fix

Relaying on more cryptographically secure functions like openssl_random_pseudo_bytes() is better for such sensitive tokens.

Impact

Authentication Bypass

Thanks,

The original report as published on HackerOne, by paulos__. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The password reset token is generated with uniqid(), which produces predictable values based on the current time rather than cryptographically secure randomness.

Impact

An attacker could bypass authentication and take over an admin account by predicting and brute-forcing the password reset token.

What the attacker needed

Email address of target account; ability to send many requests; knowledge of server timezone

The fix

The token generation should use a cryptographically secure random function such as openssl_random_pseudo_bytes() instead of uniqid().

How it was found

  1. Find the email address of the target admin account, for example by using the password recovery page to see if it says 'Email Password Reset sent'.
  2. Set your own timezone to match the server's timezone, which can be inferred from the Date header in HTTP responses.
  3. Request a password reset for the target email and simultaneously generate many possible tokens using the same uniqid() logic.
  4. Use a tool like Burp Intruder to try each generated token as the recovery ID until one works, allowing you to set a new password.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you reset a password, the system creates a secret code (token) to prove it's you. This code was made using a function that only looks at the current time, so it's easy to guess. An attacker can try many possible codes and take over an admin account.

What is Account takeover?

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.

More by paulos__

View all

16 more disclosed reports, best first.

More from Revive Adserver

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Account takeover

The lesson behind this report.

Getting into someone else's account through a flaw in sign-in, password reset, second factor, single sign-on or session handling.