Instagram Account Takeover: Racing the 6-Digit Code
Instagram's mobile password-recovery flow rate-limited guesses per source IP but not per code, allowing an attacker to send many concurrent requests from many IPs to guess the six-digit code. A successful guess could lead to full account takeover for any account with a phone number on file.
Published on masimshahzad.medium.com
Bug Bounty
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.
Context
Instagram's account recovery flow had two variants. The web reset flow used links and, according to the write-up, held up against abuse. The mobile flow sent a six-digit code by SMS instead. That code was the only thing standing between an attacker and a full account takeover, and it stayed valid for 10 minutes.
Six digits means one million possible values. The question the case study asks is whether an attacker can try enough of them inside that ten-minute window.

This is an analytical case study of a public disclosure. The finding belongs to Laxman Muthiyah, who published it as How I Could Have Hacked Any Instagram Account on The Zero Hack in 2019. Facebook fixed the issue and paid a $30,000 bounty. The severity rating was not reported.
Setup
The write-up does not describe a lab, tooling or account setup in detail. What it does establish is the precondition: the target account has a phone number on file, so the mobile recovery flow will send an SMS code to it. The precondition is that the target account has a phone number on file, so the mobile recovery flow will send an SMS code to it. The researcher's own test used 1,000 machines, and his cost estimate for a full attack was about 5,000 IP addresses and roughly $150 of cloud compute.
Finding it
The mobile reset flow sent a six-digit code over SMS. Six digits is one million possibilities, and each code remained valid for 10 minutes. That combination is only safe if the server limits how many guesses can be made against a single code.
There was a rate limit, but it behaved in a way that made it close to useless for this purpose. In the researcher's first test, roughly a quarter of a 1,000-request burst got through and the rest were throttled. Two properties stood out:
- Throttled sources were slowed, never blocked.
- The limit was keyed to the source address, not to the code being guessed.
Neither property is wrong on its own. Together they mean the defence protects the server from load, not the account from guessing. An attacker who can present many source addresses gets a fresh allowance from each one, and the code itself never accumulates a global attempt count.
Exploitation
Step 1: Measure the per-source allowance
The researcher sent a burst of 1,000 requests and observed that about a quarter were accepted while the rest were throttled. From this he derived a working figure of about 200 guesses per IP address before throttling kicks in. The write-up does not include the raw request or response for this measurement.
Step 2: Spread the guesses across sources
Because the limit is per source, the guesses are sent concurrently from many addresses. No single source ever trips the limit, because each one stays inside its own allowance. The guesses are spread across the code space rather than concentrated on one address.
Step 3: Cover the space inside the validity window
In the researcher's test, 1,000 machines sent 200,000 guesses, a fifth of the code space, inside the 10-minute window. Scaling that arithmetic to the full space gives the estimate of about 5,000 IP addresses and roughly $150 of cloud compute for a complete attack.
The case study does not publish the request format, headers or payloads used against the recovery endpoint, and states that reproduction details are intentionally omitted.
Root cause
The design flaw is that the brute-force protection was keyed to the source address rather than to the code being verified. A per-source limit bounds how much traffic one address can generate; it does not bound how many times a given code can be guessed, because the attacker can rent more addresses. The write-up's framing is that a rate limit keyed to IP addresses protects your servers, not your users' accounts.
The second flaw is that throttling slowed sources without ever blocking them, so a determined source could keep going at a reduced rate.
The case study also notes a concurrency angle in its own analysis: if the attempt counter is read and then written non-atomically, parallel requests can all read the same value, such as "0 attempts so far", and each proceed as if it were the first attempt. Whether Instagram's implementation had exactly this race is not stated in the source material; the case study presents the atomic-increment requirement as part of its own defensive analysis.
Impact
A working attack meant full takeover of any account with a phone number on file. The victim would only see an SMS they never requested. Once inside, private messages, creator income and brand accounts were all exposed.
The condition matters: the flow in question is the mobile SMS recovery flow, and the account must have a phone number attached. The web reset flow, which used links, is described as holding up.
Facebook initially could not reproduce the issue. A proof-of-concept video showing 200,000 accepted requests changed that, and the report was paid at $30,000.
Fix
Facebook fixed the issue in 2019. The write-up does not describe the specific change made on the server side.
The case study offers its own defensive recommendations, which are analysis rather than a description of Facebook's patch:
- Budget guesses per code, not per IP. Attackers can rent IP addresses, but they cannot rent extra attempts against a single code.
- Count before you compare. The attempt counter must be incremented atomically and committed before the guess is checked, otherwise parallel requests all read the same starting count.
- Cap code issuance per account. Otherwise every freshly issued code resets the attacker's budget.
The illustrative verification logic from the case study:
MAX_TRIES = 5def verify_recovery_code(account_id, submitted, request): rec = recovery_codes.get_active(account_id) if rec is None or rec.expires_at < now(): return reject("code_invalid") tries = recovery_codes.increment_attempts(rec.id) if tries > MAX_TRIES: recovery_codes.revoke(rec.id) alert("recovery_bruteforce", account_id, request.ip) return reject("code_invalid") if not constant_time_equals(rec.code_hash, hash_code(submitted)): return reject("code_invalid") if not recovery_codes.consume_once(rec.id): return reject("code_invalid") return issue_reset_session(account_id)
The important parts: the attempt counter is incremented before the comparison, so concurrent requests serialise on the counter; exceeding the cap revokes the code rather than merely delaying the caller; the comparison is constant time; and consumption is a single atomic operation so a code cannot be redeemed twice.
Variants to test
- Per-source limits on any short-code verification. Try login OTPs, password-reset codes, email verification codes and MFA enrolment codes. A positive result is that a burst from one address is throttled but the same code can still be guessed from a second address, with the code remaining valid throughout.
- Throttling without blocking. Send sustained traffic from one source and check whether requests are merely slowed or eventually refused outright. A positive result is that the source keeps receiving responses, even at a reduced rate, for the whole validity window.
- Counter races. Fire many verification requests in parallel against one code and look for more accepted attempts than the stated maximum. A positive result is a number of processed guesses above the configured cap.
- Code re-issuance. Request a new code repeatedly and check whether the attempt budget resets each time. A positive result is an unlimited supply of fresh budgets for the same account.
- Reuse after success. Verify a code, then submit it again. A positive result is a second successful reset session from the same code.
- Response differences. Compare the responses for a wrong code, an expired code and a correct code. A positive result is any observable difference that lets an attacker distinguish states without consuming attempts.
What happened, in plain words
Instagram lets you get back into your account if you forget your password. On a phone, one way it did this in 2019 was to send you a text message (SMS) with a six-digit code. You type that code into the app, and if it matches, you get to set a new password.
A six-digit code looks like this: 000000 up to 999999. That is one million possible codes. If a computer could try every one of them quickly, it would eventually hit the right one. So the whole safety of the system depends on one thing: the server must refuse to let anyone try too many codes.
In 2019 a security researcher named Laxman Muthiyah found that Instagram's mobile recovery flow did have a limit, but the limit was applied in the wrong place. It counted attempts per internet address (per IP address), not per code. An attacker who can send requests from many different addresses therefore gets a fresh allowance from each one. With enough addresses working at the same time, the attacker can try a large share of the one million codes before the code expires.
Facebook fixed the problem and paid a $30,000 bounty. The severity rating was not reported. This article is an analytical case study of that public disclosure, not a new discovery.

AI-generated illustration
The two recovery flows
Instagram had two ways to recover an account.
- The web flow. On a computer browser, recovery used links. According to the write-up, this flow held up against abuse.
- The mobile flow. On a phone, recovery sent a six-digit code by SMS instead.
The code was the only thing standing between an attacker and a full account takeover, and it stayed valid for 10 minutes. "Account takeover" means someone else gets control of your account: they can read your messages, post as you, and change your settings.
Six digits means one million possible values. The question the case study asks is simple: can an attacker try enough of those one million values inside the ten-minute window?
What the attacker needs before starting
The write-up does not describe a lab, specific tools or account setup in detail. What it does establish is the precondition: the target account has a phone number on file, so the mobile recovery flow will send an SMS code to it.
The attacker also needs the ability to send requests from many source addresses.
- the victim's username or identifier, to start the recovery process;
- the ability to send requests from many source addresses.
An IP address is the number that identifies a device or network on the internet, a bit like a return address on an envelope. Every request a server receives comes from some IP address, and the server can use that address to decide who is asking.
The researcher's own test used 1,000 machines, and his cost estimate for a full attack was about 5,000 IP addresses and roughly $150 of cloud compute. "Cloud compute" means rented computers in a data centre, paid by the hour, which anyone can order online.
Finding the weakness
The mobile reset flow sent a six-digit code over SMS. Six digits is one million possibilities, and each code remained valid for 10 minutes. That combination is only safe if the server limits how many guesses can be made against a single code.
A rate limit is a rule on a server that says "only this many requests per time period from this source". Think of a shop that lets each customer buy at most two items: the rule limits the customer, not the item. If the shop has many customers, the items still sell out.
There was a rate limit, but it behaved in a way that made it close to useless for this purpose. In the researcher's first test, roughly a quarter of a 1,000-request burst got through and the rest were throttled. "Throttled" means slowed down or refused for a while, not permanently banned.
Two properties stood out:
- Throttled sources were slowed, never blocked.
- The limit was keyed to the source address, not to the code being guessed.
Neither property is wrong on its own. Together they mean the defence protects the server from load, not the account from guessing. An attacker who can present many source addresses gets a fresh allowance from each one, and the code itself never accumulates a global attempt count.
How the attack worked
Step 1: Measure the per-source allowance
The researcher sent a burst of 1,000 requests and observed that about a quarter were accepted while the rest were throttled. From this he derived a working figure of about 200 guesses per IP address before throttling kicks in. The write-up does not include the raw request or response for this measurement.
Why measure first? Because you need to know how many guesses one address buys you before you can plan how many addresses you need. It is like checking how many tries a locked door gives you before it stops responding, so you know how many people you need to bring.
Step 2: Spread the guesses across sources
Because the limit is per source, the guesses are sent concurrently from many addresses. "Concurrently" means at the same time, in parallel, rather than one after another. No single source ever trips the limit, because each one stays inside its own allowance. The guesses are spread across the code space rather than concentrated on one address.
"Code space" means the full set of possible codes: here, all one million six-digit numbers. Spreading guesses across it means different machines try different numbers, so together they cover more ground.
Step 3: Cover the space inside the validity window
In the researcher's test, 1,000 machines sent 200,000 guesses, a fifth of the code space, inside the 10-minute window. Scaling that arithmetic to the full space gives the estimate of about 5,000 IP addresses and roughly $150 of cloud compute for a complete attack.
The case study does not publish the request format, headers or payloads used against the recovery endpoint, and states that reproduction details are intentionally omitted. "Headers" are the extra lines of information a browser sends with a request, such as what kind of browser it is. "Payload" means the actual data sent in the request body.
Why it worked: the root cause
The design flaw is that the brute-force protection was keyed to the source address rather than to the code being verified. "Brute force" means trying many possibilities until one works, like trying every key on a keyring until a door opens. A per-source limit bounds how much traffic one address can generate; it does not bound how many times a given code can be guessed, because the attacker can rent more addresses. The write-up's framing is that a rate limit keyed to IP addresses protects your servers, not your users' accounts.
The second flaw is that throttling slowed sources without ever blocking them, so a determined source could keep going at a reduced rate.
The case study also notes a concurrency angle in its own analysis: if the attempt counter is read and then written non-atomically, parallel requests can all read the same value, such as "0 attempts so far", and each proceed as if it were the first attempt. "Atomically" means as a single indivisible step: either the whole change happens or none of it does, with no moment in between where another request can slip in. Whether Instagram's implementation had exactly this race is not stated in the source material; the case study presents the atomic-increment requirement as part of its own defensive analysis.
What the impact was
A working attack meant full takeover of any account with a phone number on file. The victim would only see an SMS they never requested. Once inside, private messages, creator income and brand accounts were all exposed.
The condition matters: the flow in question is the mobile SMS recovery flow, and the account must have a phone number attached. The web reset flow, which used links, is described as holding up.
Facebook initially could not reproduce the issue. A proof-of-concept video showing 200,000 accepted requests changed that, and the report was paid at $30,000. "Proof of concept" means a working demonstration that shows the problem is real, not just theoretical.
The fix
Facebook fixed the issue in 2019. The write-up does not describe the specific change made on the server side.
The case study offers its own defensive recommendations, which are analysis rather than a description of Facebook's patch:
- Budget guesses per code, not per IP. Attackers can rent IP addresses, but they cannot rent extra attempts against a single code.
- Count before you compare. The attempt counter must be incremented atomically and committed before the guess is checked, otherwise parallel requests all read the same starting count.
- Cap code issuance per account. Otherwise every freshly issued code resets the attacker's budget.
Here is the illustrative verification logic from the case study:
MAX_TRIES = 5def verify_recovery_code(account_id, submitted, request): rec = recovery_codes.get_active(account_id) if rec is None or rec.expires_at < now(): return reject("code_invalid") tries = recovery_codes.increment_attempts(rec.id) if tries > MAX_TRIES: recovery_codes.revoke(rec.id) alert("recovery_bruteforce", account_id, request.ip) return reject("code_invalid") if not constant_time_equals(rec.code_hash, hash_code(submitted)): return reject("code_invalid") if not recovery_codes.consume_once(rec.id): return reject("code_invalid") return issue_reset_session(account_id)
Line by line, in plain words:
MAX_TRIES = 5sets the maximum number of guesses allowed for one code: five.def verify_recovery_code(account_id, submitted, request):defines the function that checks a submitted code. It receives the account, the code the user typed, and the request itself (which carries the source IP).rec = recovery_codes.get_active(account_id)looks up the active recovery code record for that account.if rec is None or rec.expires_at < now():checks whether there is no active code, or the code has expired.return reject("code_invalid")refuses the attempt with a generic message.tries = recovery_codes.increment_attempts(rec.id)increases the attempt counter for this code and returns the new value. This happens before the comparison, so parallel requests queue up on the counter instead of all reading the same old number.if tries > MAX_TRIES:checks whether the cap has been exceeded.recovery_codes.revoke(rec.id)cancels the code entirely, so it cannot be used any more.alert("recovery_bruteforce", account_id, request.ip)raises an alert for the security team, including the account and the source IP.return reject("code_invalid")refuses the attempt.if not constant_time_equals(rec.code_hash, hash_code(submitted)):compares the stored hash of the real code with the hash of the submitted code. "Hash" means a one-way fingerprint of data: you can turn a code into a fingerprint, but not back. "Constant time" means the comparison takes the same amount of time whether it matches or not, so an attacker cannot learn anything from how long the answer takes.return reject("code_invalid")refuses a wrong guess.if not recovery_codes.consume_once(rec.id):tries to mark the code as used, exactly once. If it was already used, this fails.return reject("code_invalid")refuses a code that has already been redeemed.return issue_reset_session(account_id)gives the user a reset session, which is the temporary permission to set a new password.
The important parts: the attempt counter is incremented before the comparison, so concurrent requests serialise on the counter; exceeding the cap revokes the code rather than merely delaying the caller; the comparison is constant time; and consumption is a single atomic operation so a code cannot be redeemed twice.
Variants to test
If you ever test a similar feature, these are the angles the case study lists:
- Per-source limits on any short-code verification. Try login OTPs, password-reset codes, email verification codes and MFA enrolment codes. A positive result is that a burst from one address is throttled but the same code can still be guessed from a second address, with the code remaining valid throughout. "OTP" means one-time password, a code that is valid once. "MFA" means multi-factor authentication, logging in with more than one proof, such as a password plus a code.
- Throttling without blocking. Send sustained traffic from one source and check whether requests are merely slowed or eventually refused outright. A positive result is that the source keeps receiving responses, even at a reduced rate, for the whole validity window.
- Counter races. Fire many verification requests in parallel against one code and look for more accepted attempts than the stated maximum. A positive result is a number of processed guesses above the configured cap.
- Code re-issuance. Request a new code repeatedly and check whether the attempt budget resets each time. A positive result is an unlimited supply of fresh budgets for the same account.
- Reuse after success. Verify a code, then submit it again. A positive result is a second successful reset session from the same code.
- Response differences. Compare the responses for a wrong code, an expired code and a correct code. A positive result is any observable difference that lets an attacker distinguish states without consuming attempts.
Glossary
- Account takeover: when an attacker gains control of someone else's account and can act as them.
- API: a way for one program to talk to another over the internet, like a service counter where you make a specific request and get a specific answer.
- Atomic: done as a single indivisible step, so no other request can see or change things halfway through.
- Brute force: trying many possible values until one works.
- Bounty: money a company pays a researcher for reporting a security problem.
- Cloud compute: rented computers in a data centre, paid for by usage.
- Code space: the full set of possible codes, here one million six-digit numbers.
- Concurrency: doing several things at the same time rather than one after another.
- Constant time: a comparison that takes the same time regardless of the result, so timing reveals nothing.
- CWE-307: a standard label for improper restriction of excessive authentication attempts.
- CWE-362: a standard label for a race condition, where parallel actions interfere with each other.
- Hash: a one-way fingerprint of data; easy to compute, practically impossible to reverse.
- Headers: extra information lines sent with a web request, such as browser type.
- IP address: the number identifying a device or network on the internet.
- MFA: multi-factor authentication, logging in with more than one kind of proof.
- OTP: one-time password, a code valid for a single use.
- Payload: the actual data carried in a request body.
- Proof of concept: a working demonstration that a problem is real.
- Rate limit: a server rule capping how many requests a source may make in a period.
- Race condition: a bug where the result depends on the timing of parallel actions.
- Recovery flow: the steps a service offers to get back into an account after losing access.
- Root cause: the underlying design mistake that makes a vulnerability possible.
- SMS: text message sent to a phone.
- Throttling: slowing or temporarily refusing requests, rather than banning the source.
- Token: a piece of data that proves you are allowed to do something, like a temporary pass.
- Vulnerability: a weakness in a system that an attacker can use.