How I Could Have Hacked Any Instagram Account
Published on thezerohack.com
Facebook is working constantly to improve its security controls on all of their platforms. As a part of it, they recently increased reward payouts for all critical vulnerabilities including account takeovers.
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 mobile account recovery flow is the target of this write-up. When a user forgets their password, the mobile flow asks for their mobile number and sends a six-digit passcode by SMS. The user then enters that passcode to change the password. Because the code is six digits, there are one million possible values, so the security of the flow rests on rate limiting and on the short lifetime of the code.
The researcher, Laxman Muthiyah, first looked at the web password reset, which uses a link-based mechanism. He tested it for a few minutes and found nothing. He then moved to the mobile recovery flow and found the behaviour described below. Facebook and Instagram fixed the issue and paid a $30000 bounty.

Setup
The testing was done against Instagram's mobile API at i.instagram.com, using requests that mimic the Android client. The relevant client details appear in the captured requests: an Instagram Android user agent, an en-IN, en-US language header, form-encoded bodies and a device_id parameter. The researcher used many machines and IP addresses to generate concurrency, and later estimated the resources a real attacker would need. No special account privileges are described; the flow is the ordinary forgotten-password recovery for a mobile number.
Finding it
The researcher's starting assumption was that if the verify-code endpoint accepted guesses without effective limits, an attacker could try all one million codes and change the password of any account. He expected rate limiting and tested for it.
His first tests confirmed that rate limiting existed. He sent around 1000 requests; 250 went through and the remaining 750 were rate limited. A second batch of 1000 saw many more requests limited. So the server was validating and limiting requests properly at that level.
Two observations stood out. First, the number of requests that could be sent in a fraction of time was limited, but requests could be sent continuously without the source being blocked. There was no blacklisting. Second, after a few days of continuous testing he found two properties that together bypassed the rate limiting:
- A race hazard (race condition).
- IP rotation.
Sending concurrent requests from multiple IPs allowed a large number of requests without being limited. The throughput depends on the concurrency of requests and the number of IPs used. He also noted that the code expires in 10 minutes, which makes the attack harder and means thousands of IPs are needed.
Exploitation
Step 1: Request a passcode for the victim's number
The recovery flow starts with a lookup request that triggers the SMS passcode.
POST /api/v1/users/lookup/ HTTP/1.1
User-Agent: Instagram 92.0.0.11.114 Android (27/8.1.0; 440dpi; 1080×2150; Xiaomi/xiaomi; Redmi Note 6 Pro; tulip; qcom; en_IN; 152830654)
Accept-Language: en-IN, en-US
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Encoding: gzip, deflate
Host: i.instagram.com
Connection: keep-alive
q=mobile_number&device_id=android-device-id-here
The q parameter carries the mobile number and device_id identifies the client. The victim receives a passcode, and that passcode expires in 10 minutes. That window is the entire time available for guessing.
Step 2: Brute-force the verification endpoint
The passcode is checked by a second endpoint.
POST /api/v1/accounts/account_recovery_code_verify/ HTTP/1.1
User-Agent: Instagram 92.0.0.11.114 Android (27/8.1.0; 440dpi; 1080×2150; Xiaomi/xiaomi; Redmi Note 6 Pro; tulip; qcom; en_IN; 152830654)
Accept-Language: en-IN, en-US
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Encoding: gzip, deflate
Host: i.instagram.com
Connection: keep-alive
recover_code=123456&device_id=android-device-id-here
recover_code is the six-digit guess and device_id is the same client identifier. The attack is to send this request repeatedly with different values of recover_code, spread across many IPs and issued concurrently so that the rate limiter does not see enough requests from any one source to block them.
Roughly 200 requests could be sent from a single IP before hitting the rate limit. Using 1000 different machines and IPs, the researcher sent 200k requests in his tests, which is 20 percent of the one million possible codes.
Step 3: Demonstrate the volume
The video shows the 200k requests being sent. In a real attack, the researcher estimates that 5000 IPs are needed to cover the full space within the code's lifetime. That sounds large, but he notes it is easy with a cloud provider such as Amazon or Google, and that the complete attack of one million codes would cost around 150 dollars.
Root cause
Requests could be sent continuously without the source being blocked, and concurrent requests from multiple IPs bypassed the rate limiting. The researcher describes the bypass as a combination of a race hazard and IP rotation: concurrent requests from multiple IPs let a large number of guesses through without being limited. The six-digit code space and the 10-minute expiry are what make the volume of requests necessary; the weakness is that the limiter did not account for concurrency across many sources.
Impact
Under the conditions described, an attacker who can send enough concurrent requests from enough IPs within the 10-minute window could try a large share of the one million codes and, if the correct one is among them, change the password of the targeted account without the owner's consent. The researcher sent 200k requests with 1000 machines and IPs, 20 percent of the one million possible codes; a full attack is estimated at 5000 IPs and around 150 dollars. The attack requires the victim's mobile number and the ability to rent many IPs, and it must complete before the code expires.
Fix
Facebook and Instagram fixed the issue after the researcher provided a proof of concept video of 200k valid requests. The report does not describe the specific change made to the endpoint or the limiter.

Variants to test
- Per-IP rate limits on code verification. Send a burst of guesses from one IP and observe when limiting starts; then repeat the same burst from several IPs concurrently. A positive result is that the combined throughput exceeds the single-IP limit without any source being blocked.
- Absence of blacklisting. Keep sending requests from one source after it has been limited. A positive result is that requests continue to be accepted over time rather than the source being blocked outright.
- Short-lived codes with small search spaces. Look for numeric codes of a few digits with a short expiry. A positive result is that the number of guesses achievable within the expiry, multiplied by the number of IPs available, approaches the size of the code space.
- Race conditions on verification. Fire many verification requests at the same moment for the same code or account. A positive result is that more requests are processed than the limiter should allow in that interval.
- Other recovery endpoints. Apply the same concurrency and IP rotation tests to related endpoints such as lookup and code verification on other mobile APIs. A positive result is the same pattern: per-source limits that do not hold under distributed concurrency.
What happened, in plain words
Instagram, like most online services, lets you get back into your account if you forget your password. One way it does this is through your mobile number: you type in the number, Instagram sends you a short text message (SMS) containing a six-digit code, and you type that code into the app to prove the number is yours. Once you have proved it, you can set a new password.
That six-digit code is the weak point. A six-digit code has one million possible values, from 000000 to 999999. If someone could simply try every single one of those values, they would eventually hit the right one and be able to reset the password of any account whose phone number they knew. The only thing standing in the way is that Instagram should stop you after a few wrong guesses. This is called rate limiting: a rule that says "you may only try this a certain number of times in a certain period".
The researcher, Laxman Muthiyah, found that Instagram's rate limiting on the code-checking step could be worked around. By sending many guesses at the same moment (a race condition) and by spreading them across many different IP addresses (IP rotation), he could get far more guesses through than the limit was supposed to allow. He sent 200,000 requests in his tests, 20 percent of the one million codes, and estimated that a real attacker with enough rented computers and addresses could cover all one million codes within the ten minutes the code stays valid. Facebook and Instagram fixed the problem and paid him a $30000 bounty.

This article walks through the same story from the beginning, explaining every piece of jargon as it comes up. You only need to be comfortable using a browser and a computer to follow it.
The pieces you need to know first
Before the story makes sense, here are a few ideas that come up again and again.
- An API is the way one piece of software talks to another. When you use the Instagram app, the app does not show you a web page; it sends small, structured messages to Instagram's computers and gets structured answers back. Think of it like a restaurant: you (the app) do not walk into the kitchen; you tell the waiter (the API) what you want, and the waiter brings it back. The messages the app sends are called requests, and the answers are called responses.
- An endpoint is one specific address inside that API, one particular thing you can ask for. If the API is the restaurant, each endpoint is a different dish on the menu. The password-recovery flow uses two endpoints: one to ask for a code to be sent, and one to check a code you typed in.
- A request is a single message sent to a server. It has a method (like
POST, meaning "I am sending you some data"), a path (which endpoint), some headers (extra information about the request, such as which app is sending it), and often a body (the actual data, such as a phone number). - A header is a labelled line of extra information attached to a request. For example,
User-Agenttells the server what kind of app or browser is making the request, andHosttells it which website or service is being addressed. - A parameter is a named value sent along with a request. In
q=mobile_number,qis the name andmobile_numberis the value. Parameters are how you tell the server what you want it to act on. - A device ID is a code that identifies a particular installation of an app on a particular phone. It is like a membership card number: it lets the service recognise that the same app is coming back. It is not a password, but it is part of how the app identifies itself.
- Brute force means trying every possible answer until you find the right one. If a lock has a three-digit combination, brute force is trying 000, 001, 002 and so on. It is slow but guaranteed to work eventually, unless something stops you.
- A race condition (the report also calls it a race hazard) is a situation where something goes wrong because two actions happen at almost exactly the same moment, before the system has had time to react to the first one. A simple everyday comparison: a shop has one item left in stock. Two customers click "buy" at the same instant. The shop's system checks the stock for both of them before either purchase is recorded, so both are told the item is available, and the shop has sold something it does not have. In security, a race condition often means a limit that is supposed to apply per action gets bypassed because many actions arrive together.
- Concurrency means doing many things at the same time rather than one after another. Sending 100 requests concurrently means firing them all off together instead of waiting for each to finish before starting the next.
- An IP address is the numeric address that identifies a computer on the internet, a bit like a postal address for a building. A rate limit is often applied per IP address: "this address may only make 200 requests per minute". IP rotation means using many different IP addresses in turn, so that no single address looks like it is sending too much. You can rent large numbers of IP addresses from cloud providers, companies that rent out computers and internet connections by the hour.
- A proof of concept is a demonstration that an attack really works, usually a video or a script, shown to the company so they can see the problem for themselves rather than just reading about it.
- A bounty is a reward a company pays to a security researcher who reports a real problem to them responsibly, instead of exploiting it or selling it.
The starting point: the web reset
Instagram has more than one way to recover an account. The researcher started with the one you reach through a normal web browser. On the website, the reset works by sending you a link by email or text: you click the link and it takes you to a page where you can set a new password. A link-based reset is generally strong, because the link contains a long, hard-to-guess value, and it is tied to your account.
He tested that web flow for a few minutes and found nothing wrong with it. So he moved on to the other route: the mobile recovery flow, the one built into the phone app, which uses a short numeric code instead of a link. That is where he found the behaviour described below.
The mobile recovery flow, step by step
Here is what happens, from the user's point of view, when you forget your password in the app:
- You tell Instagram your mobile number.
- Instagram sends a six-digit passcode to that number by SMS.
- You type the passcode into the app.
- If it is correct, you are allowed to set a new password.
The passcode is only valid for 10 minutes. After that it expires and you have to start again. That ten-minute window is important: it is the entire amount of time an attacker has to guess the right code.
Because the code is six digits, there are one million possible codes. So the whole security of this flow rests on two things: the code expiring quickly, and the server refusing to let anyone try too many guesses. The researcher's question was simple: does the server really refuse?
Testing whether the limit exists
He expected a rate limit, and he tested for it directly. He sent around 1000 requests to the code-checking endpoint. Of those, 250 went through and the other 750 were refused because of the rate limit. He tried another 1000, and this time many more were limited. So the server was clearly counting requests and cutting them off. At first glance the protection was working.
But two things caught his attention:
- The number of requests he could send in a short burst was limited, but he could keep sending requests continuously over time without ever being blocked outright. There was no blacklisting, meaning the server never said "this source is clearly attacking us, ban it". It just slowed him down.
- After a few days of continuous testing, he found two properties that, combined, let him get around the limit:
- a race hazard (race condition), and
- IP rotation.
Sending many requests at the same moment from many different IP addresses let him push a large number of guesses through without being limited. The total number of guesses you can make depends on two things: how many requests you can fire at once (concurrency) and how many different IP addresses you have. And because the code expires in 10 minutes, you need thousands of addresses to have any real chance.
The proof of concept: the two requests
The researcher captured the two requests the app makes during recovery, so the company could see exactly what was happening. Both go to Instagram's mobile API at i.instagram.com, and both pretend to be the official Android app.
Step 1: asking for a passcode
The first request tells Instagram to send the SMS passcode to a phone number.
POST /api/v1/users/lookup/ HTTP/1.1
User-Agent: Instagram 92.0.0.11.114 Android (27/8.1.0; 440dpi; 1080×2150; Xiaomi/xiaomi; Redmi Note 6 Pro; tulip; qcom; en_IN; 152830654)
Accept-Language: en-IN, en-US
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Encoding: gzip, deflate
Host: i.instagram.com
Connection: keep-alive
q=mobile_number&device_id=android-device-id-here
Line by line:
POST /api/v1/users/lookup/ HTTP/1.1is the first line of the request.POSTmeans "I am sending data to you"./api/v1/users/lookup/is the endpoint, the specific address on the server.HTTP/1.1is the version of the language being spoken.User-Agent: Instagram 92.0.0.11.114 Android (...)is a header that tells the server which app is calling. Here it describes the Instagram Android app, its version, and details about the phone it is running on. Servers often behave differently for different apps, so this matters.Accept-Language: en-IN, en-USsays which languages the client prefers, here Indian English and US English.Content-Type: application/x-www-form-urlencoded; charset=UTF-8says how the data in the body is formatted.application/x-www-form-urlencodedis the same simplename=value&name=valueformat you see in a web address after a question mark.charset=UTF-8says the text is encoded in UTF-8, a standard way of representing characters.Accept-Encoding: gzip, deflatesays the client can accept compressed responses, to save bandwidth.Host: i.instagram.comsays which server the request is aimed at.Connection: keep-aliveasks to keep the connection open for further requests, rather than opening a new one each time.- The blank line separates the headers from the body.
q=mobile_number&device_id=android-device-id-hereis the body.qcarries the mobile number (shown here as a placeholder), anddevice_ididentifies the app installation (also a placeholder).
After this request, the victim receives the passcode by SMS, and it expires in 10 minutes. That is the clock the attacker is racing against.
Step 2: guessing the passcode
The second request is the one that checks a code you typed in.
POST /api/v1/accounts/account_recovery_code_verify/ HTTP/1.1
User-Agent: Instagram 92.0.0.11.114 Android (27/8.1.0; 440dpi; 1080×2150; Xiaomi/xiaomi; Redmi Note 6 Pro; tulip; qcom; en_IN; 152830654)
Accept-Language: en-IN, en-US
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Encoding: gzip, deflate
Host: i.instagram.com
Connection: keep-alive
recover_code=123456&device_id=android-device-id-here
Line by line:
POST /api/v1/accounts/account_recovery_code_verify/ HTTP/1.1targets a different endpoint, the one that verifies a recovery code.- The headers are the same as before: the same app identity, the same language preferences, the same body format, the same compression and connection settings, and the same host.
recover_code=123456&device_id=android-device-id-hereis the body.recover_codeis the six-digit guess (here shown as123456, an example value), anddevice_idis the same client identifier as in the first request.
The attack is to send this second request over and over, each time with a different value of recover_code, spread across many IP addresses and fired concurrently, so that the rate limiter never sees enough requests from any one source to block them.
Step 3: how many guesses got through
Roughly 200 requests could be sent from a single IP address before hitting the rate limit. Using 1000 different machines and IP addresses, the researcher sent 200,000 requests in his tests. That is 20 percent of the one million possible codes.
The video shows those 200,000 requests being sent. In a real attack, he estimates that 5000 IP addresses would be needed to cover the whole space within the ten minutes the code lives. That sounds like a lot, but he points out it is easy to arrange through a cloud provider such as Amazon or Google, and that the complete attack, covering all one million codes, would cost around 150 dollars.
Why it worked
The rate limit could be bypassed by sending concurrent requests from many IP addresses. But the limit did not account for many sources acting together at the same moment. By combining a race hazard with IP rotation, the researcher could send a large number of requests without being limited.
There was also no blacklisting. A source that kept sending requests was slowed down but never cut off entirely, so the attack could continue for as long as the code was valid. The six-digit code space and the ten-minute expiry are what make the volume of requests necessary in the first place; the weakness is that the limiter did not hold up when requests came concurrently from many places.
What an attacker could have done
Under the conditions described, an attacker who can send enough concurrent requests from enough IP addresses within the ten-minute window could try a large share of the one million codes. If the correct code is among the guesses, the attacker can change the password of the targeted account without the owner's consent. That is an account takeover: someone else ends up in control of your account.
The researcher sent 200,000 requests with 1000 machines and IP addresses, 20 percent of the one million possible codes. A full attack is estimated at 5000 IP addresses and around 150 dollars. The attack requires knowing the victim's mobile number and being able to rent many IP addresses, and it must finish before the code expires.
The fix
Facebook and Instagram fixed the issue after the researcher provided a proof of concept video showing 200,000 valid requests. The report does not describe the specific change made to the endpoint or to the limiter.

How you could look for the same kind of problem
These are the same checks the researcher describes, written so that someone new to security can follow the idea. They are meant for systems you own or are authorised to test.
- Per-IP rate limits on code verification. Send a burst of guesses from one IP address and watch when the limiting starts. Then repeat the same burst from several IP addresses at the same time. A positive result is that the combined throughput exceeds the single-IP limit without any source being blocked.
- Absence of blacklisting. Keep sending requests from one source after it has been limited. A positive result is that requests continue to be accepted over time rather than the source being blocked outright.
- Short-lived codes with small search spaces. Look for numeric codes of a few digits with a short expiry. A positive result is that the number of guesses achievable within the expiry, multiplied by the number of IP addresses available, approaches the size of the code space.
- Race conditions on verification. Fire many verification requests at the same moment for the same code or account. A positive result is that more requests are processed than the limiter should allow in that interval.
- Other recovery endpoints. Apply the same concurrency and IP rotation tests to related endpoints such as lookup and code verification on other mobile APIs. A positive result is the same pattern: per-source limits that do not hold under distributed concurrency.
Glossary
- API: the way one piece of software talks to another; a set of structured messages a program can send to a service and get answers back.
- Endpoint: one specific address inside an API, one particular thing you can ask for.
- Request: a single message sent to a server, with a method, a path, headers and often a body.
- Response: the answer a server sends back to a request.
- Header: a labelled line of extra information attached to a request or response, such as which app is calling or which host is being addressed.
- Parameter: a named value sent with a request, such as
q=mobile_number. - Body: the part of a request that carries the actual data, such as a phone number or a code.
- POST: a request method meaning "I am sending data to you".
- User-Agent: a header that tells the server what kind of app or browser is making the request.
- Host: a header that says which server the request is aimed at.
- Content-Type: a header that says how the data in the body is formatted.
- application/x-www-form-urlencoded: a simple
name=value&name=valueformat for sending data in a request body. - UTF-8: a standard way of encoding text characters.
- gzip / deflate: compression formats used to make responses smaller.
- keep-alive: a setting that asks to keep a connection open for further requests instead of opening a new one each time.
- Device ID: a code that identifies a particular installation of an app on a particular phone.
- Passcode: a short numeric code sent by SMS to prove you control a phone number.
- Brute force: trying every possible answer until you find the right one.
- Rate limiting: a rule that only allows a certain number of requests in a certain period, often per IP address.
- Blacklisting: blocking a source outright because it is behaving badly, rather than just slowing it down.
- Race condition (race hazard): a problem that arises when two actions happen at almost the same moment, before the system has had time to react to the first one.
- Concurrency: doing many things at the same time rather than one after another.
- IP address: the numeric address that identifies a computer on the internet.
- IP rotation: using many different IP addresses in turn so that no single address looks like it is sending too much.
- Cloud provider: a company that rents out computers and internet connections by the hour, such as Amazon or Google.
- Proof of concept: a demonstration that an attack really works, usually a video or a script.
- Bounty: a reward a company pays to a security researcher who reports a real problem responsibly.
- Account takeover: a situation where someone else gains control of your account without your consent.
- Expiry: the point at which a code or link stops being valid.