Skip to content
CSRF Write-up Intermediate

2FA bypass via CSRF attack

The 2FA disable function on pandao.ru was vulnerable to CSRF because the anti-CSRF token did not expire and could be reused across accounts. An attacker could craft a malicious HTML page that, when visited by a logged-in victim, disables the victim's two-factor authentication.

Vishal Bharad Follow

Published on medium.com

#### Vishal Bharad

Vishal Bharad, 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

Mail.ru runs a bug bounty programme on HackerOne. The vulnerability described here was found on Pandao.ru, which the author identifies as the extended programme name for the Mail.ru programme. The affected feature is the account settings page where a user can enable or disable two factor authentication:

Text
https://pandao.ru/profile/settings

Normally, disabling 2FA is a sensitive account action: the user must be authenticated, and the request that turns 2FA off should only be accepted when it genuinely comes from that user's own session and intent. The author's finding is that this request could be triggered cross site, so an attacker could turn off a victim's second factor.

The author frames the bug as a 2FA bypass achieved through a client side attack, CSRF. He lists the common ways 2FA is bypassed:

  1. Bypassing 2FA using conventional session management
  2. Bypassing 2FA via OAuth mechanism
  3. Bypassing 2FA via brute force
  4. Bypassing 2FA using race conditions (rare)
  5. Bypassing 2FA using a modified response
  6. Bypassing 2FA using an activation link
  7. Bypassing 2FA on the password reset page

The technique here is different: the second factor is not circumvented at login, it is removed from the account beforehand by making the victim's browser send the disable request.

Setup

Two accounts on Pandao.ru are needed:

  1. An attacker account, used to capture the legitimate disable 2FA request.
  2. A victim account, used to fire the generated CSRF proof of concept while logged in.

The only tool the author lists is BurpSuite, used to intercept the disable 2FA request and to generate the CSRF PoC. The victim's session is run in a private browser window so that the two accounts do not share cookies.

Finding it

The author went looking for the bug deliberately, by trying to disable 2FA through a CSRF file. When he generated the CSRF PoC from the captured request, he saw that a token was present in the PoC. That is the expected anti CSRF measure, and it should have stopped the attack.

What he then observed was that the token never expired: the same token could be used again and again to disable 2FA on another account. That is the weakness that makes the CSRF work despite the token being there.

Exploitation

Step 1: create the two accounts

Go to the settings page and sign up for two accounts, one for the attacker and one for the victim:

Text
https://pandao.ru/profile/settings

Step 2: capture the disable 2FA request and generate a CSRF PoC

Log in to the attacker account, perform the disable 2FA action, and capture the resulting request in Burp Suite. Burp's CSRF PoC generator is then used to produce an HTML page that reproduces the request. The report does not include the captured request itself, so the exact endpoint, parameters and headers are not shown here.

Step 3: save the PoC as an HTML file

Save the generated CSRF PoC with the .HTML extension. This file is the payload that will be opened in the victim's browser.

Step 4: fire the PoC in the victim's session

Log in to the victim account in a private browser window and open the CSRF file. The victim's browser sends the disable 2FA request with the victim's cookies. The result, as the author describes it, is that 2FA is disabled on the victim's account, which is the 2FA bypass.

A video was attached to the report to demonstrate the vulnerability. The author also notes that the report was submitted to Mail.ru on 9 August, and that the programme team reviewed the report, the steps to reproduce and the PoC video.

Image for post
Image for post From the original on medium.com

Root cause

The disable 2FA action is reachable cross site and is not protected by a token that is bound to the user's session and single use. A token is generated and appears in the CSRF PoC, but it does not expire and can be reused to disable 2FA on another account. In effect the token provides no protection against CSRF: the same token could be used again and again to disable 2FA on another account.

Impact

An attacker who can get a victim to open the crafted HTML page, while the victim is logged in to Pandao.ru, can turn off the victim's two factor authentication. From that point the victim's second factor is off. The attack requires user interaction (the victim must open the file or page) and a logged in victim session.

The author notes that Pandao.ru is in the extended scope of the Mail.ru programme and that the programme does not pay for client side attacks, so no bounty was awarded. The author still considered it worth reporting.

Fix

The report does not describe any fix applied by the vendor. The change that addresses the root cause is to bind the anti CSRF token to the user's session and make it single use, so that a token captured from one account cannot be replayed against another, and to reject the disable 2FA request when the token does not match the current session. Requiring the current password or a fresh 2FA code before disabling 2FA would add a second barrier.

Variants to test

  1. Token reuse across accounts. Capture the disable 2FA request from your own account, generate a CSRF PoC, and open it in a second account's session. A positive result is that 2FA is disabled on the second account.
  2. Token that never expires. Take a token from an old request and replay it much later, or after logging out and back in. A positive result is that the old token is still accepted.
  3. Other sensitive settings. Apply the same capture and replay to email change, password change and recovery options on the settings page. A positive result is that the change is applied in the victim's session without any user confirmation.
  4. Missing or weak token check. Remove the token parameter from the captured request and resend it. A positive result is that the action still succeeds, showing the token is not actually validated.

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

What happened, in plain words

A security researcher named Vishal Bharad found a way to switch off another person's second lock on their account, without knowing that person's password or their one time code. The trick is called CSRF, and it works because the website accepted a request that came from a page the attacker controlled.

Let me unpack that. Many websites let you protect your account with two factor authentication, usually shortened to 2FA. The idea is simple: your password is the first factor (something you know), and a code from your phone is the second factor (something you have). Even if someone steals your password, they still cannot log in without the code. Turning 2FA off is therefore a very sensitive action, because it lowers the account back to password only protection.

The researcher found that the request which turns 2FA off could be triggered from a different website. An attacker could prepare a small HTML page, get the victim to open it while logged in, and the victim's own browser would send the request to Pandao.ru and switch 2FA off.

A quick everyday comparison: imagine a bank counter where the clerk accepts a withdrawal slip that someone else filled in, as long as it is on the bank's own paper. The paper looks official, so the clerk processes it. CSRF is the web version of that: the server sees a request that looks like it came from its own site, so it acts on it, even though the person who wrote the request was someone else.

This was found on Pandao.ru, which the author describes as the extended programme name for the Mail.ru bug bounty programme on HackerOne. A bug bounty programme is a scheme where a company invites outside researchers to look for security problems and report them, sometimes for a reward.

The author frames the finding as a 2FA bypass achieved through a client side attack, CSRF. He lists the common ways people bypass 2FA:

  1. Bypassing 2FA using conventional session management
  2. Bypassing 2FA via OAuth mechanism
  3. Bypassing 2FA via brute force
  4. Bypassing 2FA using race conditions (rare)
  5. Bypassing 2FA using a modified response
  6. Bypassing 2FA using an activation link
  7. Bypassing 2FA on the password reset page

His technique is different from all of those. He does not try to get past the code at the login screen. Instead he removes the second factor from the account beforehand, by making the victim's browser send the request that disables it. Once 2FA is off, the second factor is gone.

The pieces you need to understand first

Before the steps make sense, here are the few ideas the whole attack rests on.

A request. When you click a button on a website, your browser sends a request to the server: a short message saying what you want. The server replies, and the page updates. Every action you take online, from logging in to changing a setting, is a request.

A cookie. After you log in, the server gives your browser a small piece of data called a cookie, which the browser stores and sends back with every later request to that site. The cookie is how the server recognises you: it is like a wristband at an event, proving you already checked in. If someone else's browser sends your cookie, the server treats that request as you.

A token. Because cookies are sent automatically, websites add a second check for sensitive actions: a hidden random value, called a token, that must be included in the request. The server compares it with the value it expects. The idea is that an attacker's page cannot know this random value, so it cannot forge a valid request. A token is like a numbered claim ticket that the counter checks against its records before handing over the goods.

CSRF (Cross Site Request Forgery). This is the vulnerability class. It means a request that changes something on a site can be triggered from a different site, using the victim's own logged in browser and cookies. The attacker does not steal anything; they make the victim's browser do the work.

Burp Suite. A tool used by security testers. It sits between your browser and the website, so you can pause a request, look at it, change it, and send it again. It also has a feature that takes a captured request and writes an HTML page which reproduces it. That page is the CSRF proof of concept, often shortened to PoC: a small demonstration that proves the bug is real.

A private browser window. A separate window that does not share cookies with your normal window. It lets you be logged in as two different people at the same time, one in each window, without the sessions mixing.

Setting up

Two accounts on Pandao.ru are needed:

  1. An attacker account, used to capture the legitimate disable 2FA request.
  2. A victim account, used to fire the generated CSRF proof of concept while logged in.

The only tool the author lists is BurpSuite, used to intercept the disable 2FA request and to generate the CSRF PoC. The victim's session is run in a private browser window so that the two accounts do not share cookies. Without that separation, the browser would send the attacker's cookie when you meant to test the victim, and the test would prove nothing.

Finding it

The author went looking for the bug deliberately, by trying to disable 2FA through a CSRF file. In other words, he did not stumble on it: he took a sensitive action, turned it into a standalone page, and checked whether the site would accept it from another context.

When he generated the CSRF PoC from the captured request, he saw that a token was present in the PoC. That is the expected anti CSRF measure, and it should have stopped the attack. Seeing a token there would normally end the test.

What he then observed was that the token never expired: the same token could be used again and again to disable 2FA on another account. That is the weakness that makes the CSRF work despite the token being there. The lock was on the door, but the same key opened every door and never wore out.

Exploitation

Step 1: create the two accounts

Go to the settings page and sign up for two accounts, one for the attacker and one for the victim:

Text
https://pandao.ru/profile/settings

This is the account settings page, the place where a user manages their profile and their security options, including 2FA. Two accounts are needed because the attack is about one person's browser acting on another person's account: you need one account to prepare the request and a second one to receive it.

Step 2: capture the disable 2FA request and generate a CSRF PoC

Log in to the attacker account, perform the disable 2FA action, and capture the resulting request in Burp Suite. Burp's CSRF PoC generator is then used to produce an HTML page that reproduces the request.

The reason for doing this on your own account first is safety and clarity: you are recording exactly what a real disable request looks like, without touching anyone else. The generator then turns that recording into a page that any browser can open and that will send the same request.

The report does not include the captured request itself, so the exact endpoint, parameters and headers are not shown here.

Step 3: save the PoC as an HTML file

Save the generated CSRF PoC with the .HTML extension. This file is the payload that will be opened in the victim's browser. An HTML file is just a web page stored on disk; opening it in a browser runs it exactly as if it had been loaded from a website.

Step 4: fire the PoC in the victim's session

Log in to the victim account in a private browser window and open the CSRF file. The victim's browser sends the disable 2FA request with the victim's cookies. The result, as the author describes it, is that 2FA is disabled on the victim's account, which is the 2FA bypass.

Notice why the private window matters here: the victim must be logged in when the page is opened, because the browser has to attach the victim's cookie to the request.

A video was attached to the report to demonstrate the vulnerability. The author also notes that the report was submitted to Mail.ru on 9 August, and that the programme team reviewed the report, the steps to reproduce and the PoC video.

Image for post
Image for post From the original on medium.com

Why it works

The disable 2FA action is reachable cross site and is not protected by a token that is bound to the user's session and single use. A token is generated and appears in the CSRF PoC, but it does not expire and can be reused to disable 2FA on another account.

In effect the token provides no protection against CSRF: the same token could be used again and again to disable 2FA on another account. To go back to the claim ticket comparison: the counter checks that the ticket is one of its own, but never checks whose ticket it is, and never takes it out of circulation.

What an attacker could do with it

An attacker who can get a victim to open the crafted HTML page, while the victim is logged in to Pandao.ru, can turn off the victim's two factor authentication. From that point the victim's second factor is off.

The attack requires user interaction (the victim must open the file or page) and a logged in victim session. That is the limit of the bug: it is not something the attacker can do silently from a distance, it needs the victim to take one action while signed in.

The author notes that Pandao.ru is in the extended scope of the Mail.ru programme and that the programme does not pay for client side attacks, so no bounty was awarded. The author still considered it worth reporting.

How to fix it

The report does not describe any fix applied by the vendor. The change that addresses the root cause is to bind the anti CSRF token to the user's session and make it single use, so that a token captured from one account cannot be replayed against another, and to reject the disable 2FA request when the token does not match the current session. Requiring the current password or a fresh 2FA code before disabling 2FA would add a second barrier.

Things to try yourself

If you want to practise the same idea on a site you are allowed to test, these are the variations worth checking. Each one starts from the same capture and replay routine.

  1. Token reuse across accounts. Capture the disable 2FA request from your own account, generate a CSRF PoC, and open it in a second account's session. A positive result is that 2FA is disabled on the second account.
  2. Token that never expires. Take a token from an old request and replay it much later, or after logging out and back in. A positive result is that the old token is still accepted.
  3. Other sensitive settings. Apply the same capture and replay to email change, password change and recovery options on the settings page. A positive result is that the change is applied in the victim's session without any user confirmation.
  4. Missing or weak token check. Remove the token parameter from the captured request and resend it. A positive result is that the action still succeeds, showing the token is not actually validated.

Glossary

  • 2FA (two factor authentication): a login protection that asks for two different things, usually a password plus a one time code from a phone, so a stolen password alone is not enough.
  • 2FA bypass: any way of getting into an account, or removing the protection from it, without supplying the second factor.
  • Account settings page: the part of a website where a logged in user changes their profile and security options, such as turning 2FA on or off.
  • Anti CSRF token: a random value a site puts into sensitive forms and checks on the server, so that a page from another site cannot forge a valid request.
  • Attacker account: in this test, the researcher's own account, used to record what a real disable 2FA request looks like.
  • Browser: the program you use to view web pages, which stores cookies and sends requests on your behalf.
  • Bug bounty programme: a scheme where a company invites outside researchers to report security problems, sometimes for a reward.
  • Burp Suite: a testing tool that sits between browser and website so requests can be paused, inspected, changed and replayed, and that can generate a CSRF PoC from a captured request.
  • Client side attack: an attack that relies on the victim's own browser to send the harmful request, rather than on breaking into the server directly.
  • Cookie: a small piece of data a site stores in your browser after you log in, sent back with later requests so the server recognises you.
  • CSRF (Cross Site Request Forgery): a bug where a request that changes something on a site can be triggered from a different site, using the victim's logged in browser and cookies.
  • CSRF PoC: a small HTML page that reproduces a captured request, used to demonstrate that the request can be triggered cross site.
  • Endpoint: the specific address on a server that a request is sent to.
  • Extended scope: an arrangement where a programme also covers related domains or products beyond its main target.
  • HackerOne: a platform where bug bounty programmes are listed and reports are submitted and discussed.
  • Header: extra information attached to a request or response, such as what kind of content it carries.
  • HTML file: a web page stored as a file, which a browser can open and run just like a page loaded from a website.
  • Parameter: a named value sent with a request, such as a setting name or a token.
  • Payload: the content an attacker delivers to make the attack happen, here the HTML file.
  • Private browser window: a separate window that does not share cookies with your normal window, useful for being logged in as two different users at once.
  • Proof of concept (PoC): a small, working demonstration that proves a reported bug is real.
  • Race condition: a bug where two actions happening at almost the same moment produce an unintended result.
  • Request: the message a browser sends to a server asking it to do something.
  • Session: the server's record of your logged in state, tied to your cookie, so it knows which requests belong to you.
  • Token: a random value used to prove a request is legitimate, checked by the server against what it expects.
  • Victim account: in this test, the second account whose logged in browser is made to send the disable request.

More by Vishal Bharad

View all

5 more disclosed reports, best first.

More from Mail.ru

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site request forgery (CSRF)

The lesson behind this report.

Another site makes a signed-in user's browser perform an action they did not intend.