1.反射型XSS
原理:
通過在頁面上植入惡意鏈接,誘使用戶點擊,執行js腳本,所謂反射型XSS就是將用戶輸入的數據(惡意用戶輸入的js腳本),“反射”到瀏覽器執行。
實例:
php源碼:
<?php $input = $_GET("param"); echo "<div>".$input."</div>"; ?>
構造xsspayload
http://127.0.0.1/test.php?param=<script>alert(/xss/)</script>
2.存儲性XSS
原理:此類XSS漏洞是指,用戶輸入的數據(惡意代碼)可以“存儲”在服務端,只要有人訪問這個包含有存儲型XSS代碼的頁面,XSS腳本就會在他們的瀏覽器中執行,這種XSS具有很強的穩定性。所以也被稱做,“持久型XSS”。
實例:
通過js腳本獲取cookie值,當然,在實際應用中,應該是通過植入鏈接來將js腳本植入的。
<html> <head> <script type="text/javascript"> function getCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "=") if (c_start!=-1) { c_start=c_start + c_name.length+1 c_end=document.cookie.indexOf(";",c_start) if (c_end==-1) c_end=document.cookie.length return unescape(document.cookie.substring(c_start,c_end)) } } return "" } function setCookie(c_name,value,expiredays) { var exdate=new Date() exdate.setDate(exdate.getDate()+expiredays) document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) } function checkCookie() { username=getCookie('username') if (username!=null && username!="") {alert('Welcome again '+username+'!')} else { username=prompt('Please enter your name:',"") if (username!=null && username!="") { setCookie('username',username,365) } } alert(document.cookie) } </script> </head> <body onLoad="checkCookie()"> </body> </html>
3.DOM型XSS
原理:類似於反射型XSS,但是,這種XSS攻擊的實現是通過對DOM樹的修改而實現的。
實例:
<script> function test(){ var str=document.getElementById("text").value; document.getElementById("t").innerHTML = "<a href='"+str+"'>testLink</a>"; } </script> <div id="t"></div> <input type="text" id="text" value=""/> <input type="button" id="s" value="write" onclick="test()"/>
構造payload
' onclick=alert(/xss1/) //
或者
‘><img src=# onerror=alert(/XSS2/) /><'
就可以順利彈框了。