Skip to content
Account takeover Write-up Intermediate

OTP Bypass Account Takeover to Admin Panel — Ft. Header Injection

The application used IP-based rate limiting for OTP authentication and IP-based restrictions for admin pages, but trusted the X-Forwarded-For header. An attacker could spoof the header to bypass rate limiting and brute-force the OTP, and also access restricted admin interfaces.

Avinash Jain Follow

Published on logicbomb.medium.com

It looks like this year has great promises at least the starting is good. Already 3 bug bounty in the pipeline(just showing off:P) and learned a nice methodology which laid down the opportunity for me to write and share this writeup with everyone.

Avinash Jain (@logicbomb), on logicbomb.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

The target was an online education platform that used OTP authentication for login. The feature under review was the OTP login flow itself: a user supplies a phone number, receives a one-time code, and submits that code to complete authentication. Because the whole login depends on a short numeric secret, the natural question for a tester is how the code can be guessed or bypassed, and how the server defends the endpoint that checks it.

Setup

The work was done as a part-time bug bounty effort against the platform, using Burp Suite's Intruder for the brute force. No account details, versions or specific tooling beyond Intruder are given in the report. The precondition for the attack is simply that the OTP verification endpoint exists and is reachable, and that the server applies some form of IP-based rate limiting to it.

Finding it

The first attempt was a straightforward brute force of the OTP. That attempt hit IP-based rate limiting: after a number of requests the server stopped accepting guesses from the same client IP. The important observation is what that defence implies. If the limit is keyed on the client IP as presented to the upstream server, then changing the IP the server believes the request comes from should reset the counter.

The report explains the mechanism behind this. When a client sits behind a proxy, the proxy forwards the client's address to the server in a specific header, X-Forwarded-For. In some configurations a client can set that header itself, and the server will trust the value, effectively letting the client spoof its own IP address.

Exploitation

Step 1: Bypass the OTP rate limit with a spoofed header

The researcher inserted an X-Forwarded-For header into the OTP verification request, sent the request to Intruder, and configured a Cluster bomb attack so that both the OTP value and the IP address in the header varied across requests. The goal was to brute force the OTP for a given phone number while presenting a different client IP on each attempt.

From the original on logicbomb.medium.com

Because each request appeared to originate from a different IP, the per-IP rate limit no longer applied, and the OTP could be guessed until the correct code was found. As expected, the brute force succeeded and produced a successful OTP login.

At this point the researcher had a valid session for the account tied to that phone number, which is a horizontal privilege escalation: access to another user's account rather than to an administrative one.

Step 2: Recognise the broader header injection

The successful rate-limit bypass made it clear that header injection was present. The same trust in X-Forwarded-For that defeated rate limiting could plausibly be used for something else: bypassing IP-based access control. The report describes the pattern from a previous organisation, where WordPress administrator interfaces were restricted to internal IPs based on the client's address. If an allowed internal address is placed in the header value, the proxy forwards the X-Forwarded-For value even though the connection actually originated from a non-whitelisted IP, and the restricted page or API endpoint becomes reachable.

Concretely, if the header is set as follows, the responding server assumes the request comes from an internal address and allows access to restricted content:

HTTP
X-Forward-For: [redacted]

(The report writes the header name this way in this passage; the earlier and later references use X-Forwarded-For.)

The limiting factor is finding pages that are actually restricted this way. Normally admin pages, admin panels and sensitive endpoints are the ones protected by IP allowlists.

Step 3: Confirm on the blog's WordPress admin

The researcher tried the WordPress administrator interface on the platform's blog page (wp-admin) with the spoofed header, and it returned 200 OK.

From the original on logicbomb.medium.com

Step 4: Directory brute force for more restricted endpoints

With one confirmed hit, the next step was to enumerate further endpoints that might be IP-restricted. The researcher used two public wordlists and path collections for this purpose and passed them to Intruder:

Text
https://github.com/ziadab/AdminBomber/blob/master/AdminBomber.py
https://github.com/s0md3v/Breacher/blob/master/paths.txt
From the original on logicbomb.medium.com

Among all the candidates, one admin page of the platform's CMS catalogue returned 200 OK:

Text
/cms/_admin/logon.php

The researcher describes this as a successful horizontal privilege escalation, reaching an admin login page of the CMS catalogue. The researcher notes that they did not go a level further and attempt to log in to the portal itself, so the report stops at reaching the page.

Root cause

The application (or the proxy in front of it) trusted the X-Forwarded-For header supplied by the client. Any security decision keyed on the client IP, whether the OTP rate limit or an IP allowlist protecting admin interfaces, could therefore be influenced by the attacker. The existing defences did not stop the attack because they were built on a value the client controls: the rate limiter counted requests per presented IP, and the access control compared the presented IP against the internal range. Once the header could be set freely, both checks passed for requests that did not come from a trusted network.

Impact

Two distinct impacts follow from the same flaw. First, the OTP brute force succeeded, giving a successful login to the account associated with the targeted phone number, which is account takeover for that user. Second, IP-restricted administrative surfaces became reachable: the blog's WordPress admin returned 200 OK, and the CMS catalogue admin login page at /cms/_admin/logon.php returned 200 OK. The researcher did not attempt to authenticate to the CMS portal, so the report does not establish what access beyond the login page was possible.

Fix

The recommendation is to allow specifying a list of IPs (or CIDRs) of trusted proxies and load balancers. If a request did not come from one of them, the X-Forwarded-For header should be discarded. The report describes what Nginx does: go through the list starting from the last entry and check each entry against the list of trusted proxies; when an entry is encountered that is not on the list, discard everything before it.

On the timeline given in the report: the bug was reported to the company on 8 January 2021, marked fixed on 11 January 2021, re-tested and the fix confirmed the same day, and rewarded on 20 January 2021.

Variants to test

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

What happened, in plain words

An online education platform let people log in with a one-time password, or OTP: you type your phone number, the platform sends you a short numeric code by SMS, and you type that code back to prove the phone is yours. The whole login rests on that short number, so the obvious question for anyone testing the platform is: can I guess the code? The platform had a defence against guessing, but that defence could be fooled by adding one extra line to the request. Once the researcher could fool it, they could guess the code and log in as the phone's owner. The same trick then opened doors that were supposed to be locked to the outside world, including a WordPress admin area on the platform's blog and an admin login page for their content management system.

This is a beginner's walkthrough of how that worked, step by step, with every concept explained from scratch.

The target and the feature

The target was an online education platform. It used OTP authentication for login. The feature under review was the OTP login flow itself: a user supplies a phone number, receives a one-time code, and submits that code to complete authentication.

A few words first, because everything else builds on them:

  • Authentication is simply proving who you are. Showing a passport at a border is authentication. Typing a password, or a code sent to your phone, is the online equivalent.
  • OTP (one-time password) is a code that works once and then expires. It is usually a handful of digits. The idea is that even if someone steals your password, they still need your phone to receive the code.
  • An endpoint is a specific address on a server that does one job. Think of a large office building: the building is the website, and each endpoint is a particular counter, one for "check this OTP", one for "show the blog", one for "open the admin panel". Each counter has its own address, and you reach it with a request.

Because the whole login depends on a short numeric secret, the natural question for a tester is how the code can be guessed or bypassed, and how the server defends the endpoint that checks it.

The setup

The work was done as a part-time bug bounty effort against the platform. A bug bounty is a programme where a company invites outside people to look for security problems and pays them for reporting what they find, instead of punishing them. The researcher used Burp Suite, a tool that sits between your browser and a website so you can see and edit every request before it leaves, and its Intruder feature, which sends the same request many times with small parts changed each time. That is how guessing at scale is done.

No account details, versions or specific tooling beyond Intruder are given in the report. The precondition for the attack is simply that the OTP verification endpoint exists and is reachable, and that the server applies some form of IP-based rate limiting to it.

Two more terms:

  • IP address is the numeric address of a computer on a network, like a postal address for a building. Every request that reaches a server carries the sender's IP address, so the server can send the answer back.
  • Rate limiting is a cap on how often someone may do something in a period of time. A shop that lets you buy at most two tickets per person is rate limiting. A server that accepts at most a few OTP guesses per minute from one IP address is doing the same thing, to make guessing impractical.

Finding it

The first attempt was a straightforward brute force of the OTP. Brute force means trying every possibility until one works, like working through every combination on a bicycle lock. With a short numeric code, there are few enough combinations that a computer can try them quickly, which is exactly why rate limiting exists.

That attempt hit IP-based rate limiting: after a number of requests the server stopped accepting guesses from the same client IP. The important observation is what that defence implies. If the limit is keyed on the client IP as presented to the upstream server, then changing the IP the server believes the request comes from should reset the counter.

Here is the mechanism the report explains. When you visit a website, your request often does not go straight to the server that does the real work. It passes through an intermediary, a proxy or load balancer, whose job is to receive requests and pass them on. Think of a receptionist in an office: visitors do not walk straight to the right desk, they tell the receptionist, and the receptionist forwards them. Because the real server only sees the receptionist, the receptionist also passes along a note saying who the original visitor was. That note is a header: a small labelled line of extra information attached to a request, separate from the main content.

The specific header used for this is X-Forwarded-For. In some configurations a client can set that header itself, and the server will trust the value, effectively letting the client spoof its own IP address. Spoofing means claiming to be something you are not, like writing a fake return address on an envelope. If the server believes the note rather than checking who actually walked in, the visitor can claim to be anyone.

Exploitation

Step 1: Bypass the OTP rate limit with a spoofed header

The researcher inserted an X-Forwarded-For header into the OTP verification request, sent the request to Intruder, and configured a Cluster bomb attack so that both the OTP value and the IP address in the header varied across requests. Cluster bomb is one of Intruder's attack types: when a request has several places marked for substitution, it tries every combination of the values you supply for each place, like trying every shirt with every pair of trousers. The goal was to brute force the OTP for a given phone number while presenting a different client IP on each attempt.

From the original on logicbomb.medium.com

Because each request appeared to originate from a different IP, the per-IP rate limit no longer applied, and the OTP could be guessed until the correct code was found. As expected, the brute force succeeded and produced a successful OTP login.

At this point the researcher had a valid session for the account tied to that phone number. A session is the server's memory that you have already logged in: after you prove who you are once, the server gives your browser a marker so it does not ask again on every page. That marker is usually a cookie, a small piece of data your browser stores and sends back with each request, like a wristband given at a festival entrance. Holding someone else's session means acting as them.

This is a horizontal privilege escalation: access to another user's account rather than to an administrative one. Picture two office workers on the same floor: horizontal escalation is one worker getting into the other's desk, while vertical escalation would be getting into the manager's office.

Step 2: Recognise the broader header injection

The successful rate-limit bypass made it clear that header injection was present. Header injection means the attacker can add or change the extra labelled lines of a request, and the server acts on them. The same trust in X-Forwarded-For that defeated rate limiting could plausibly be used for something else: bypassing IP-based access control. Access control is the rule about who may enter what. An IP allowlist is a list of addresses that are allowed in, and everyone else is refused, like a guest list at a door.

The report describes the pattern from a previous organisation, where WordPress administrator interfaces were restricted to internal IPs based on the client's address. WordPress is a very common system for running blogs and websites, and its administrator interface, the pages where you manage the site, is normally at a path called wp-admin. If an allowed internal address is placed in the header value, the proxy forwards the X-Forwarded-For value even though the connection actually originated from a non-whitelisted IP, and the restricted page or API endpoint becomes reachable. An API is a set of endpoints meant to be used by programs rather than people, the same way a restaurant has a dining room for guests and a service counter for delivery drivers.

Concretely, if the header is set as follows, the responding server assumes the request comes from an internal address and allows access to restricted content:

HTTP
X-Forward-For: [redacted]

Line by line: X-Forward-For is the name of the header, the label on the note. [redacted] is a special address that always means "this same machine", the computer talking to itself. It is the digital equivalent of writing "I am already inside the building" on the note. The colon separates the label from the value. The report writes the header name this way in this passage; the earlier and later references use X-Forwarded-For.

The limiting factor is finding pages that are actually restricted this way. Normally admin pages, admin panels and sensitive endpoints are the ones protected by IP allowlists.

Step 3: Confirm on the blog's WordPress admin

The researcher tried the WordPress administrator interface on the platform's blog page (wp-admin) with the spoofed header, and it returned 200 OK. A status code is the short number a server sends back to say how the request went. 200 OK means "here you are, everything is fine". A refusal would normally come back as a different number, such as 403 for forbidden.

From the original on logicbomb.medium.com

Step 4: Directory brute force for more restricted endpoints

With one confirmed hit, the next step was to enumerate further endpoints that might be IP-restricted. Enumeration means listing what exists, the way you would walk down a corridor trying every door handle. The researcher used two public wordlists and path collections for this purpose and passed them to Intruder. A wordlist here is simply a long list of common file and folder names to try, because admin pages tend to live at predictable addresses.

Text
https://github.com/ziadab/AdminBomber/blob/master/AdminBomber.py
https://github.com/s0md3v/Breacher/blob/master/paths.txt

Line by line: both lines are web addresses on GitHub, a site where people publish code and files. The first points to a file called AdminBomber.py, a script whose name suggests it hunts for admin pages. The second points to paths.txt, a text file of paths. These are the resources the researcher fed to Intruder as the list of things to try.

From the original on logicbomb.medium.com

Among all the candidates, one admin page of the platform's CMS catalogue returned 200 OK. A CMS is a content management system, the software a site uses to store and publish its pages and products; a catalogue is the list of things the platform offers.

Text
/cms/_admin/logon.php

Line by line: the leading / means this is a path from the root of the website, like a folder path on your own computer. cms is the folder for the content management system. _admin is a folder for administration. logon.php is the file that shows the login form, and .php tells you it is written in the PHP programming language. Put together, it is the address of the CMS admin login page.

The researcher describes this as a successful horizontal privilege escalation, reaching an admin login page of the CMS catalogue. The researcher notes that they did not go a level further and attempt to log in to the portal itself, so the report stops at reaching the page.

Root cause

The application, or the proxy in front of it, trusted the X-Forwarded-For header supplied by the client. Any security decision keyed on the client IP, whether the OTP rate limit or an IP allowlist protecting admin interfaces, could therefore be influenced by the attacker. The existing defences did not stop the attack because they were built on a value the client controls: the rate limiter counted requests per presented IP, and the access control compared the presented IP against the internal range. Once the header could be set freely, both checks passed for requests that did not come from a trusted network. In everyday terms, the guard was checking the name on the visitor's own badge instead of checking it against a list at the door.

Impact

Two distinct impacts follow from the same flaw. First, the OTP brute force succeeded, giving a successful login to the account associated with the targeted phone number, which is account takeover for that user: someone else is now inside your account. Second, IP-restricted administrative surfaces became reachable: the blog's WordPress admin returned 200 OK, and the CMS catalogue admin login page at /cms/_admin/logon.php returned 200 OK. The researcher did not attempt to authenticate to the CMS portal, so the report does not establish what access beyond the login page was possible.

Fix

The recommendation is to allow specifying a list of IPs (or CIDRs) of trusted proxies and load balancers. A CIDR is a compact way of writing a whole range of IP addresses, such as a street name standing for every house on it. If a request did not come from one of them, the X-Forwarded-For header should be discarded. The report describes what Nginx, a common web server and proxy, does: go through the list starting from the last entry and check each entry against the list of trusted proxies; when an entry is encountered that is not on the list, discard everything before it. In other words, only believe the note if the receptionist who handed it over is one you actually employ.

On the timeline given in the report: the bug was reported to the company on 8 January 2021, marked fixed on 11 January 2021, re-tested and the fix confirmed the same day, and rewarded on 20 January 2021.

Variants to test

Glossary

  • Access control: the rule about who is allowed to reach which page or action.
  • Account takeover: gaining control of someone else's account, usually by logging in as them.
  • API: a set of endpoints designed to be used by programs rather than people.
  • Authentication: the act of proving who you are, such as with a password or a code.
  • Brute force: trying every possible value until one works.
  • Bug bounty: a programme where a company pays outsiders for finding and reporting security problems.
  • Burp Suite: a tool that sits between your browser and a website so you can inspect and edit requests.
  • CIDR: a short notation for a whole range of IP addresses.
  • Cluster bomb: an Intruder attack type that tries every combination of the values supplied for several marked positions in a request.
  • CMS (content management system): software used to store and publish a website's pages and content.
  • Cookie: a small piece of data a browser stores and sends back with each request, often used to remember that you are logged in.
  • Endpoint: a specific address on a server that performs one job.
  • Enumeration: systematically listing what exists, such as trying many paths to see which respond.
  • Header: a small labelled line of extra information attached to a request or response.
  • Header injection: adding or changing request headers so the server acts on values the attacker supplied.
  • Horizontal privilege escalation: reaching another user's account at the same level as your own.
  • Intruder: the Burp Suite feature that repeats a request many times with chosen parts changed.
  • IP address: the numeric address of a computer on a network.
  • IP allowlist: a list of IP addresses that are permitted access, with everyone else refused.
  • Load balancer: an intermediary that receives requests and spreads them across servers.
  • Nginx: a widely used web server and proxy.
  • OTP (one-time password): a code that works once and then expires, often sent by SMS.
  • Proxy: an intermediary that receives requests and forwards them to the server that does the real work.
  • Rate limiting: a cap on how many actions may be performed in a period of time.
  • Session: the server's record that you have already logged in, usually kept alive by a cookie.
  • Spoofing: pretending to be something you are not, such as claiming a false IP address.
  • Status code: the short number a server returns to say how a request went, such as 200 OK for success.
  • Wordlist: a long list of common names or paths to try during enumeration.
  • WordPress: a very common system for running blogs and websites, whose admin area is usually at wp-admin.
  • X-Forwarded-For: a header in which a proxy passes along the original client's IP address, and which some servers wrongly trust from the client.

More by Avinash Jain

View all

29 more disclosed reports, best first.

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.