Skip to content
Account takeover Write-up Intermediate

How I bypassed 2 Factor Authentication

The 2FA recovery flow used a numeric identifier for the phone number that was not tied to the logged-in account, so an attacker could change it to a previously used number and receive the victim's 2FA code. This allowed bypassing 2FA and taking over the victim's account.

Hemant Singh Manral Follow

Published on medium.com

Bounty$250 View original

I am not revealing the name of the website, we will be assuming it as example.com

HEMANT SINGH MANRAL, on medium.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. 5 min read.

Context

This is a write-up of a two-factor authentication bypass on a site the author refers to only as example.com; the real name is deliberately withheld. The target offered two ways to satisfy 2FA:

  1. An authenticator app.
  2. A YubiKey OTP.

Alongside those, the site let a user register a recovery method, either an email address or a phone number, so that a code could still be obtained if the authenticator app was unavailable. The recovery path is the part that turned out to be broken.

When the phone recovery option was used, the site sent a six digit string to the registered number. The author notes that the code was a string, a mix of letters and digits, and that it stayed valid for a long time with no rate limiting on attempts. Brute forcing it was therefore considered but rejected: the mixed character set made the search space too large, and the author expected the attempts to be blocked anyway.

Setup

The author used Burp Suite to intercept and modify requests. Two accounts were used, described in the report as follows:

  • Account A, with recovery phone number a.
  • Account B, with recovery phone number b.

Each phone number was observed to be mapped to a seven digit identifier. In the author's example, a is assigned 1234567 and b is assigned 8901234. Account B is later treated as the victim's account and A as the attacker's.

Finding it

The recovery flow produced a POST request that the author intercepted in Burp Suite:

Text
{"loginID":"[redacted]","sendCodeTo":6547296}

The sendCodeTo parameter caught the author's attention because its name suggests it selects where the code is sent. Two experiments followed.

First try: using the same phone number, the author checked whether the value of sendCodeTo changed between requests. It stayed constant, which suggested the value identifies the number rather than being a per-request nonce.

Second try: the author changed the recovery phone number on the account, captured the request for the 2FA code again, and saw the same request shape with a different value for sendCodeTo.

Together these showed that each phone number is assigned a particular seven digit value used to identify it. That is the design flaw: the client supplies the identifier of the destination number, and the server appears to trust it.

Exploitation

Step 1: capture the recovery request

With account A logged in, the site asked for a 2FA code. The author switched to the phone recovery option and captured the POST request:

Text
{"loginID":"[redacted]","sendCodeTo":1234567}

Here loginID identifies the session or account being authenticated, and sendCodeTo is the identifier of the phone number that should receive the code, in this case 1234567 for number a.

Step 2: swap in another number's identifier

The author replaced the value of sendCodeTo with the identifier belonging to account B's number b:

Text
{"loginID":"[redacted]","sendCodeTo":8901234}

The request was forwarded, but no code arrived on b. At this point the substitution alone did not produce a code on the other number.

Step 3: change the attacker's number

The author then changed the recovery phone number on account A from a to a new number c, with identifier 5423147. The state was now:

Account Recovery number Identifier
A (attacker) c 5423147
B (victim) b 8901234
A (old number) a 1234567

Number a still carried the identifier 1234567 even though it was no longer the recovery number on account A.

Step 4: capture the victim's request

The author logged in with account B, chose the phone recovery option for 2FA, and captured the request:

Text
{"loginID":"[redacted]","sendCodeTo":8901234}

This is the victim's login, with sendCodeTo pointing at the victim's own number b.

Step 5: point the victim's login at the old attacker number

The value of sendCodeTo was changed to 1234567, the identifier of the number a that the attacker had previously registered and then removed:

Text
{"loginID":"[redacted]","sendCodeTo":1234567}

Step 6: receive the code

The request was forwarded and the 2FA code arrived on a, the attacker's old number. The victim's login was now waiting on a code that the attacker controlled, which completes the bypass.

Root cause

The server takes the destination of the recovery code from the sendCodeTo parameter supplied by the client, and the identifier is not tied to the account being authenticated in the request the author sent. Because the identifier for a number survives after that number is removed from an account, an attacker can keep a number they once registered, then redirect a victim's login to it. The report does not describe any server-side check that the identifier belongs to the account in loginID; the behaviour is consistent with that check being absent, but the report does not state it directly.

The absence of rate limiting on the six digit code did not matter here, because the attacker never had to guess it. The mixed alphanumeric character set likewise only discouraged brute force, not redirection.

Impact

An attacker who can register a recovery phone number, then remove it, can redirect another user's 2FA recovery code to that number and complete login as the victim. The attacker needs the victim's login to reach the 2FA recovery step; the report does not describe how that login was obtained.

Fix

The fix implied by the finding is to stop accepting the destination from the client: the server should derive the recovery number from the authenticated account, or at minimum verify that the supplied identifier belongs to that account and reject identifiers for numbers no longer registered.

Variants to test

  1. Identifier substitution on any recovery or OTP endpoint. Intercept the request that triggers a code and look for a parameter naming the destination (number, email, device). Swap it for an identifier belonging to another account. A positive result is a code arriving at the other destination, or a response indicating the code was sent there.
  2. Stale identifiers after removal. Register a number or email, note its identifier, remove it, then try using the identifier again. A positive result is the identifier still being accepted and a code still being delivered.
  3. Identifier enumeration. Check whether identifiers are sequential or otherwise guessable, as the seven digit values here suggest. A positive result is being able to predict a valid identifier for a number you do not control.
  4. Binding between session and destination. Compare the identifier in the request with the one the server expects for the logged-in account. A positive result is the server accepting a mismatch without error.

Disclosure

The author reported the bug on 15 September. The company replied that it had reproduced the issue on 17 September, and rewarded the author with 250 USD on 12 October.

From the original on medium.com

Thanks to the readers, and best regards to Hemant Singh Manral.

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. 10 min read.

What happened, in plain words

A website let people protect their accounts with a second step at login, called two-factor authentication (2FA). Besides the usual password, you also have to prove you hold something else, such as a phone. When you log in, the site sends a short code to your phone and you type it in. The idea is that a thief who steals your password still cannot get in, because the code goes to your phone, not theirs.

This site also let you register a backup phone number, so that if you lost access to your authenticator app you could still receive a code. That backup path had a flaw. The request your browser sends when it asks for the code contains a number that tells the server which phone to send the code to. The server trusted that number as it arrived from the browser. So if an attacker could learn the identifier of a phone number they once owned, they could ask the server to send a victim's login code to that old number, read the code, and finish the victim's login.

The author of the report calls the site example.com because the real name is not public. The author is Hemant Singh Manral, a bug hunter from India, and this was his first write-up.

The site's 2FA options

The site offered two ways to do the second step:

  1. An authenticator app. This is a small app on your phone that shows a fresh six digit code every 30 seconds or so, generated from a secret shared with the website when you set it up. Because the code changes constantly and is tied to your phone, a thief with only your password cannot produce it.
  2. A YubiKey OTP. A YubiKey is a small USB stick you plug in (or tap) that types a one-time password for you. "OTP" means one-time password: a code that is valid once and then useless.

On top of those, the site let you add a recovery method, either an email address or a phone number. The purpose is simple: if you lose your phone or your key, you still need a way back into your account. The site sends a code to that backup address or number instead.

That recovery path is where the bug lived.

The recovery code and why guessing it was not the plan

When the phone recovery option was used, the site sent a six digit string to the registered number. The report stresses "string": the code was a mix of letters and digits, not just numbers.

The author noticed two more things about that code:

  • It stayed valid for a long time.
  • There was no rate limiting. Rate limiting is a server rule that says "only so many attempts per minute from one place". Without it, a program can try thousands of guesses quickly.

A six digit code with no rate limiting sounds like an open door: you could write a script that tries every combination. But because the code mixed letters and digits, the number of possible codes was far too large to try in practice, and the author expected the site to block the attempts anyway. So guessing was set aside and a different route was chosen.

Getting set up

To see and change the traffic between the browser and the website, the author used Burp Suite. Burp Suite is a tool that sits between your browser and the site like a postman who opens every letter, reads it, and can rewrite it before delivering it. It lets you pause a request, edit its contents, and send it on.

Two accounts were used, described in the report like this:

  • Account A, with recovery phone number a.
  • Account B, with recovery phone number b.

Each phone number turned out to be mapped to a seven digit identifier. In the author's example, number a gets 1234567 and number b gets 8901234. Later, account B plays the victim and account A plays the attacker.

Finding the flaw

When the recovery flow ran, it produced a POST request. A POST request is the way a browser sends data to a server, for example when you submit a form. The author intercepted it in Burp Suite:

Text
{"loginID":"[redacted]","sendCodeTo":6547296}

Line by line:

  • The whole thing is a JSON object. JSON is a text format for sending structured data, made of names and values in curly braces.
  • "loginID":"[redacted]" is a name and a value. loginID is a long random-looking string that identifies the login attempt or session. A session is the server's memory of "this browser is currently logged in as this person". The long string works like a claim ticket: whoever presents it is treated as that session.
  • "sendCodeTo":6547296 is the part that caught the author's eye. The name literally says "send the code to this". The value is a number, not a phone number in the usual sense, so it looks like an internal identifier for a destination.

Because the parameter's name suggests it chooses where the code goes, the author decided to test it. Two experiments followed.

First try: using the same phone number, the author checked whether the value of sendCodeTo changed from one request to the next. It stayed the same. That matters because many security values are deliberately different every time (a fresh random value per request is hard to reuse). A value that never changes looks like a fixed label for the phone number, not a one-time ticket.

Second try: the author changed the recovery phone number on the account, captured the request for the 2FA code again, and saw the same request shape with a different value for sendCodeTo.

Together, the two experiments showed that each phone number is assigned a particular seven digit value used to identify it. That is the design flaw: the browser supplies the identifier of the destination number, and the server appears to trust it. In plain terms, the site asks the customer "which phone should I ring?" and believes whatever answer comes back, instead of looking up the phone number saved on the account.

Exploitation, step by step

Step 1: capture the recovery request

With account A logged in, the site asked for a 2FA code. The author switched to the phone recovery option and captured the POST request:

Text
{"loginID":"[redacted]","sendCodeTo":1234567}
  • loginID identifies the session or account being authenticated. Think of it as the name on the order.
  • sendCodeTo is the identifier of the phone number that should receive the code. Here it is 1234567, which belongs to number a.

Step 2: swap in another number's identifier

The author replaced the value of sendCodeTo with the identifier belonging to account B's number b:

Text
{"loginID":"[redacted]","sendCodeTo":8901234}

Only the number after sendCodeTo changed: 1234567 became 8901234. The request was forwarded, but no code arrived on b. So simply pointing the request at someone else's number did not deliver a code to that number. Something else was going on, and the author kept experimenting.

Step 3: change the attacker's number

The author then changed the recovery phone number on account A from a to a new number c, with identifier 5423147. The state was now:

Account Recovery number Identifier
A (attacker) c 5423147
B (victim) b 8901234
A (old number) a 1234567

Number a still carried the identifier 1234567 even though it was no longer the recovery number on account A. This is the key observation: removing a number from an account did not remove its identifier. The label stayed attached to the phone number itself.

Step 4: capture the victim's request

The author logged in with account B, chose the phone recovery option for 2FA, and captured the request:

Text
{"loginID":"[redacted]","sendCodeTo":8901234}

This is the victim's login. loginID is the victim's session identifier, and sendCodeTo points at the victim's own number b, with identifier 8901234.

Step 5: point the victim's login at the old attacker number

The value of sendCodeTo was changed to 1234567, the identifier of number a that the attacker had previously registered and then removed:

Text
{"loginID":"[redacted]","sendCodeTo":1234567}

Nothing else in the request changed. The victim's session is still the one being authenticated, but the destination for the code is now the attacker's old phone.

Step 6: receive the code

The request was forwarded and the 2FA code arrived on a, the attacker's old number. The victim's login was now waiting on a code that the attacker controlled. The attacker reads the code from their old phone, which the victim's login was waiting on. That completes the bypass.

Why it worked

The server takes the destination of the recovery code from the sendCodeTo parameter supplied by the browser, and the identifier is not tied to the account being authenticated in the request the author sent. Because the identifier for a number survives after that number is removed from an account, an attacker can keep a number they once registered, then redirect a victim's login to it.

The report does not describe any server-side check that the identifier belongs to the account in loginID. The behaviour is consistent with that check being absent, but the report does not state it directly.

The missing rate limiting on the six digit code did not matter here, because the attacker never had to guess it. The mixed letters-and-digits character set likewise only discouraged guessing, not redirection.

Who could be hurt, and how badly

An attacker who can register a recovery phone number, then remove it, can redirect another user's 2FA recovery code to that number and complete login as the victim.

In everyday terms: if someone already has your password, the second lock is supposed to stop them. Here the second lock could be opened by pointing it at a phone the attacker still holds.

The fix

The fix implied by the finding is to stop accepting the destination from the browser: the server should look up the recovery number from the authenticated account, or at minimum verify that the supplied identifier belongs to that account and reject identifiers for numbers no longer registered.

Similar things to test elsewhere

  1. Identifier substitution on any recovery or OTP endpoint. Intercept the request that triggers a code and look for a parameter naming the destination (number, email, device). Swap it for an identifier belonging to another account. A positive result is a code arriving at the other destination, or a response indicating the code was sent there.
  2. Stale identifiers after removal. Register a number or email, note its identifier, remove it, then try using the identifier again. A positive result is the identifier still being accepted and a code still being delivered.
  3. Identifier enumeration. Check whether identifiers are sequential or otherwise guessable, as the seven digit values here suggest. A positive result is being able to predict a valid identifier for a number you do not control.
  4. Binding between session and destination. Compare the identifier in the request with the one the server expects for the logged-in account. A positive result is the server accepting a mismatch without error.

Disclosure

The author reported the bug on 15 September. The company replied that it had reproduced the issue on 17 September, and rewarded the author with 250 USD on 12 October.

From the original on medium.com

Thanks to the readers, and best regards to Hemant Singh Manral.

Glossary

  • 2FA (two-factor authentication): a login that needs two separate proofs, usually a password plus a code from a phone or key.
  • Authenticator app: a phone app that generates a fresh short code every 30 seconds from a secret shared with the website.
  • YubiKey OTP: a small hardware key that produces a one-time password when plugged in or tapped.
  • OTP (one-time password): a code valid for a single use, then useless.
  • Recovery method: a backup email address or phone number used to receive a code when the main second factor is unavailable.
  • Rate limiting: a server rule that caps how many attempts are allowed in a period, to slow down guessing.
  • Brute forcing: trying many possible codes or passwords automatically until one works.
  • String: a piece of text, here a code made of letters and digits rather than only numbers.
  • Burp Suite: a tool that sits between browser and website, letting you pause, read and edit requests.
  • POST request: the way a browser sends data to a server, for example when submitting a form.
  • JSON: a text format for structured data, made of names and values in curly braces.
  • Parameter: a named value inside a request, such as sendCodeTo.
  • Session: the server's memory of which browser is currently logged in as which person.
  • Session identifier (loginID): the long random-looking value that stands for a session, like a claim ticket.
  • Identifier (sendCodeTo value): the seven digit number the site uses internally to label a phone number.
  • Endpoint: a specific address on a server that handles a particular action, such as sending a recovery code.
  • Server-side check: validation done on the server, which the user's browser cannot bypass, as opposed to trusting what the browser sends.
  • Enumeration: working out valid values (such as identifiers) by spotting a pattern or trying them in order.
  • Stale identifier: an identifier that still works after the thing it labelled was removed from the account.
  • Bypass: getting past a security control without satisfying it legitimately.

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.