> For the complete documentation index, see [llms.txt](https://kruknight.gitbook.io/daemon-of-hacking/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kruknight.gitbook.io/daemon-of-hacking/writeups/portswigger-labs/authentication/broken-brute-force-protection-ip-block.md).

# Broken Brute-Force Protection, IP Block

## Lab Description

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2F6Xdj4KmVH40AHqAdbypl%2Fimage.png?alt=media&amp;token=edaa68f5-7bf2-41f7-93ad-f38cc8d3c677" alt=""><figcaption></figcaption></figure>

## Walkthrough

### **Step 1: Initial Observations**

* Upon visiting the login page, entering arbitrary credentials results in a rate-limiting error after multiple failed attempts, stating that you must wait 1 minute.

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2FbRVTegWJ3MeGWXRk8Y0l%2Fimage.png?alt=media&amp;token=4e6abd5f-cac6-431f-ad07-6cb419622bcd" alt=""><figcaption></figcaption></figure>

### Step 2 : Analyzing the protection method

By testing further, I observed:

1. The counter resets **after a successful login**.
2. If I attempt **two failed logins** for one user and successfully log in as another user (wiener), the lockout mechanism resets for future attempts.

This behavior reveals a **logic flaw** in the brute-force protection:

* The system resets the counter upon a successful login, allowing us to alternate between two users to bypass the lockout.

### **Step 3: Crafting the Attack**

To exploit this logic flaw:

1. Use the victim's username (**`carlos`**) and attempt to brute-force their password.
2. Alternate the password attempts for **`carlos`** with a known valid login (`wiener:peter`) to avoid the lockout.

Modify the password list to repeat **wiener's password** after every incorrect attempt:

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2FCnyu4MrsWgjh8UuDT6Xa%2Fimage.png?alt=media&amp;token=35d9d34c-f123-4876-aee0-22126232cbdf" alt=""><figcaption></figcaption></figure>

We use the provided password list and modify it to use wieners password after each line to trigger a successful login

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2FmzG2O3k3dTVPYe4rdn6Z%2Fimage.png?alt=media&amp;token=651305cb-e20e-46b0-b269-fb4249456b1d" alt=""><figcaption></figcaption></figure>

{% file src="/files/HE0J1ze34Iuqytht1rKF" %}

### **Step 4: Analyzing the Output**

Once the attack finishes:

1. Filter results for **`carlos`** and status code **302 Redirect**.
2. The **302 status code** indicates a successful login, revealing the correct password for `carlos`

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2FpWBqfYCkaK2H1vD9ne7U%2Fimage.png?alt=media&amp;token=c82724bb-dd44-4531-b5d9-7c3fe35942a7" alt=""><figcaption></figcaption></figure>

And then we can see **`carlos's`** password

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2Fn2tHcu9X2eXdsF1nw3F9%2Fimage.png?alt=media&amp;token=634e0cce-9f96-4d2c-a1df-0b2f3799de93" alt=""><figcaption></figcaption></figure>
