Hello! In our last lesson, we explored how flaws in password reset workflows can lead to complete account takeover. We saw how attackers can either leak a reset token through parameter tampering or predict it due to weak generation logic.
Today, we'll tackle the next logical barrier an attacker faces: Multi-Factor Authentication (MFA). This lesson directly addresses the learning outcome: Identify and exploit insecure multi-factor authentication (MFA) implementations for bypass.
While MFA provides a significant security boost over single-factor authentication, it's not infallible. A poorly implemented MFA system can often be bypassed, rendering it ineffective. We will explore the common weak points in MFA implementations, focusing on three main categories of attack:
- Brute-Forcing OTPs: Exploiting the lack of rate limiting.
- Response Manipulation: Abusing excessive trust in the client-side.
- Logic & State Management Flaws: Bypassing the MFA step entirely.
Let's dive into how you, as a penetration tester or bug bounty hunter, can dismantle this crucial security control when it's not built correctly.
1. Brute-Forcing OTPs via Rate Limiting Bypass
A One-Time Password (OTP), especially a short numeric one (e.g., 4-6 digits), is theoretically guessable. A 4-digit code has only 10,000 possible combinations. The primary defense against this is rate limiting—locking an account or delaying subsequent attempts after a small number of incorrect guesses.
However, attackers can succeed if they find an endpoint that is supposed to validate the OTP but, for some reason, lacks this rate-limiting protection. A very common pattern is finding a legacy or alternative API endpoint that is still active but less secure than the primary one.
The following video provides an excellent real-world demonstration of this concept.
Exploiting Rate Limiting to Brute-Force OTP | crAPI |
In the video 'Exploiting Rate Limiting to Brute-Force OTP' by Medusa, the presenter targets a password reset function protected by a 4-digit OTP. Watch how they discover and exploit an older, unprotected API version to bypass the rate limiting present on the current version.
Watch from 01:21 to 08:11. Pay close attention to these key moments: 01:21 - 04:01: The initial attempt to brute-force the OTP on the primary API (/v3/) fails due to rate limiting. 04:01 - 07:15: The key insight. The presenter notices other application endpoints use API version 2 (/v2/) and hypothesizes that an older OTP verification endpoint might exist and be less secure. This is a form of 'Improper Asset Management'. 07:15 - 08:11: The attacker successfully brute-forces the OTP by targeting the /v2/ endpoint, which lacks rate limiting, and achieves account takeover.
This video demonstrates a critical mindset for a bug hunter: if one door is locked, check for other, older doors that may have been left open. Always enumerate API versions and test for inconsistencies in security controls across them.
2. Bypassing MFA via Response Manipulation
Another common implementation flaw occurs when the server correctly validates the OTP but leaves the final decision of "what to do next" up to the client-side code.
The flow looks like this:
- The user submits the OTP.
- The server checks if the OTP is correct and sends back a response, like
{"success": false}. - The client-side JavaScript receives this response and is supposed to show an error message.
An attacker with Burp Suite can intercept the server's response before it reaches their browser and simply flip the false to true. If the server-side application logic doesn't maintain its own state and assumes that a successful OTP check must have happened if the client proceeds, the bypass will be successful.
This next video shows this exact technique.
Bypass OTP Verification with Burp Suite (Response Manipulation Method) | Ethical Hacking @itspyguru
The video 'Bypass OTP Verification with Burp Suite (Response Manipulation Method)' by pyGuru demonstrates how to bypass both email and phone OTP verification by modifying the server's response.
Watch from 04:47 to 11:03. Focus on how the attacker uses Burp Suite's 'Intercept response' feature. 04:47 - 08:50: An incorrect email OTP is entered. The server responds with a status indicating failure (in this case, d=2). The attacker modifies this to d=1 (success) and forwards the response, successfully tricking the application. 08:50 - 11:03: The same technique is repeated to bypass the phone number verification step, proving it's a systemic vulnerability.
This vulnerability is fundamentally an issue of broken state management. The server should not just tell the client whether the OTP was correct; it should update its own internal session state to flag that the user has successfully completed the MFA step. Subsequent requests should be validated against this server-side state, not just what the client claims.
Test your understanding!
You are testing an application's MFA. After you log in with a username and password, you are redirected to /mfa-verify. You enter an incorrect 6-digit code. The application makes a POST request to /api/mfa/check_code with your code, and the server returns a JSON response: {"status": "INVALID_CODE"}.
What would be your immediate next step to test for a response manipulation vulnerability?
Show answer
Using a tool like Burp Suite, you would resend the same request with the incorrect code. This time, you would use the "Intercept > Response to this request" feature. When the server's response {"status": "INVALID_CODE"} is caught in Burp, you would modify it to what a successful response might look like, for example, {"status": "SUCCESS"} or {"status": "VALID_CODE"}. You then forward this modified response to your browser. If the application proceeds as if you entered the correct code, you have successfully bypassed the MFA check.
3. Exploiting Logic Flaws in MFA Workflows
Beyond brute-forcing and response manipulation, a wide array of logic flaws can allow an attacker to bypass MFA entirely. These often involve skipping the MFA step or abusing related functionality.
The article below provides an excellent catalog of these techniques. We will use it as a guide to explore several key MFA bypass patterns.
The article '2FA/MFA/OTP Bypass' from VeryLazyTech serves as a comprehensive checklist for various MFA bypass techniques. It covers everything from simple forced browsing to more advanced session tricks.
Read the following sections from the article to get a broad overview of common logic flaws: Direct Endpoint Access Token-Based Exploits (focus on Token Reuse and Token Exposure) Account and Session Tricks (focus on Password Reset and Session Manipulation) These sections outline some of the most frequently found MFA bypasses in bug bounty hunting.
Let's summarize the key takeaways from that reading:
- Direct Endpoint Access (Forced Browsing): This is one of the most common MFA flaws. After entering a correct password, the application sets an authenticated session but before verifying the MFA token. An attacker can simply ignore the MFA prompt page and browse directly to a privileged internal page (e.g.,
/dashboard,/my-profile). If the server doesn't check for a specific "MFA-completed" flag for every request to a privileged area, access is granted. - Token Reuse: A high-security token should be single-use. If the application fails to invalidate a token immediately after it's used, an attacker who obtains a valid token once might be able to reuse it for subsequent logins.
- Token Exposure: Sometimes, the application leaks the valid MFA token in an API response right after it's generated. This is often done to support client-side validation logic, but it completely defeats the purpose of MFA if an attacker can see it. Always inspect the full HTTP response after triggering an OTP generation.
- Bypass via Password Reset: As we saw in the last lesson, password reset is a critical function. Some applications are coded to disable MFA temporarily or permanently for an account once a password reset is successfully completed. An attacker who compromises a user's email can use the password reset flow not just to change the password, but also to bypass the MFA requirement.
- Other Advanced Vectors: While we focused on the most common, be aware of other vectors mentioned in the resources like exploiting backup codes, using old sessions, or even leveraging social engineering with an adversary-in-the-middle (AiTM) phishing attack, as illustrated in the diagrams from Ars Technica and DZone. These phishing attacks use a reverse proxy to intercept credentials and the MFA token/session cookie in real time.
Conclusion
Multi-Factor Authentication is a powerful security layer, but its effectiveness hinges entirely on its implementation. As an attacker or tester, your job is to scrutinize this implementation for shortcuts, oversights, and logic flaws.
Key Takeaways:
- MFA is only as strong as its weakest link. A bypass anywhere in the workflow undermines the entire control.
- Think like an attacker: If rate limiting is on, is there an endpoint where it's off? If the server sends a failure message, can I change it to success? If I'm asked for a token, can I just skip that step and go somewhere else?
- Your primary tools for these attacks will be an interception proxy like Burp Suite and a methodical approach. Use Intruder for brute-forcing, Repeater for testing logic, and Proxy for intercepting and modifying responses.
- Common patterns to hunt for: Legacy API endpoints, client-side validation logic, poor server-side state management, and insecure interactions with other features like password reset.
Next Lesson Preview:
We have now covered breaking two major pillars of authentication: password resets and MFA. Once an attacker has successfully authenticated, their next goal is to access data and perform actions. However, they should only be able to access their own data and actions. In our next lesson, we will dive into Authorization Bypass & Logic Flaws, starting with one of the most prevalent and impactful web vulnerabilities: Insecure Direct Object References (IDOR).