Title: CSRF (Cross-Site Request Forgery)
Category: Broken Access Control
Difficulty: ⭐⭐⭐ (3/6)
The challenge "CSRF" involves executing a Cross-Site Request Forgery (CSRF) attack to change the name of a user on the OWASP Juice Shop platform without their consent.
- Web Browser: Specifically an older version that lacks modern CSRF protections (e.g., the more simple one is Firefox version 81.0).
- Burp Suite: To intercept and analyze HTTP requests.
- HTML Editor: To construct and deploy a CSRF exploit page (http://htmledit.squarefree.com/ was suggested).
-
Endpoint Discovery:
- Use Burp Suite to intercept and examine HTTP requests made while changing the username through the application’s profile page.
- Identify the POST request that changes the username, specifically noting the URL and form parameters.
-
Crafting the CSRF Payload:
- Create an HTML page that includes an auto-submitting form directed at the vulnerable endpoint.
- Use hidden form fields to set the desired new username value.
- Include JavaScript to automatically submit the form when the page loads.
<html> <body> <form action="http://127.0.0.1:3000/profile" method="POST"> <input type="hidden" name="username" value="HelloFromCSRF" /> </form> <script>document.forms[0].submit();</script> </body> </html>
- Attack Execution:
- Upload the CSRF attack HTML to a publicly accessible or controlled domain. For the purpose of this CTF, the file was tested locally using http://htmledit.squarefree.com/ to simulate a real attack scenario.
- When the victim visits the malicious page, the script triggers the form submission using the victim's authenticated session, changing the username without the user’s explicit approval.
- Overcoming Browser CSRF Protections:
- Due to enhancements in modern browsers to block CSRF attacks, use an older browser version that does not include these protections.
- Disable security features that would normally block or alert on suspicious cross-site requests.
To protect against CSRF vulnerabilities:
- Use Anti-CSRF Tokens: Ensure that each form submission includes a server-side validated token.
- Adopt Same-Site Cookies: Configure cookies to be only sent in requests originating from the same site the cookie was set.
- Implement CORS Policies: Properly configure Cross-Origin Resource Sharing (CORS) policies to restrict resources to trusted domains only.