githubEdit

CORS (Cross-Origin Resource Sharing) Attack

CORS (Cross-Origin Resource Sharing) Attack

CORS is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served. The CORS Attack is the attacking methodology that abuses this mechanism.

Bypass Restriction

Assume that https://example.com restricts the access by CORS. We try to set domains that are allowed to Origin header.

Origin: https://example.com
Origin: http://localhost
Origin: https://api.example.com

Origin Reflection

1. Change Origin Value of Request Header

Origin: https://attacker.com
Origin: https://vulnerable.com.attacker.com

2. Check if the Response Allowing Cross-Origin

It's reflected the previous reqeust in the response header, you can exploit it.

Access-Control-Allow-Origin: https://attacker.com
Access-Control-Allow-Origin: https://vulnerable.com.attacker.com
Access-Control-Allow-Credentials: true

3. Exploit with Your Malicious Web Page

For example, it's hosted as "https://attacker.com/exploit" or "https://vulnerable.com.attacker.com/exploit". Add the JavaScript code in the web page.

It shows the users' sensitive information of the target website in your server's log.

Null origin

1. Send Request with Origin: null

2. Check if the Response Allowing Cross-Origin

3. Add the iframe to Your Malicious Web Page

For example, it's hosted as "https://attacker.com/exploit".

Insecure Protocol

1. Send Request with Abbused Origin

2. Check if the Response Allowing Cross-Origin

3. Add the JavaScript Code to Your Malicious Web Page

It's hosted as "https://attacker.com/exploit"

JSONP (Json with Padding)

Tools

circle-info

In any site disclosing users & passwords (or other sensitive info), try CORS.

CORS PoC

CORS PoC 2

CORS PoC 3 - Sensitive Data Leakage

CORS JSON PoC

Last updated