Skip to content
Account takeover Write-up Intermediate

Pre-Account Takeover by Reversing a Weak Email Verification Token Algorithm

The email verification token was built from two sequential numeric values that only increased between tokens, so an attacker could create accounts just before and after a victim's address to bracket the valid token and brute-force it. This let the attacker verify any email address they did not own, enabling pre-account takeover once the real owner signed in with a linked login method.

Craig Hays Follow

Published on craighays.com

I spoofed access to other people’s email in order to pre-steal user accounts before they are first registered. Here’s how I did it.

Craig Hays (@craighays), on craighays.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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 6 min read.

Context

The target was a private bug bounty program, according to the report. The application required every new user to verify ownership of their email address before the account could be used: on sign-up it sent a verification link by email and would not let the user proceed until that link was opened. The report notes that forcing this validation is exactly what prevents pre-account takeovers, so the verification step was the security control worth attacking.

A pre-account takeover, as described in the report, works like this:

  1. The attacker creates a user account using an email address they do not own.
  2. The application does not verify that they own the address.
  3. The account sits dormant.
  4. The real owner later signs in with a second method, for example 'Sign in with Facebook', and the provider supplies the validated email address.
  5. The application links the two accounts because the email addresses match.
  6. The attacker can now log in with the email address and password they chose, and sees everything the victim does inside the account.

The report lists the common login methods that make this possible: username and password, email address and password, OAuth providers such as Facebook or Twitter, SAML single sign-on from an identity provider, and passwordless magic links. The application in question already linked email/password accounts with Facebook accounts that shared an email address.

Setup

The researcher's routine on any scoped application was to start with account creation and authentication. For this test the tooling was three separate browser profiles, plus Burp Intruder to hold the account creation requests and release them one after another. No versions are given in the report.

Finding it

After registering, the researcher received a 'confirm your account' email and copied the link into a text editor. All one-time links received during testing were saved together with the account name, email address and registration time, so that patterns could be spotted later.

The link had this format (the report writes it without the spaces):

Text
https://craighays.com/verify/?P1=randomString &P2=randomString &P3=staticText &P4=staticText

After generating several verification emails for different accounts, P3 and P4 were always the same, while P1 and P2 changed on every email. Removing or altering P1 or P2 and then opening the link produced an error message and the address was not verified, so the pair together formed a two-part ownership token.

Both P1 and P2 were base64 encoded. The report points out the usual tell: a random-looking string ending in a single = or double ==, the padding used to bring the pre-encoded string up to the required bit length, though a string of exactly the right length needs no padding. Decoding several P1 and P2 values from different links showed a fixed structure:

Parameter Decoded format Example
P1 four static characters followed by 12 numerical characters TEXT000123456789
P2 9 numerical characters 123456789

The numbers were incrementing, moving up in large steps from one verification link to the next. P1 and P2 were not correlated in any other way: both simply went up.

Exploitation

Step 1: try to guess from timestamps

The first attempt was to guess the numbered strings from the timestamps in the HTTP response. The report says this got nowhere.

Step 2: bound the search space

The idea that worked was to define an upper and lower bound around the token belonging to the target address. The mathematics: P1's twelve-digit number always started with 000, so it was effectively 9 digits, and P2 was 9 digits. A 9 digit number has 1,000,000,000 possible values, so a token had 1,000,000,000 * 1,000,000,000 combinations. The weakness was ordering: within each generated token, P1 and P2 were greater than the previous token's values and lower than the next token's. Generating a token that can be seen, then one that cannot, then another that can be seen, brackets the unknown value and shrinks the range enormously.

The attack sequence:

  1. Create an account with an email address I own
  2. Create an account with the email address I don't own, but want to validate

Step 3: create the three accounts

To prove the bypass, the researcher chose to validate their own name at the target company's domain. Three browser profiles were taken through the account creation process to the last page. Using Burp Intruder to hold the requests and release them one after another as quickly as possible, the 'create account' form was submitted on all three, with the address at the company domain in the middle. Two verification emails arrived, one for each address the researcher owned; the middle one went to an address they had no access to.

Step 4: extract the bounds

From the two received links, the P1 and P2 values gave these bounds:

Text
LowerP1: 000148309914
UpperP1: 000148309953

LowerP2: 187633910
UpperP2: 187634120

P1 Range: 39
P2 Range: 210

Possible combinations: 8,190

8,190 candidates instead of 1,000,000,000 * 1,000,000,000 = 1.0e18.

Step 5: brute force the range

The script logic, reproduced as the report gives it (the report notes it is pseudo code that will not run and only summarises the logic):

Python
for P1 in range (LowerP1..UpperP1):
  for P2 in range (LowerP2..UpperP2):
    P1 = "TEXT000" + string(P1)
    P1 = base64encode(P1)
    P2 = base64encode(P2)
    url = buildURL(P1, P2)
    getUrl(url)

# Note, this is pseudo code - it won't actually run but
# it summaries the script logic into a readable form

buildURL() added P3, P4 and the rest of the URL. An HTTP GET request was then sent for each of the 8,190 possible two-part tokens between the bounds until the target address was validated.

Step 6: result

The address at the company domain was validated, proving the bypass. Because the application already linked email/password accounts with Facebook accounts sharing an email address, no further proof was needed; a simple explanation of the behaviour was enough for the bug bounty report. As a side effect, the run also validated a few other addresses created by members of the public that happened to fall inside the bounds at the time of testing.

Root cause

The token was built from two sequential numbers, base64 encoded. The only thing protecting a token was the size of the number space, and the ordering of generated tokens collapsed that space to a few thousand candidates once two tokens either side of the target could be observed. The application did enforce verification, which is the right control, but the token it issued was predictable. The report notes that the password reset method already used a long random string, but the developers reinvented the token process for email verification.

Impact

The verification requirement could be bypassed, so an account could be used without being tied to a real email address. Pre-account takeovers were possible on any email address that was not already registered: the attacker registers first with a password of their choice, ready for when the real owner later signs in with Facebook, Twitter or another provider. The report limits this to addresses that were not already registered.

Fix

The recommended remediation is to replace P1 and P2 with a really long and random string of characters, removing sequential numbers from the token generation algorithm. The report does not say whether the fix was applied.

Variants to test

  • Decode every token parameter (base64, hex, URL encoding) and look for structure: fixed prefixes, counters, timestamps. A positive result is a decoded value that increments between successive tokens.
  • Register three accounts in quick succession, the middle one on an address you do not control, and compare the outer tokens. A small numeric gap between them means the middle token is brute-forceable.
  • Check whether the same weak generator is used for password reset, magic links, invitations or API keys. A positive result is a reset or magic-link token with the same sequential structure.
  • Test whether the application links accounts by email across login methods without requiring verification. A positive result is an account created with an unverified address being merged with a later OAuth login on the same address.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 12 min read.

What happened, in plain words

A security researcher was testing a website that was part of a private bug bounty program. A bug bounty program is a scheme where a company invites outside testers to look for security weaknesses in its systems and report them, usually for a reward. The researcher found that the website sent new users an email with a link to click, to prove the email address really belonged to them. The link contained a code, called a token. A token is a short piece of text that a website uses to recognise something, a bit like a cloakroom ticket: whoever holds the ticket gets the coat. The researcher worked out how those tokens were built, and found they were made from numbers that simply counted upwards. By creating a few accounts in a row and comparing the tokens, the researcher could narrow down the possible token for an email address they did not own, then try every candidate until one worked. That let them prove ownership of an address they had no access to. Because the site joined accounts that shared an email address, this opened the door to taking over someone's account before they had even signed up. The report calls this a pre-account takeover.

Why email verification matters

The first thing the researcher tests on any application in scope is account creation and login. On this occasion, the application would not let a new user do anything until they had verified ownership of their email address. On sign-up it emailed a verification link and waited for the user to open it. The report notes that forcing this validation is exactly what prevents pre-account takeovers, so the verification step was the security control worth attacking.

A pre-account takeover, as the report describes it, works like this:

  1. The attacker creates a user account using an email address they do not own.
  2. The application does not verify that they own the address.
  3. The account sits dormant.
  4. The real owner later signs in with a second method, for example 'Sign in with Facebook', and the provider supplies the validated email address.
  5. The application links the two accounts because the email addresses match.
  6. The attacker can now log in with the email address and password they chose, and sees everything the victim does inside the account.

The report lists the common login methods that make this possible: username and password, email address and password, OAuth providers such as Facebook or Twitter, SAML single sign-on from an identity provider, and passwordless magic links. OAuth is a way for one website to ask another, such as Facebook, to confirm who you are, so you do not need a separate password. SAML single sign-on is a similar idea used by companies, where one central login system vouches for you across many applications. A magic link is a one-time link emailed to you that logs you in when clicked, with no password. The application in question already linked email/password accounts with Facebook accounts that shared an email address.

Setting up the test

The researcher's routine on any scoped application was to start with account creation and authentication. For this test the tooling was three separate browser profiles, plus Burp Intruder to hold the account creation requests and release them one after another. A browser profile is a separate set of cookies and saved data inside a browser, so you can be logged in as different users at the same time. Burp Intruder is a tool that sends many web requests automatically, and can be told to pause them and send them in a chosen order. No versions are given in the report.

Finding the weak token

After registering, the researcher received a 'confirm your account' email and copied the link into a text editor. All one-time links received during testing were saved together with the account name, email address and registration time, so that patterns could be spotted later. This is a simple habit: keep a record of what the site sends you, because repeated values often reveal how the site builds them.

The link had this format (the report writes it without the spaces):

Text
https://craighays.com/verify/?P1=randomString &P2=randomString &P3=staticText &P4=staticText

Line by line: the first part, https://craighays.com/verify/, is the address of the page that checks the token. The ? marks the start of the parameters, which are named values passed to the page. P1=randomString is the first parameter, whose value looked random. &P2=randomString is the second parameter, also looking random. &P3=staticText and &P4=staticText are two more parameters whose values never changed. The spaces in the report's version are just for readability; the real link had none.

After generating several verification emails for different accounts, P3 and P4 were always the same, while P1 and P2 changed on every email. Removing or altering P1 or P2 and then opening the link produced an error message and the address was not verified, so the pair together formed a two-part ownership token. In other words, the site needed both halves to match before it would believe you owned the address.

Both P1 and P2 were base64 encoded. Base64 is a way of writing any data using only letters, digits and a couple of symbols, so it can travel safely in a web address. The report points out the usual tell: a random-looking string ending in a single = or double ==, the padding used to bring the pre-encoded string up to the required bit length, though a string of exactly the right length needs no padding. Decoding several P1 and P2 values from different links showed a fixed structure:

Parameter Decoded format Example
P1 four static characters followed by 12 numerical characters TEXT000123456789
P2 9 numerical characters 123456789

The numbers were incrementing, moving up in large steps from one verification link to the next. P1 and P2 were not correlated in any other way: both simply went up. That is the weakness: a token that only counts upwards is predictable, because seeing one value tells you roughly what the next one will be.

Trying to exploit it

Step 1: try to guess from timestamps

The first attempt was to guess the numbered strings from the timestamps in the HTTP response. A timestamp is the time recorded in the reply the server sends back. The idea was that the numbers might be derived from the clock. The report says this got nowhere.

Step 2: bound the search space

The idea that worked was to define an upper and lower bound around the token belonging to the target address. The mathematics: P1's twelve-digit number always started with 000, so it was effectively 9 digits, and P2 was 9 digits. A 9 digit number has 1,000,000,000 possible values, so a token had 1,000,000,000 * 1,000,000,000 combinations. That is a huge number, far too many to try one by one. The weakness was ordering: within each generated token, P1 and P2 were greater than the previous token's values and lower than the next token's. Generating a token that can be seen, then one that cannot, then another that can be seen, brackets the unknown value and shrinks the range enormously. It is like guessing a page number in a book: if you know the page before and the page after, you only have to check the few pages in between.

The attack sequence:

  1. Create an account with an email address I own
  2. Create an account with the email address I don't own, but want to validate

Step 3: create the three accounts

To prove the bypass, the researcher chose to validate their own name at the target company's domain. Three browser profiles were taken through the account creation process to the last page. Using Burp Intruder to hold the requests and release them one after another as quickly as possible, the 'create account' form was submitted on all three, with the address at the company domain in the middle. Two verification emails arrived, one for each address the researcher owned; the middle one went to an address they had no access to.

Step 4: extract the bounds

From the two received links, the P1 and P2 values gave these bounds:

Text
LowerP1: 000148309914
UpperP1: 000148309953

LowerP2: 187633910
UpperP2: 187634120

P1 Range: 39
P2 Range: 210

Possible combinations: 8,190

Line by line: LowerP1 is the P1 value from the first account, the one created before the target. UpperP1 is the P1 value from the third account, created after the target. The target's P1 must sit between them. The same applies to LowerP2 and UpperP2. P1 Range: 39 means there are 39 possible values of P1 between the bounds, and P2 Range: 210 means 210 possible values of P2. Multiplying them gives Possible combinations: 8,190, the number of candidate tokens to try. That is 8,190 candidates instead of 1,000,000,000 * 1,000,000,000 = 1.0e18.

Step 5: brute force the range

Brute force means trying every possibility until one works. The script logic, reproduced as the report gives it (the report notes it is pseudo code that will not run and only summarises the logic):

Python
for P1 in range (LowerP1..UpperP1):
  for P2 in range (LowerP2..UpperP2):
    P1 = "TEXT000" + string(P1)
    P1 = base64encode(P1)
    P2 = base64encode(P2)
    url = buildURL(P1, P2)
    getUrl(url)

# Note, this is pseudo code - it won't actually run but
# it summaries the script logic into a readable form

Line by line: for P1 in range (LowerP1..UpperP1): loops over every number from the lower P1 bound to the upper P1 bound. for P2 in range (LowerP2..UpperP2): does the same for P2, inside the first loop, so every P1 is paired with every P2. P1 = "TEXT000" + string(P1) rebuilds the decoded form by putting the fixed prefix TEXT000 in front of the number. P1 = base64encode(P1) turns that back into the encoded form the website expects. P2 = base64encode(P2) encodes the P2 number the same way. url = buildURL(P1, P2) assembles the full verification link from the two encoded values. getUrl(url) sends the request to the website, which is the actual attempt to verify the address. The comment at the end explains that this is pseudo code, a sketch of the logic rather than a working program.

buildURL() added P3, P4 and the rest of the URL. An HTTP GET request was then sent for each of the 8,190 possible two-part tokens between the bounds until the target address was validated. An HTTP GET request is simply a browser asking a server for a page, the same thing that happens when you type an address and press enter.

Step 6: result

The address at the company domain was validated, proving the bypass. Because the application already linked email/password accounts with Facebook accounts sharing an email address, no further proof was needed; a simple explanation of the behaviour was enough for the bug bounty report. As a side effect, the run also validated a few other addresses created by members of the public that happened to fall inside the bounds at the time of testing.

Root cause

The token was built from two sequential numbers, base64 encoded. The only thing protecting a token was the size of the number space, and the ordering of generated tokens collapsed that space to a few thousand candidates once two tokens either side of the target could be observed. The application did enforce verification, which is the right control, but the token it issued was predictable. The report notes that the password reset method already used a long random string, but the developers reinvented the token process for email verification.

Impact

The verification requirement could be bypassed, so an account could be used without being tied to a real email address. Pre-account takeovers were possible on any email address that was not already registered: the attacker registers first with a password of their choice, ready for when the real owner later signs in with Facebook, Twitter or another provider. The report limits this to addresses that were not already registered.

Fix

The recommended remediation is to replace P1 and P2 with a really long and random string of characters, removing sequential numbers from the token generation algorithm. A random string of enough length cannot be guessed or bracketed, because there is no order to follow. The report does not say whether the fix was applied.

Variants to test

  • Decode every token parameter (base64, hex, URL encoding) and look for structure: fixed prefixes, counters, timestamps. A positive result is a decoded value that increments between successive tokens.
  • Register three accounts in quick succession, the middle one on an address you do not control, and compare the outer tokens. A small numeric gap between them means the middle token is brute-forceable.
  • Check whether the same weak generator is used for password reset, magic links, invitations or API keys. A positive result is a reset or magic-link token with the same sequential structure.
  • Test whether the application links accounts by email across login methods without requiring verification. A positive result is an account created with an unverified address being merged with a later OAuth login on the same address.

Glossary

  • Bug bounty program: a scheme where a company invites outside testers to find and report security weaknesses, usually for a reward.
  • Token: a short piece of text a website uses to recognise something, such as a logged-in user or a verified email address.
  • Pre-account takeover: an attack where someone registers an account on an email address they do not own, so that when the real owner later signs up the accounts are linked and the attacker gains access.
  • Email verification: the step where a site emails a link to prove the person signing up really controls that email address.
  • OAuth: a way for one website to ask another, such as Facebook, to confirm who you are, so you do not need a separate password.
  • SAML single sign-on: a company login system where one central identity provider vouches for you across many applications.
  • Identity provider (IdP): the central system that confirms your identity in single sign-on.
  • Magic link: a one-time link emailed to you that logs you in when clicked, with no password.
  • Browser profile: a separate set of cookies and saved data inside a browser, letting you be logged in as different users at once.
  • Burp Intruder: a tool that sends many web requests automatically, and can pause and release them in a chosen order.
  • Parameter: a named value passed to a web page in its address, written as name=value.
  • Base64: a way of writing any data using only letters, digits and a couple of symbols, so it can travel safely in a web address.
  • Padding: extra characters added to encoded data so it reaches the required length, often shown as = or == at the end of base64.
  • Bit length: the size of a piece of data measured in bits, the smallest unit of digital information.
  • Timestamp: the time recorded in a server's reply.
  • HTTP response: the reply a server sends back after a request.
  • HTTP GET request: a browser asking a server for a page, the same thing that happens when you type an address and press enter.
  • Brute force: trying every possibility until one works.
  • Upper and lower bounds: the highest and lowest values a hidden number can take, based on values seen before and after it.
  • Search space: the total number of possibilities an attacker would have to try.
  • Pseudo code: a sketch of program logic written for people to read, not a program that will run.
  • Root cause: the underlying reason a weakness exists.
  • Remediation: the fix for a weakness.
  • API key: a secret string that lets a program prove its identity to another service.

More by Craig Hays

View all

2 more disclosed reports, best first.

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.