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.

SOP blocks JavaScript from accessing the response of a cross-origin request, but the request is still sent.

SOP allows images to be loaded cross-origin.

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

Apache OFBiz Web Tools Login page

Response headers for login request

Web Tools main page
Web Tools Find User Login
Web Tools Create User Login

POST request for new user creation

Update User Login Security Settings
Web Tools: Find Security Group
The SUPER Role
Web Tools: Edit Security Group
Web Tools: Add User Login to Security Group
User added to SUPER group

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

The csrftest user was successfully created
Burp Suite HTTP history tab with CSRF attack

Creating our next payload file

New form element for adding our user to the SUPER group

New JavaScript function to submit our two forms

Our browser state after loading obfiz1.html
Logged in as csrftest

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

Using Burp Suite to check cookie attributes

Response headers for /code

Sending the request for /code to Repeater
Baseline request and response

Trusting Any Origin

Requesting the secret code without a session cookie

Request containing an Origin header and the subsequent response

Basic CORS exploit page

Some browsers restrict cookies on cross-origin requests based on privacy settings. If the following examples do not work, you may need to modify settings in your browser to relax these controls for the cors1.html and cors2.html pages.

In Chrome and Chromium, you can enable Third-party cookies after loading the page by clicking on Not secure, then Cookies and site data, and then toggling "Third-party cookies".

In Firefox, you may need to disable Enhanced Tracking Protection for the page by clicking on the shield icon next to the URL and then toggling "Enhanced Tracking Protection is ON for this site".

Browser console output includes the secret code

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