Skip to content
Account takeover Write-up Intermediate

How I Was Able to Remove Your Instagram Phone Number

The Instagram sign-up OTP verification endpoint had no rate limit, so the six-digit code could be brute-forced. An attacker could then register a new account using a phone number already tied to a victim's account, which removed that number from the victim's Instagram account.

Neeraj Sonaniya Follow

Published on medium.com

Bounty$1,000 View original

Security

Neeraj Sonaniya, 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

Instagram lets people sign up and log in with a mobile number instead of an email address. After a number is submitted during registration, Instagram verifies that the person controls it by sending a six digit OTP (One Time Password) by SMS. The account is only created once the correct code is entered.

This write-up describes a flaw in that verification step, and a second flaw in how registration treats a number that is already attached to an existing account. Together they let the author create a new account from a number that was already registered, and in doing so remove that number from the original account.

Setup

The author worked against Instagram's own registration and login flows. Two accounts are involved:

  1. A real Instagram account, already registered with a mobile number.
  2. A test account, created during the research using that same mobile number.

No specific tooling, versions or endpoints are named in the report. The work is done by hand against the registration page and the OTP verification step, with the responses inspected as they come back.

Finding it

The starting point is the normal flow: sign up through a mobile number, then verify that you are a real person through the OTP sent to that number.

From the original on medium.com

While looking at that flow, the author noticed that the endpoint which verifies the OTP has no limit on attempts. That means the six digit code can be brute-forced: there are only one million possible values, and nothing stops a client from trying them one after another.

From the original on medium.com

A second observation sits alongside it: even when a mobile number is already registered with Instagram, the registration page still accepts that same number again.

From the original on medium.com

Exploitation

Step 1: Confirm the OTP endpoint has no lockout

The author sent repeated verification attempts and recorded the two possible responses.

Response when the OTP is wrong:

Text
{"status": "ok", "error_type": "form_validation_error", "errors": {"sms_code": ["That code is no longer valid. Go back to request a new one."]}, "account_created": false}
From the original on medium.com

Response when the OTP is correct:

Text
{"status": "ok", "account_created": true}
From the original on medium.com

The two responses are clearly distinguishable: a wrong code returns form_validation_error with an sms_code message and account_created set to false, while a correct code returns account_created set to true. That difference is what makes automated guessing practical, because a script can tell success from failure on every attempt.

Step 2: Brute-force the code

The author reports that 636 requests were made with no lockout encountered. Because the endpoint never throttled or blocked the attempts, the six digit code could be enumerated until the correct one was found.

Step 3: Create the account

Once the correct OTP was reached, the author was able to create an account from that mobile number. This is the point where the second flaw matters: the number was already registered to the real account, yet registration accepted it again.

Step 4: Observe the effect on the original account

The author logged out of the test account and signed in to the real Instagram account, the one originally registered with that mobile number. After logging in, this page was shown:

From the original on medium.com

That page confirms that the mobile number had been removed from the real Instagram account.

A proof of concept video was also provided to the vendor.

Root cause

The report identifies two contributing weaknesses:

  1. The OTP verification endpoint had no attempt limit, so a six digit code could be guessed by brute force. The response format made each guess trivially classifiable as right or wrong, which removes any ambiguity an attacker would otherwise have to work around.
  2. The registration flow allowed a mobile number that was already registered to be used again. The report does not explain why the number moved to the new account.

Impact

An attacker who knows a victim's mobile number can start a registration with it and brute-force the OTP. On success, the attacker creates an account tied to that number, and the number is removed from the victim's existing Instagram account. The author demonstrates exactly this against their own real account.

The attack requires the ability to reach the registration and OTP verification flow and to send many requests, which the missing rate limit permits. The report does not describe any further consequences beyond the removal of the number from the original account.

Fix

The issue was patched on 27 December 2016, and a $1000 bounty was awarded on 29 December 2016.

Timeline

Date Event
8 November 2016 Report submitted
16 November 2016 Facebook response that the issue could not be reproduced
18 November 2016 POC video provided
19 November 2016 Again not accepted
19 November 2016 POC video with time and date provided again
19 November 2016 Issue triaged
27 December 2016 Issue patched
29 December 2016 $1000 bounty awarded
From the original on medium.com

Variants to test

  1. OTP endpoints without attempt limits. Submit wrong codes repeatedly against any SMS or email verification endpoint and watch for a lockout, CAPTCHA or delay. A positive result is a long run of attempts that all return the normal wrong-code response with no change in behaviour.
  2. Distinguishable success and failure responses. Compare the body of a wrong-code response with a correct one. A positive result is a field such as account_created or a distinct error type that lets a script classify each guess without ambiguity.
  3. Re-registration of an already bound identifier. Try registering with a phone number or email that is already attached to an account. A positive result is the flow proceeding to verification instead of rejecting the identifier as already in use.
  4. Binding takeover after verification. Complete verification on the duplicate registration and then sign in to the original account. A positive result is the identifier having moved to the new account and disappeared from the original one.
  5. Short numeric codes generally. Any flow that uses a short numeric code (six digits or fewer) is worth testing for the same combination of no rate limit and a clear success signal.

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

What happened, in plain words

Instagram lets you create an account with a mobile phone number instead of an email address. When you sign up that way, Instagram sends a short code by text message to prove the number is really yours. That code is called an OTP, short for One Time Password. You type it in, and only then is the account created.

This report is about two mistakes in that process. First, Instagram let someone try the six digit code as many times as they liked, with no limit. Second, Instagram let someone start a new registration with a phone number that was already attached to an existing account. Put together, the author was able to guess the code, create a new account with a number that already belonged to their own real account, and in the process the number was removed from the real account.

Before going further, a few words on the pieces involved, because the rest of the article uses them constantly.

  • API: the set of addresses a website's own pages talk to behind the scenes. When you fill in a form and press a button, your browser sends a request to one of these addresses and gets a reply, usually in a compact data format rather than a full web page. Think of it as the service counter behind the shop front: you never see it, but every action you take is handled there.
  • Endpoint: one specific address on that counter, for one specific job. There is an endpoint for "check this OTP", another for "create the account", and so on.
  • Request and response: the message your browser sends (the request) and the message that comes back (the response).
  • JSON: a simple way of writing data as labelled values, like a form with boxes. {"account_created": true} means "the field called account_created holds the value true".
  • Brute force: trying every possible value until one works. A six digit code has one million possible values (000000 to 999999). A person cannot type a million codes, but a computer can send them quickly, so the only real defence is a limit on how many attempts are allowed.
  • Rate limit / lockout: a rule that says "after N wrong tries, stop accepting attempts for a while". Without one, brute force becomes practical.

The normal flow

The starting point is the ordinary sign-up: choose to register with a mobile number, receive the OTP by SMS, and enter it to prove you are a real person.

From the original on medium.com

The two observations

While looking at that flow, the author noticed something about the endpoint that checks the OTP: it had no limit on attempts. Nothing stopped a client from sending code after code. Since the code is only six digits, that means it can be brute-forced.

From the original on medium.com

The second observation sits next to it: even when a mobile number is already registered with Instagram, the registration page still accepts that same number again. Normally you would expect a site to say "this number is already in use". Here it did not.

From the original on medium.com

Neither observation is dramatic on its own. The first means the code can be guessed. The second means a guessed code can be used to attach an already-owned number to a brand new account. Together they are the whole bug.

Step 1: Confirm there is no lockout

To show the missing limit, the author sent repeated verification attempts and recorded what came back. There are only two possible outcomes, and both are shown below.

Response when the OTP is wrong:

Text
{"status": "ok", "error_type": "form_validation_error", "errors": {"sms_code": ["That code is no longer valid. Go back to request a new one."]}, "account_created": false}
From the original on medium.com

Line by line, in plain words:

  • "status": "ok" means the request itself was handled normally. The server is not saying "you are blocked" or "too many attempts"; it is simply reporting the result.
  • "error_type": "form_validation_error" says the submitted form value failed validation, that is, the code was not accepted.
  • "errors": {"sms_code": [...]} groups the problem under the field named sms_code, which is the box where the code is typed. The message inside tells the user the code is no longer valid and to request a new one.
  • "account_created": false is the key part: no account was made.

Response when the OTP is correct:

Text
{"status": "ok", "account_created": true}
From the original on medium.com
  • "status": "ok" again means the request was handled.
  • "account_created": true means the code was accepted and the account now exists.

The two replies are easy to tell apart. A wrong code gives an error block and account_created set to false; a right code gives account_created set to true. That matters because a script can look at each reply and know instantly whether the guess worked. If both replies looked identical, guessing would be far harder, because the attacker could not tell success from failure.

Step 2: Guess the code

The author reports that 636 requests were made and no lockout appeared. In other words, after hundreds of wrong guesses the endpoint still behaved exactly as it did on the first try: no block, no delay, no challenge. Because nothing throttled the attempts, the six digit code could simply be enumerated until the right one turned up.

Step 3: Create the account

Once the correct OTP was reached, the author was able to create an account from that mobile number. This is where the second flaw matters. The number was already registered to the real account, yet registration accepted it again and completed.

Step 4: Look at the original account

The author then logged out of the test account and signed in to the real Instagram account, the one that had originally been registered with that mobile number. After logging in, this page appeared:

From the original on medium.com

The page confirms that the mobile number had been removed from the real Instagram account. The number had effectively moved to the newly created account.

A proof of concept video was also sent to the vendor. A proof of concept, or POC, is simply a recording or set of steps that shows the bug happening for real, so the people who run the site can see it rather than take it on trust.

Why it worked

Two weaknesses combined:

  1. The OTP verification endpoint had no attempt limit, so a six digit code could be guessed by brute force. The reply format made every guess trivially classifiable as right or wrong, which removes any doubt an attacker would otherwise have to work around.
  2. The registration flow allowed a mobile number that was already registered to be used again. The report does not explain why the number moved to the new account.

What an attacker could do

Someone who knows a victim's mobile number can start a registration with it and brute-force the OTP. On success, they create an account tied to that number, and the number is removed from the victim's existing Instagram account. The author demonstrated exactly this against their own real account.

The attack needs the ability to reach the registration and OTP verification flow and to send many requests, which the missing rate limit permits. The report does not describe any further consequences beyond the removal of the number from the original account.

The fix

The issue was patched on 27 December 2016, and a $1000 bounty was awarded on 29 December 2016.

Timeline

Date Event
8 November 2016 Report submitted
16 November 2016 Facebook response that the issue could not be reproduced
18 November 2016 POC video provided
19 November 2016 Again not accepted
19 November 2016 POC video with time and date provided again
19 November 2016 Issue triaged
27 December 2016 Issue patched
29 December 2016 $1000 bounty awarded
From the original on medium.com

Things worth testing elsewhere

  1. OTP endpoints without attempt limits. Submit wrong codes repeatedly against any SMS or email verification endpoint and watch for a lockout, CAPTCHA or delay. A positive result is a long run of attempts that all return the normal wrong-code response with no change in behaviour.
  2. Distinguishable success and failure responses. Compare the body of a wrong-code response with a correct one. A positive result is a field such as account_created or a distinct error type that lets a script classify each guess without ambiguity.
  3. Re-registration of an already bound identifier. Try registering with a phone number or email that is already attached to an account. A positive result is the flow proceeding to verification instead of rejecting the identifier as already in use.
  4. Binding takeover after verification. Complete verification on the duplicate registration and then sign in to the original account. A positive result is the identifier having moved to the new account and disappeared from the original one.
  5. Short numeric codes generally. Any flow that uses a short numeric code (six digits or fewer) is worth testing for the same combination of no rate limit and a clear success signal.

Glossary

  • API: the set of addresses a website's own pages use behind the scenes to carry out actions and fetch data.
  • Endpoint: one specific address in that set, responsible for one job, such as checking an OTP.
  • Request: the message a browser or script sends to a server.
  • Response: the message the server sends back.
  • JSON: a text format for data written as labelled values, such as {"account_created": true}.
  • OTP (One Time Password): a short code, valid for one use, sent to a phone or email to prove the person controls it.
  • SMS: a text message sent to a mobile phone.
  • Rate limit: a cap on how many requests are accepted in a period of time.
  • Lockout: blocking further attempts after too many failures.
  • Throttling: deliberately slowing down or limiting repeated requests.
  • CAPTCHA: a challenge meant to be easy for a person and hard for a script.
  • Validation error: a rejection saying a submitted value is not acceptable.
  • Registration flow: the sequence of pages and requests that ends in a new account being created.
  • Binding: the link between an identifier, such as a phone number, and an account.
  • POC (proof of concept): a demonstration, often a video, that shows a bug actually happening.
  • Triaged: reviewed and accepted as a genuine issue by the vendor's security team.
  • Patched: fixed in the live product.
  • Bounty: a payment made by a company to someone who reports a valid security issue.

More by Neeraj Sonaniya

View all

3 more disclosed reports, best first.

More from Meta

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.