ThinkPHP 3.1.3及之前的版本存在一个SQL注入漏洞,漏洞存在于ThinkPHP/Lib/Core/Model.class.php 文件
根据官方文档对"防止SQL注入"的方法解释(见http://doc.thinkphp.cn/manual/sql_injection.html)使用查询条件预处理可以防止SQL注入,没错,当使用如下代码时可以起到效果:
$Model->where("id=%d and username='%s' and xx='%f'",array($id,$username,$xx))->select();
或者 $Model->where("id=%d and username='%s' and xx='%f'",$id,$username,$xx)->select();
但是,当你使用如下代码时,却没有"防止SQL注入"效果(而官方文档却说可以防止SQL注入):
$model->query('select * from user where id=%d and status=%s',$id,$status);
或者 $model->query('select * from user where id=%d and status=%s',array($id,$status)); 原因:ThinkPHP/Lib/Core/Model.class.php 文件里的parseSql函数没有实现SQL过滤.
原函数:
protected function parseSql($sql,$parse) {
// 分析表达式
if(true === $parse) {