🗂️PortSwigger Lab Writeup: 2FA Bypass using a Brute-Force Attack

🎯 Objective
The objective of this lab is to exploit an multi-factor authentication weakness where the app is vulnerable to brute-forcing. The goal is to bypass the authentication of carlos and log in to the account.
- Lab URL:
https://portswigger.net/web-security/authentication/multi-factor/lab-2fa-bypass-using-a-brute-force-attack - Category: Authentication
- Difficulty: Expert
🧪 Exploitation Steps
🕵️Step 1: Observe the Website
- Firstly open the lab URL in your browser, and observe what it is about and how it works.


- At first glance, the website seems to be a blogging website with a login page. In the lab description, it is mentioned that we need to bruteforce the password of user -
carlosand log in to account.
📝Step 2: Try MFA
- Now we will first observe how multi-factor authentication works by logging in as
carlos:montoya.
- Now, we are being redirected to
/login2page for entering OTP sent on mail. - Since, we don't have access to Email Client, try guessing OTPs and see how rate limiting is done.

- Now, after 3 failed attempts, we are again sent back on
/loginpage for entering credentials again. - Therefore, after every 3 attempts, we must perform the whole process of authentication again.
🚀Step 3: Brute-Force MFA code
- Now send the
GET /login2request from HTTP history to Repeater throughCtrl + R
- Change the cookie
verify:wienertoverify:carlosand send the request to generate the 2FA code.
- Now send the
POST /login2request from HTTP history to Intruder throughCtrl + I
- Change the cookie
verify:wienertoverify:carlosto crack the 2FA code forcarlos - Add the marker on mfa-code value and set the attack type to Sniper.

- In payloads section, set the payload type to Brute forcer
- Set the character set to
0123456789and Min/Max length to 4 as mfa code is of 4 digit.
- After configuring everything, start the attack.

- In all the payloads, you will see a unique response
302 Foundwhich means we have successfully cracked the MFA code forcarlos
🧑💼Step 4: Log in as carlos
- Enter the credentials
carlos:montoyain login page and send the request.
- Now change the URL from
/login2to/myaccount?id=carlos - Hence, we are now successfully being logged in as
carloswithout completing 2FA. - Now, Right-click on this request and select Show response in browser. Copy the URL and load it in the browser.

- And Finally, the Lab is solved.
🧠 Conclusion
- This lab involves a weak 2FA implementation, where the OTP verification step lacks proper brute-force protection and rate limiting.
- Since the application allows unlimited OTP guesses, an attacker can use automated tools like Intruder to iterate through all 4-digit codes and find the valid one.
- By brute-forcing the OTP for
carlosand observing the302 Foundresponse, we successfully bypassed MFA and accessed his account.