Expert · updated

Authentication

PortSwigger Web Security Academy · Expert

  • #Authentication

Broken brute-force protection, multiple credentials per request

The vulnerability

The login counts requests, not passwords. It also accepts a list of passwords instead of a single one, so you can try all of them in one request.

Fix: Count failed passwords per account, and reject a login where the password isn’t a string.

The lab

Open the lab on PortSwigger

This lab is vulnerable due to a logic flaw in its brute-force protection. To solve the lab, brute-force Carlos’s password, then access his account page.

* Victim’s username: carlos

* Candidate passwords

Solution

1. Test the Login Form: On the login page, enter carlos as the username and any password. Look at the HTTP/2 200 OK response with an "Invalid username or password" error.

2. Intercept Login Request: In Burp Suite’s Proxy → HTTP history, find the POST /login request and send it to Repeater.

3. Inject Multiple Passwords: In Repeater, modify the request body. Change the password from a single string to a JSON array containing a list of candidate passwords.

{
   "username" : "carlos",
   "password" : [
      "123456",
      "password",
      "12345678",
      "qwerty",
      "12345",
      "1234",
      [...]
      "999"
   ]
}
  1. Make sure the Content-Type header is application/json.

5. Send Request and Access Account: Send the request. A successful login will return an HTTP/2 302 Found response. Right-click the response and select "Show response in browser" to get the URL to Carlos's account page. Copy this URL and paste it into your browser to solve the lab.

2FA Bypass Using a Brute-Force Attack

The vulnerability

After two wrong codes you are logged out, but you can just log in again and keep guessing. Burp can do that for you, and there are only 10,000 codes.

Fix: Limit the number of wrong codes per account, also across several logins.

The lab

Open the lab on PortSwigger

This lab’s two-factor authentication is vulnerable to brute-forcing. You have already obtained a valid username and password, but do not have access to the user’s 2FA verification code. To solve the lab, brute-force the 2FA code and access Carlos’s account page.

Victim’s credentials: carlos:montoya

Note

As the verification code will reset while you’re running your attack, you may need to repeat this attack several times before you succeed. This is because the new code may be a number that your current Intruder attack has already attempted.

Solution

1. Log in and Look at 2FA: Log in with the credentials carlos:montoya. You will be redirected to a 2FA page. Enter an incorrect code. After a few attempts, you will be forced to log in again.

2. Create a Session Handling Macro: In Burp Suite, go to Settings -> Sessions -> Session Handling Rules. Click Add to create a new rule. In the Scope tab, select "Include all URLs." In the Details tab, click "Add -> Run a macro." Record a macro that performs the full login sequence (e.g., GET /login -> POST /login -> GET /login2).

  1. Click “Test macro” to confirm it reaches the 2FA page.

4. Send 2FA Request to Intruder: In Burp Suite’s Proxy → HTTP history, find the POST /login2 request and send it to Intruder.

5. Configure Intruder Attack:

  • Positions: In the Positions tab, clear all positions except for the value of the mfa-code parameter.
  • Payloads: In the Payloads tab, select Numbers as the payload type. Set the "From" field to 0 and "To" to 9999. Set "Min integer digits" and "Max integer digits" both to 4 to ensure all numbers from 0000 to 9999 are tested.

  • Resource Pool: In the Resource Pool tab, set "Maximum concurrent requests" to 1 to avoid issues with session cookies being used simultaneously.

6. Launch and Solve Attack: Start the attack. Burp Intruder will automatically use the macro to re-authenticate after each session invalidates. Monitor the Status and Length columns in the Intruder results. A successful login will result in an HTTP/2 302 Found response. Right-click on this request and select "Show response in browser." Copy the URL and paste it into your browser to access Carlos's account page and solve the lab.