DATA URI
“Used to embed small items of data into a URL—rather than link to an external resource, the URL contains the actual encoded data. URIs are supported by most modern browsers except for some versions of Internet Explorer.”
Data URI 是一种提供让外置资源的直接内嵌在页面中的方案。这种技术允许我们只需单次 HTTP 请求即可获取所有需要引用的图片与样式资源。
在 RFC2397(http://tools.ietf.org/html/rfc2397)中定义了它格式规范:
1 | data:[<mime type>][;charset=<charset>][;base64],<encoded data> |
Bypass WAF
一般来说,WAF识别XSS向量,主要通过以下规则
- html标签,如:
<script>
,<iframe>
,<object>
,<svg>
等 - event handlers, 如:
onload
,onerror
- data Attribute
- js keyword, 如:
alert()
,confirm()
使用DATA URI利用base64编码数据绕过WAF对xss payload的检测。那么如何使用DATA URI执行javascript呢?
object tag
1 | # base64 decode: <script>alert(1);</script> |
通常WAF都会拦截<object>
标签
svg tags
参考 http://insert-script.blogspot.com.au/2014/02/svg-fun-time-firefox-svg-vector.html, 使用svg + use
执行javascript.
- test.html for firefox
1 | <svg> |
base64 payload 解码为:
1 | <svg id="rectangle" |
当点击黑色方框时会触发XSS.要达到自动触发XSS的目的,可以使用如下paylaod:
1 | <svg id="rectangle" |
- better test.html for firefox
1 |
|
img tags
1 | <img src="data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=" onload=alert(1)> |