Skip to content
Account takeover Write-up Intermediate

How I can Account Take Over Any Account! | by omarzu

A development subdomain of the target site exposed the same OTP verification flow as the main site, but its rate limiting could be bypassed by adding an X-Forwarded-For header. This let the author brute force the four-digit OTP and take over any account for which they knew the phone number.

medium.com

Published on medium.com

Bugbounty Writeup

Omar Alzughaibi, 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 short account of an account takeover found during subdomain enumeration. The target is referred to only as Target.com, and the researcher's starting point was a subdomain in the form app.dev.Target.com. That subdomain turned out to be a copy of the original site, which made it a second place to exercise the same functionality.

The relevant feature is registration and login by phone number. On the main domain, registration accepts a phone number only, and the account is then verified with a 4-digit OTP. The same OTP flow exists on the app.dev copy of the site.

Setup

No tooling, versions or account roles are described beyond the researcher's own phone number used for registration. The preconditions that matter are:

  1. A reachable subdomain that mirrors the main application (app.dev.Target.com).
  2. A login and registration flow keyed on a phone number.
  3. A 4-digit OTP used to verify that number.
  4. A rate limit on OTP attempts, present on both the main domain and the subdomain.

Finding it

During subdomain enumeration the researcher noticed app.dev.Target.com, a subdomain that was a copy of the original site. After finishing enumeration, the plan was to browse the subdomains one by one and exercise every function to understand the target.

While browsing the main domain, the login function stood out: registration was by number only. Entering a phone number triggered an OTP of 4 digits. A 4-digit code is a small keyspace, so brute forcing it was the first idea, but the application enforced a rate limit.

The researcher then spent effort trying to bypass that rate limit on the main domain, and every attempt failed.

Exploitation

Step 1: try to spoof the origin IP with headers

The first bypass attempt was to change the perceived origin IP using headers:

HTTP
X-Originating-IP: 127.0.0.1X-Forwarded-For: 127.0.0.1X-Remote-IP: 127.0.0.1X-Remote-Addr: 127.0.0.1X-Client-IP: 127.0.0.1X-Host: 127.0.0.1X-Forwared-Host: [redacted]

These are the usual headers an application or an intermediary might trust when deriving the client address. The attempt did not work: the rate limit still applied.

Step 2: try similar endpoints

The next attempt was to use similar endpoints, presumably alternative paths that reach the same OTP verification logic. This did not work either.

Step 3: add extra parameters to the path

The third attempt was to add extra parameters to the path. This also did not work.

After a lot of methods that all failed, the researcher moved on to other functions, but came back to the interesting subdomain app.dev.Target.com and decided to try brute forcing the OTP there. That subdomain had a rate limit too.

Step 4: bypass the rate limit on the subdomain with a single header

Rather than give up, the researcher tried the same class of bypass on the subdomain, changing the origin IP with a header:

HTTP
X-Forwarded-For:

This worked: the rate limit was bypassed on app.dev.Target.com, which would allow the 4-digit OTP to be brute forced there.

With that, the researcher states that any account could be taken over just by knowing the phone number.

Root cause

The report does not describe the server-side implementation, so the exact mistake is not stated. The report does not explain why the empty header worked; it only records that the rate limit was bypassed on the subdomain. Sending the header with an empty value was enough to bypass the rate limit on the subdomain.

The main domain did not behave this way: the same header set, similar endpoints and extra path parameters all failed there. The 4-digit OTP length is what would make the bypass exploitable: once attempts are unlimited, the code could be guessed in a feasible number of requests.

Impact

The researcher states that an attacker who knows a victim's phone number could brute force the 4-digit OTP on the affected subdomain and take over the account. The report frames this as taking over any account, with knowledge of the phone number as the only precondition. The attack depends on the rate limit being bypassable, which was the case on app.dev.Target.com and not on the main domain.

Fix

The fix implied by the behaviour is to stop trusting client-supplied forwarding headers when deriving the address used for rate limiting, or to key the limit on something the client cannot choose, such as the account or phone number being verified, in addition to the address. Applying the same configuration to the subdomain as to the main domain would also have closed the gap. A longer OTP would reduce the feasibility of brute force even if a limit fails.

Variants to test

  1. Send X-Forwarded-For with an empty value, then with rotating values, against any OTP or login endpoint and watch whether the rate limit resets. A positive result is that attempts continue past the configured limit.
  2. Repeat the same header set from the main domain (X-Originating-IP, X-Forwarded-For, X-Remote-IP, X-Remote-Addr, X-Client-IP, X-Host, X-Forwared-Host) on every sibling subdomain, since configuration can differ per host. A positive result is one host where the limit no longer applies.
  3. Try similar endpoints and extra path parameters on each host, as was done here. A positive result is an alternative path that reaches the same verification logic without the limit.
  4. Look for short numeric OTPs (4 digits here) on registration and login flows. A positive result is a code small enough to brute force once any limit is removed.
  5. Check whether the limit is keyed on the phone number or the account rather than the address. A positive result is that changing the header does not help, which tells you the limit is stronger there and where to focus.

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 security researcher was looking at a company's website (called Target.com here) and found a smaller, related copy of it at an address shaped like app.dev.Target.com. On both the main site and this copy, you could sign up and log in using only a phone number. To prove the phone number is yours, the site sent a 4-digit code by SMS, called an OTP. The researcher realised that a 4-digit code is easy to guess by trying every possibility, but the site blocked repeated attempts with a rate limit. On the main site, every trick to get around that limit failed. On the copy at app.dev.Target.com, one simple trick worked: sending a particular header with an empty value. That was enough to get past the rate limit on the copy. The researcher states that with unlimited guesses a 4-digit code can be found, and any account taken over if you know the phone number.

The setup

Before the steps, a few words about what is involved.

A subdomain is a name that sits in front of the main domain name. If the main site is Target.com, then app.dev.Target.com is a subdomain of it. Companies often use subdomains for testing versions, staging copies or separate apps. A copy of the original site means the subdomain runs the same application, with the same pages and the same features, just at a different address.

Subdomain enumeration is the process of finding these subdomains. You cannot see them all from the main page, so you look them up from lists, certificates, search results and other sources. The researcher did this and noticed app.dev.Target.com because it looked interesting: it was a copy of the original site.

Registration and login by phone number means the site does not ask for an email and password. You type your phone number, and the site sends a short code by SMS to prove the number belongs to you. That code is the OTP, a one-time password. Here it was 4 digits, so there are only 10,000 possible codes (0000 to 9999).

Brute forcing means trying every possible value until one works. With 10,000 possibilities, a computer can try them all quickly, which is why a 4-digit OTP is weak on its own.

A rate limit is a cap on how many times you can do something in a period of time. It is like a cash machine that refuses more than three withdrawals in a row: the bank is not saying your card is wrong, it is saying you have asked too often. Rate limits are what stop brute forcing from working, because after a few wrong guesses the site stops answering.

The researcher's preconditions were simple:

  1. A reachable subdomain that mirrors the main application (app.dev.Target.com).
  2. A login and registration flow keyed on a phone number.
  3. A 4-digit OTP used to verify that number.
  4. A rate limit on OTP attempts, present on both the main domain and the subdomain.

No tools, versions or account roles are described beyond the researcher's own phone number used for registration.

Finding it

During subdomain enumeration the researcher noticed app.dev.Target.com, a subdomain that was a copy of the original site. After finishing enumeration, the plan was to browse the subdomains one by one and try every function, to understand how the target works. This is like walking around a new building and opening every door, not to break in, but to learn the layout.

While browsing the main domain, the login function stood out: registration was by number only. Entering a phone number triggered an OTP of 4 digits. A 4-digit code is a small keyspace, meaning the set of possible values is small, so brute forcing it was the first idea. But the application enforced a rate limit.

The researcher then spent effort trying to bypass that rate limit on the main domain, and every attempt failed.

Exploitation

Step 1: try to spoof the origin IP with headers

The first bypass attempt was to change the perceived origin IP using headers:

HTTP
X-Originating-IP: 127.0.0.1X-Forwarded-For: 127.0.0.1X-Remote-IP: 127.0.0.1X-Remote-Addr: 127.0.0.1X-Client-IP: 127.0.0.1X-Host: 127.0.0.1X-Forwared-Host: [redacted]

What is a header? When your browser talks to a website, it sends a request. Along with the request it sends small labelled lines of text called headers. Some headers are standard, like the one that says which browser you use. Others are meant for servers and proxies in the middle of the connection. A proxy is a machine that sits between you and the website, forwarding traffic, and it often adds headers to say where the request really came from.

An IP address is the numeric address of a machine on a network, like a postal address for computers. A rate limit is often keyed on the IP address: the site counts attempts per address, so one visitor cannot try thousands of codes.

Some of these headers, such as X-Forwarded-For, exist so that a proxy can tell the website the original client address. If the website trusts that header from anyone, a client can write whatever address it likes into it. That is called IP spoofing in this context: not changing your real network address, but changing the address the application believes you have.

Line by line, the block above sends seven headers, each claiming the request came from [redacted]:

  • X-Originating-IP: [redacted] claims the originating address is localhost.
  • X-Forwarded-For: [redacted] is the most common proxy header, claiming the client address is localhost.
  • X-Remote-IP: [redacted] and X-Remote-Addr: [redacted] are alternative names some servers look at.
  • X-Client-IP: [redacted] is another alternative.
  • X-Host: [redacted] and X-Forwared-Host: [redacted] claim the requested host is localhost. Note the spelling X-Forwared-Host is as written in the report.

[redacted] is the loopback address, the address a machine uses to refer to itself. Sending it is a common test value: if the application believes it, the request looks like it came from the server itself.

The attempt did not work: the rate limit still applied.

Step 2: try similar endpoints

The next attempt was to use similar endpoints. An endpoint is a specific address on a site that does a specific job, like /login or /verify. Similar endpoints means alternative paths that reach the same OTP verification logic, for example a slightly different URL that ends up at the same code check. The idea is that the rate limit might be attached to one path but not to its twin. This did not work either.

Step 3: add extra parameters to the path

The third attempt was to add extra parameters to the path. A parameter is a piece of information added to a URL, usually after a ?, like ?code=1234. Adding extra parameters, or changing the path slightly, is another way to try to reach the same logic through a route the rate limiter does not recognise. This also did not work.

After a lot of methods that all failed, the researcher moved on to other functions, but came back to the interesting subdomain app.dev.Target.com and decided to try brute forcing the OTP there. That subdomain had a rate limit too.

Step 4: bypass the rate limit on the subdomain with a single header

Rather than give up, the researcher tried the same class of bypass on the subdomain, changing the origin IP with a header:

HTTP
X-Forwarded-For:

This block is a single header with nothing after the colon: an empty value. The header name is X-Forwarded-For, and the value is blank. The reasoning is that if the rate limiter reads this header to decide who the client is, an empty value may be treated as a different client than the real one, or as no client at all, so each request lands in a fresh counting bucket.

This worked: the rate limit was bypassed on app.dev.Target.com, which would allow the 4-digit OTP to be brute forced there. With that, the researcher states that any account could be taken over just by knowing the phone number.

Why it worked

The report does not describe the server-side implementation, so the exact mistake is not stated. The report does not explain why the empty header worked; it only records that the rate limit was bypassed on the subdomain. Sending the header with an empty value was enough to bypass the rate limit on the subdomain.

The main domain did not behave this way: the same header set, similar endpoints and extra path parameters all failed there. The 4-digit OTP length is what would make the bypass exploitable: once attempts are unlimited, the code could be guessed in a feasible number of requests.

Impact

The researcher states that an attacker who knows a victim's phone number could brute force the 4-digit OTP on the affected subdomain and take over the account. The report frames this as taking over any account, with knowledge of the phone number as the only precondition. The attack depends on the rate limit being bypassable, which was the case on app.dev.Target.com and not on the main domain.

Fix

The fix implied by the behaviour is to stop trusting client-supplied forwarding headers when deriving the address used for rate limiting, or to key the limit on something the client cannot choose, such as the account or phone number being verified, in addition to the address. Applying the same configuration to the subdomain as to the main domain would also have closed the gap. A longer OTP would reduce the feasibility of brute force even if a limit fails.

Variants to test

  1. Send X-Forwarded-For with an empty value, then with rotating values, against any OTP or login endpoint and watch whether the rate limit resets. A positive result is that attempts continue past the configured limit.
  2. Repeat the same header set from the main domain (X-Originating-IP, X-Forwarded-For, X-Remote-IP, X-Remote-Addr, X-Client-IP, X-Host, X-Forwared-Host) on every sibling subdomain, since configuration can differ per host. A positive result is one host where the limit no longer applies.
  3. Try similar endpoints and extra path parameters on each host, as was done here. A positive result is an alternative path that reaches the same verification logic without the limit.
  4. Look for short numeric OTPs (4 digits here) on registration and login flows. A positive result is a code small enough to brute force once any limit is removed.
  5. Check whether the limit is keyed on the phone number or the account rather than the address. A positive result is that changing the header does not help, which tells you the limit is stronger there and where to focus.

Glossary

  • Subdomain: a name in front of the main domain, such as app.dev.Target.com under Target.com.
  • Subdomain enumeration: the process of discovering a site's subdomains from lists, certificates and other sources.
  • Endpoint: a specific address on a site that performs a specific job, like a login or verification path.
  • Parameter: a piece of information added to a URL, usually after a ?.
  • Header: a small labelled line of text sent with a web request or response, carrying extra information.
  • Proxy: a machine between the client and the website that forwards traffic and may add headers.
  • IP address: the numeric address of a machine on a network.
  • Loopback address: [redacted], the address a machine uses to refer to itself.
  • IP spoofing (in this context): making an application believe a request came from a different address by writing it into a header.
  • OTP: one-time password, a short code sent to prove you control a phone number or account.
  • Brute forcing: trying every possible value until one works.
  • Keyspace: the set of all possible values, such as the 10,000 codes of a 4-digit OTP.
  • Rate limit: a cap on how many attempts are allowed in a period of time.
  • Rate limit bypass: getting around that cap so attempts keep being accepted.
  • Account takeover: gaining control of someone else's account.
  • X-Forwarded-For: a header used by proxies to tell a website the original client address; if trusted from the client, it can be forged.

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.