Skip to content
Account takeover Write-up Intermediate

Trivial C# Random Exploitation

A web service generated password reset tokens using C#'s parameterless Random, which seeds from the system clock with 1ms resolution. An attacker could send two reset requests within the same millisecond to obtain identical tokens for their own account and a victim's account, leading to account takeover.

blog.doyensec.com

Published on blog.doyensec.com

Exploiting random number generators requires math, right? Thanks to C#’s Random, that is not necessarily the case!

Dennis Goodlett, on blog.doyensec.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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

How it worked

Root cause

The application used C#'s parameterless Random to generate password reset tokens, which seeds from the system clock with only 1ms resolution, making tokens predictable and duplicable within the same millisecond.

Impact

An attacker could take over any account, including an admin's, by obtaining a valid password reset token through a race condition.

What the attacker needed

Ability to send requests within 1ms; ideally two accounts you control for testing

The fix

The fix for weak PRNG vulnerabilities is to use a cryptographically secure random number generator instead of a time-seeded one.

How it was found

  1. Create two accounts on the website that you control.
  2. Use Burp's repeater groups to perform the single packet attack to reset both accounts.
  3. Check your email for duplicate tokens.
  4. If you fail, go on testing other stuff until the lockout window dies, then hit send again.
  5. Use testing accounts to obtain a delta time window that works.
  6. When launching the actual exploit, only attempt to log in when the delta time is within your testing bounds.

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 write-up has not been written yet. The Original tab links to the source.

A random number generator is supposed to produce unpredictable values, but C#'s Random class without a seed uses the current time as its starting point. If two requests arrive in the same millisecond, they get the same starting point and therefore the same 'random' token. An attacker can exploit this by sending two password reset requests at almost exactly the same moment, one for their own account and one for the victim's, and then use the token they received to reset the victim's password.

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.

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.