对于ThinkPHP框架早期版本的一个SQL注入漏洞详细分析 2015-01-25 来源:网络 字号:大 中 小 我要评论 收藏本文
ThinkPHP官网上曾有一段公告指出,在ThinkPHP 3.1.3及之前的版本存在一个SQL注入漏洞,漏洞存在于ThinkPHP/Lib/Core/Model.class.php 文件 $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) { $options = $this->_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; }
验证漏洞(举例): http://localhost/Main?id=boo" or 1="1 或 http://localhost/Main?id=boo%22%20or%201=%221 action代码: $model=M('Peipeidui'); $m=$model->query('select * from peipeidui where name="%s"',$_GET['id']); dump($m);exit; 或者: $model=M('Peipeidui'); $m=$model->query('select * from peipeidui where name="%s"',array($_GET['id'])); dump($m);exit; 结果: 可将parseSql函数修改为: protected function parseSql($sql,$parse) { // 分析表达式 if(true === $parse) { $options = $this->_parseOptions(); $sql = $this->db->parseSql($sql,$options); }elseif(is_array($parse)){ // SQL预处理 $parse = array_map(array($this->db,'escapeString'),$parse);//此行为新增代码 $sql = vsprintf($sql,$parse); }else{ $sql = strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>C('DB_PREFIX'))); } $this->db->setModel($this->name); return $sql; } 总结: |
相关热词搜索:ThinkPHP框架SQL注入漏洞分析
上一篇:成为好程序员必须避免的5个坏习惯
下一篇:PHP不用递归遍历目录下所有文件的代码
看完本文,您的心情是?
分享到:
收藏
评论排行
- ·如何清除DNS缓存 使用命令清理dns缓存方法(2)
- ·Win8.1升级Win10遇到错误代码0xc190010...(1)
- ·Windows RT 8.1 Update 3九月发布 ...(0)
- ·如何将ubuntu安装到U盘实现即插即用(0)
- ·微软否认Xbox One有远程关闭开关(0)
- ·Surface Book详细拆解:千万不要自己动手修(0)
- ·WIN10免费升级正版手册(5分钟读懂WIN10...(0)
- ·你的今日头条账号为什么会被封?(0)
- ·win7电脑怎么翻墙看国外的网站?(0)
- ·shell脚本运行5秒后自动退出的代码(0)
- ·jsp 不支持EL表达式,解决办法(0)
- ·table合并单元格与img图片铺满整个td的html(0)
- ·Mac OS X 系统备份指南(0)
- ·Shell脚本注释写法(0)
- ·windows8激活码、序列号、激活密钥、激...(0)
- ·从一个不错的留言本弄的mysql数据库操作类(0)
- ·PHP漏洞全解(详细介绍)(0)
- ·phpBB BBcode处理的漏洞(0)
- ·安装Win10技术预览版有风险吗?win10预...(0)
- ·基于mysql的论坛(6)(0)
猜你喜欢
- ·destoon常用的安全设置概述
- ·PHP保留两位小数并且四舍五入及不四舍五入...
- ·php文本转图片自动换行的方法
- ·PHP正确配置mysql(apache环境)
- ·php redis实现文章发布系统(用户投票系统)
- ·PHP中数组的分组排序实例
- ·php fckeditor 调用的函数
- ·php学习之 认清变量的作用范围
- ·用php实现gb2312和unicode间的编码转换
- ·PHP+ACCESS 文章管理程序代码
- ·php不允许用户提交空表单(php空值判断)
- ·php的array_multisort()使用方法介绍
- ·新浪新闻小偷
- ·phplock(php进程锁) v1.0 beta1
- ·模板引擎smarty工作原理以及使用示例
- ·dedecms采集中可以过滤多行代码的正则表达式
热门推荐
本月排行
最近更新
- ·PHP递归实现无限级分类
- ·PHP改进计算字符串相似度的函数similar_text()、levenshtein()
- ·PHP启动windows应用程序、执行bat批处理、执行cmd命令的方法(exec、system函数详解)
- ·PHP的mysqli_query参数MYSQLI_STORE_RESULT和MYSQLI_USE_RESULT的区别
- ·PHP错误Warning: Cannot modify header information - headers already sent by解决方法
- ·PHP正则替换函数preg_replace和preg_replace_callback使用总结
- ·PHP PDOStatement对象bindpram()、bindvalue()和bindcolumn之间的区别
- ·CodeIgniter错误mysql_connect(): No such file or directory解决方法
- ·PHP JSON出错:Cannot use object of type stdClass as array解决方法
- ·PHP遍历目录函数opendir()、readdir()、closedir()、rewinddir()总结
- ·phpmyadmin出现Cannot start session without errors问题解决方法
- ·Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 2611816 bytes)
- ·PHP执行Curl时报错提示CURL ERROR: Recv failure: Connection reset by peer的解决方法
- ·php中使用session_set_save_handler()函数把session保存到MySQL数据库实例
- ·PHP错误Parse error: syntax error, unexpected end of file in test.php on line 12解决方法
- ·thinkphp视图模型查询提示ERR: 1146:Table 'db.pr_order_view' doesn't exist的解决方法
- ·浅析application/x-www-form-urlencoded和multipart/form-data的区别
- ·PHP 面向对象程序设计(oop)学习笔记(一) - 抽象类、对象接口、instanceof 和契约式编程
- ·PHP 正则表达式之正则处理函数小结(preg_match,preg_match_all,preg_replace,preg_split)
- ·Fatal error: session_start(): Failed to initialize storage module: files问题解决方法