加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

对于ThinkPHP框架早期版本的一个SQL注入漏洞详细分析

发布时间:2020-12-14 14:00:35 所属栏目:大数据 来源:网络整理
导读:ThinkPHP官网上曾有一段公告指出,在ThinkPHP 3.1.3及之前的版本存在一个SQL注入漏洞,漏洞存在于ThinkPHP/Lib/Core/Model.class.php 文件根据官方文档对"防止SQL注入"的方法解释(参考http://doc.thinkphp.cn/manual/sql_injection.html)使用查询条件预处理可

ThinkPHP官网上曾有一段公告指出,在ThinkPHP 3.1.3及之前的版本存在一个SQL注入漏洞,漏洞存在于ThinkPHP/Lib/Core/Model.class.php 文件 根据官方文档对"防止SQL注入"的方法解释(参考http://doc.thinkphp.cn/manual/sql_injection.html) 使用查询条件预处理可以防止SQL注入,没错,当使用如下代码时可以起到效果:

where("id=%d and username='%s' and xx='%f'",array($id,$username,$xx))->select();

或者

where("id=%d and username='%s' and xx='%f'",$id,$xx)->select();

但是,当你使用如下代码时,却没有"防止SQL注入"的效果(但是官方文档却说可以防止SQL注入):

query('select * from user where id=%d and status=%s',$status);

或者

query('select * from user where id=%d and status=%s',$status));

原因分析:

ThinkPHP/Lib/Core/Model.class.php 文件里的parseSql函数没有实现SQL过滤. 其原函数为:

_parSEOptions(); $sql = $this->db->parseSql($sql,$options); }elseif(is_array($parse)){ // SQL预处理 $sql = vsprintf($sql,$parse); }else{ $sql = strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>C('DB_PREFIX'))); } $this->db->setModel($this->name); return $sql; }

验证漏洞(举例): 请求地址:

action代码:

query('select * from peipeidui where name="%s"',$_GET['id']); dump($m);exit;

或者:

query('select * from peipeidui where name="%s"',array($_GET['id'])); dump($m);exit;

结果:

表peipeidui所有数据被列出,SQL注入语句起效.

解决方法:

可将parseSql函数修改为:

db,'escapeString'),$parse);//此行为新增代码 $sql = vsprintf($sql,'__PREFIX__'=>C('DB_PREFIX'))); } $this->db->setModel($this->name); return $sql; }

总结:

1.不要过分依赖TP的底层SQL过滤,程序员要做好安全检查 2.不建议直接用$_GET,$_POST

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读