Module 7: Cross-Origin Attacks
Same-Origin Policy
Accessing the CORS Sandbox
Start the VPN, the VM, and add the IP to your hosts file.
Introduction to the Same-Origin Policy
An origin is the combination of a protocol, hostname, and port number.
SameSite Cookies
This attribute instructs the browser to send the cookie on any relevant request, regardless of where or how the request originated.
Cross-Site Request Forgery (CSRF)
Detecting and Preventing CSRF
Usually done via a hidden nonce value or "csrf" token.
Exploiting CSRF
It's easier to exploit CSRF with GET requests due to the multiple ways to instruct a browser to send a GET request.
Case Study: Apache OFBiz
Accessing Apache OFBiz
Start the VPN, the VM, and add its IP to hosts.
Apache OFBiz - Discovery

Response headers for login request



POST request for new user creation






POST request to add a user to a security group
Apache OFBiz - Exploitation
CSRF payload outline
Adding the input fields
Restarting the Apache HTTP Server


Creating our next payload file
New form element for adding our user to the SUPER group
New JavaScript function to submit our two forms


Revising the CSRF Payload
Basic HTML and JavaScript structure of ofbiz2.html
JavaScript functions to create a new user and add that user to SUPER group
Using the fetch API to send our POST request in the "no-cors" mode restricts us to using "application/x-www-form-urlencoded" as the content type. Setting credentials to include instructs the browser to send cookies on the request.
Our CSRF fails due to the browser defaulting to a Lax SameSite value. If set to None then we would have been successful.
Cross-Origin Resource Sharing (CORS)
Anatomy of the CORS Request
Before sending an actual cross-origin request, the browser makes a preflight request to the intended destination.
Sample preflight request
Response Headers
Servers can set several headers to enable CORS.
Sample preflight response
Exploiting Weak CORS Policies
Weak CORS Policies - Discovery

Response headers for /code


Trusting Any Origin
Requesting the secret code without a session cookie

Basic CORS exploit page

Updated get_code() function
Contents of access.log including the secret code
Improper Domain Allowlist
Response to OPTIONS request to /allowlist
The Access-Control-Allow-Origin value has changed
The Access-Control-Allow-Origin value has the original value
The Access-Control-Allow-Origin value reflects the value we submitted
Last updated