- A+
前言

在 CMS 中难免会调用到 SQL 执行(废话),百密总有一疏,今天跟师傅们分享一些平时审计时遇到的注入,可能不全面,希望和师傅们一起学习。
关于 ThinkPHP 中的 注入
这绝对是能拿来探讨探讨的,因为我看到的版本就有两三种了,这里给出两个例子。
ThinkPHP3.2.3
首先我们举个最简单的例子作为开场:
public function login(){
    $User = D('User');
    $map = array('username' => $_POST['username']);
    $user = $User->where($map)->find();
}首先调用了 where 函数:
public function where($where,$parse=null){
    ....
    if(isset($this->options['where'])){
        $this->options['where'] =   array_merge($this->options['where'],$where);
    }else{
        $this->options['where'] =   $where;
    }
    return $this;
}这里简单的将 where 放进了 options[where] 里。
然后第二步是调用 find 函数,find 的内部又调用了 ->db->select,这是具体的实现,可以进去看看(查询时可能会查找三个,通常是 Driver.class.php):
public function select($options=array()) {
    $this->model  =   $options['model'];
    $this->parseBind(!empty($options['bind'])?$options['bind']:array());
    $sql    = $this->buildSelectSql($options); // 生成 sql 语句
    $result   = $this->query($sql,!empty($options['fetch_sql']) ? true : false);
    return $result;
}继续跟入 buildSelectSql 函数,会发现里面调用了 parseSql 函数,继续跟:
ThinkPHP5.0
在 TP5 中 parseWhereItem 在 Db.class.php,但其实也有一段和 3.2 中差不多的代码:
if(isset($val[2]) && 'exp'==$val[2]) {
    $whereStr .= $key.' '.strtoupper($val[0]).' '.$val[1];
}但是在 TP5.0 却加入了一个全局过滤:

- 微信 wzgj360
- 联系免费答疑
- 
			  
- QQ 613049615
- 联系免费答疑
- 
			  






