> 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/password-reset-broken-logic.md).

# Password reset broken logic

## Lab description

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2FCYstnzanJXpXSVUKQKDE%2Fimage.png?alt=media&amp;token=d471a56a-9275-4652-83d5-8c6524b6fb2c" alt=""><figcaption></figcaption></figure>

## Walkthrough

### Step 1: Understand the Password Reset Functionality

Begin by navigating to the login page and selecting the "Forgot password?" link. The application will prompt you to enter a username. Start by testing the reset process with your own account, using the username `wiener`.

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2FLZgBFFQ6xi7Qj0sOqvTW%2Fimage.png?alt=media&amp;token=e32991c2-5496-497c-bd55-bcd373b6e104" alt=""><figcaption></figcaption></figure>

When going to the forget password page we find that it asks for a username so we type our account username `wiener` and click submit

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2F666GkCeZOmWFekgZWE3H%2Fimage.png?alt=media&amp;token=0400ab19-9e03-49b1-9028-9f9622b65ce4" alt=""><figcaption></figcaption></figure>

### Step 2: Inspect the Email Reset Link

After submitting your username, an email is sent to your associated email account. This email contains a reset link, which directs you to a page prompting you to enter a new password twice.

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2FoPSV322VlXRng9lBNQL4%2Fimage.png?alt=media&amp;token=2036f9d9-8618-498d-ae6e-b9bf1f328127" alt=""><figcaption></figcaption></figure>

### Step 3: Analyze the Reset Password Request

Submit a new password, and intercept the request using Burp Suite. Carefully inspect the request payload. You will notice:

* A `temp-forgot-password-token` is included in both the header and the body of the request.
* A `username` parameter specifies which account’s password is being reset.

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2F0zSxT8Jl5vrn5r09fF6M%2Fimage.png?alt=media&amp;token=80173ca9-9e75-4e20-a0a6-34a777092ed0" alt=""><figcaption></figcaption></figure>

### Step 4: Exploit Logic Flaw

After analyzing the request, remove the `temp-forgot-password-token` from both the header and the body. Resubmit the request. Observe that the server processes the request without validating the token. This indicates that the token isn’t required to reset the password.

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2F9ZIUKWnnOc76LIV97dyv%2Fimage.png?alt=media&amp;token=7ef510d2-a3a0-4eb2-b6e2-af9c6471e495" alt=""><figcaption></figcaption></figure>

### Step 5: Reset Carlos’s Password:

First, request a password reset for Carlos by entering his username on the "Forgot password?" page.

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2F2Tw7bLwHAWgtyd0SWK1D%2Fimage.png?alt=media&amp;token=e19a6c8c-baeb-4911-8f50-9274dde3178c" alt=""><figcaption></figcaption></figure>

* Intercept the reset request for your own account (Wiener) and modify the `username` field to `carlos`. Update the `new-password-1` and `new-password-2` fields to the desired new password for Carlos (e.g., `KruKnight`).
* Send the modified request.

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2FUijeI1hz6PnweiFJac9W%2Fimage.png?alt=media&amp;token=b2446e97-867f-4ea2-9ad0-8011d090200a" alt=""><figcaption></figcaption></figure>

### **Step 6: Verify Access to Carlos’s Account**

Navigate to the login page, enter `carlos` as the username and the newly set password. You should successfully log in to Carlos’s account, confirming the exploit worked.

<figure><img src="https://2387347627-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F47EuhANOY5sIuDySBX97%2Fuploads%2F9Yza6GEoW1NrMYGsoV9I%2Fimage.png?alt=media&amp;token=0346b1fb-ea23-4382-ac76-4e0497e1d4d8" alt=""><figcaption></figcaption></figure>
