Lab1: Reflected XSS into HTML context with nothing encoded
https://portswigger.net/web-security/cross-site-scripting/reflected/lab-html-context-nothing-encoded

點上圖access the lab,進入下圖網頁:

隨便打個aaa,按search,進入以下網頁:

現在用的是firefix,按F12觀察目前網頁狀態:

可以想想,如果上圖紅圈的aaa部分替換成彈窗程式碼,是不是就可以彈窗?
所以試試在search欄位貼上這一串:
alert(document.domain)
順利彈窗,看一下F12,也的確如剛剛所想。這是個簡單題,因為沒有任何轉譯或過濾。

Lab2: Stored XSS into HTML context with nothing encoded
https://portswigger.net/web-security/cross-site-scripting/stored/lab-html-context-nothing-encoded

進入上圖網頁以後按上圖紅圈處進入文章。

上圖有留言板,可以觀察一下送出留言後的網頁排版。

輸入如上圖資訊送出後,網頁排版如下圖。同樣,如果下圖紅圈aaa的部分替換成彈窗程式碼即可。

MrXSS
XSS@XSS.com


按上圖的Back to blog


按F12看一下網頁排版:

Lab3: DOM XSS in document.write sink using source location.search
https://portswigger.net/web-security/cross-site-scripting/dom-based/lab-document-write-sink


在上圖的頁面按ctrl+U來檢視source code,問題在下面這一個:

看看上圖紅圈。如果直接輸入
alert(document.domain)這樣的彈窗會失敗,因為上圖紅圈會把上一句處理成這樣:

前面要先把img src的語句用">閉合。XSS攻擊語句如下:
">alert(document.domain)



Lab4: DOM XSS in innerHTML sink using source location.search
https://portswigger.net/web-security/cross-site-scripting/dom-based/lab-innerhtml-sink

按access the lab進入以下網頁:

先隨便打個字串搜索一下:

用firefox瀏覽器,在上圖按F12,可以看到輸出:

根據
https://ithelp.ithome.com.tw/articles/10241374?sc=rss.iron
來了解一下innerHTML:


輸入
</span><img src=/ onerror=alert(1) />//
使得整句變為:

用</span>來閉合search message,接下來用onerror來彈窗。

可以再F12看一下剛剛的XSS語句在網頁如何表現:

跟原本的aaa比較:

Lab5: DOM XSS in jQuery anchor href attribute sink using location.search source
https://portswigger.net/web-security/cross-site-scripting/dom-based/lab-jquery-href-attribute-sink

按上圖access the lab進入以下網頁:

按上圖右上角進入以下網頁:

按F12:

在網址列的最後面輸入: javascript:alert(document.domain)
再按重新整理:


Lab6: Reflected XSS into attribute with angle brackets HTML-encoded

按上圖access the lab進入下面網頁:

先隨便打一個彈窗的語法看看:
" alERT(/XSS/) "

再按F12,可以發現有對語句的<跟>進行轉譯,變成<跟>。

參考以下文章,可以發現有不需<跟>就可以彈窗的程式碼:
" onmouseover =alert(document.domain) name="1

只要動滑鼠就會出現以上視窗。

Lab7: Stored XSS into anchor href attribute with double quotes HTML-encoded

按上圖access the lab進入下面網頁:

按上圖最下面view post。

看到留言出現:

開F12看看留言的結構:

可以發現website的地方其實可以塞彈窗程式碼:
javascript:alert(1)

送出後回到評論,按下圖紅圈,即可彈窗。

用F12看,程式碼如下:

Lab8: Reflected XSS into a JavaScript string with angle brackets HTML encoded

按上圖access the lab進入下面網頁:



XSS語句:
';alert(1);//

按search後彈窗:

看一下F12,其實語句的意思是先把下圖紅圈處的單引號閉合,再執行彈窗指令。


![[Py 百日馬 Day 3] 用 if / elif / else 見機行事](https://static.coderbridge.com/img/x94lexie/daf43622c41840c6b25f03242049c080.jpg)