Daemon Of Hacking
  • WELCOME!
    • 👋/home/usr/KruKnight
  • METHODOLOGIES & RESOURCES
    • Passwords & Attacks
    • Post Exploitation
      • 👀Situational Awareness
      • 🖥️Privilege Escalation
        • Linux Privilege Escalation
        • Windows Privilege Escalation
  • Writeups
    • CyCtf 2024
      • Vending Machine
      • Aerospace
      • OhMyCell
    • Portswigger Labs
      • Authentication
        • Username enumeration via different responses
        • 2FA simple bypass
        • Password reset broken logic
        • Username enumeration via subtly different responses
        • Username enumeration via response timing
        • Broken Brute-Force Protection, IP Block
        • Username enumeration via account lock
        • 2FA broken logic
        • Brute-forcing a stay-logged-in cookie
        • Offline password cracking
        • Password reset poisoning via middleware
        • Password brute-force via password change
        • Broken brute-force protection, multiple credentials per request
      • Os Command Injection
        • OS command injection, simple case
        • Blind OS command injection with time delays
        • Blind OS command injection with output redirection
        • Blind OS command injection with out-of-band interaction
        • Blind OS command injection with out-of-band data exfiltration
      • Cross-Origin Resource Sharing (CORS)
        • CORS vulnerability with basic origin reflection
        • CORS vulnerability with trusted null origin
        • CORS vulnerability with trusted insecure protocols
      • Server-side template injection
        • Basic server-side template injection
        • Basic server-side template injection (code context)
      • Server-Side Request Forgery (SSRF)
        • Basic SSRF against the local server
        • Basic SSRF against another back-end
        • Blind SSRF with out-of-band detection
        • SSRF with blacklist-based input filter
        • SSRF with filter bypass via open redirection vulnerability
      • Path Traversal
  • 🟩HTB Writeups
    • Heal
Powered by GitBook
On this page
  • Walkthrough
  • Step 1: Analyzing the Account Details Page
  • Step 2: Testing Origin Reflection
  • Step 3: Crafting the Exploit
  • Step 4: Delivering the Exploit
  • Step 5: Submitting the Solution

Was this helpful?

  1. Writeups
  2. Portswigger Labs
  3. Cross-Origin Resource Sharing (CORS)

CORS vulnerability with basic origin reflection

PreviousCross-Origin Resource Sharing (CORS)NextCORS vulnerability with trusted null origin

Last updated 5 months ago

Was this helpful?

Lab Description

Walkthrough

Step 1: Analyzing the Account Details Page

  1. Log in to the application using the provided credentials: wiener:peter.

  2. Navigate to the account details page. You will notice a response containing:

    • User information such as the username, email, and API key.

    • The response headers include:

      • Access-Control-Allow-Credentials: true: Indicates that the server allows requests with user credentials (e.g., cookies).

      • It implies that the server is designed to trust and process cross-origin requests that include authentication credentials. If the origin validation is flawed, this becomes a vector for attacks.

Step 2: Testing Origin Reflection

  1. send the request of /accountDetails to the repeater.

  2. Add the header Origin: https://evil.com to the request.

  3. Observe the response:

    • The server reflects the Origin header back in the Access-Control-Allow-Origin response header.

    • This indicates a vulnerable CORS configuration where any origin is trusted.

Step 3: Crafting the Exploit

Using the information gathered, the plan is to:

  • Exploit the insecure CORS configuration.

  • Use JavaScript to retrieve the administrator's API key from the account details endpoint.

Code Breakdown

  • var req = new XMLHttpRequest();

    • Creates a new object to send an HTTP request.

  • req.onload = function()

    • Defines a callback function to execute once the HTTP request is complete.

    • Appends the server's response (API key) to /log?key= and sends it to the exploit server.

  • req.open('get', 'URL', true);

    • Prepares a GET request to fetch the account details.

  • req.withCredentials = true;

    • Includes cookies and credentials in the request.

  • req.send();

    • Sends the crafted request.

Step 4: Delivering the Exploit

  • Upload the crafted JavaScript payload to your exploit server.

  • Deliver the exploit to the victim (administrator) by sharing the link to the exploit server.

  • Monitor the exploit server logs.

  • Observe requests made by the victim, including their session details.

Step 5: Submitting the Solution

  1. Decode the request to extract the administrator's API key.

  2. Use the captured API key to complete the lab.

  3. Verify the solution by submitting the key as prompted.