thinkphp日志泄漏漏洞_ThinkPHP框架通杀所有版本的一个SQL注入漏洞详细分析及测试方法...
ThinkPHP 3.1.3及之前的版本存在一個(gè)SQL注入漏洞,漏洞存在于ThinkPHP/Lib/Core/Model.class.php 文件
根據(jù)官方文檔對(duì)"防止SQL注入"的方法解釋(見http://doc.thinkphp.cn/manual/sql_injection.html)使用查詢條件預(yù)處理可以防止SQL注入,沒(méi)錯(cuò),當(dāng)使用如下代碼時(shí)可以起到效果:
$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();
但是,當(dāng)你使用如下代碼時(shí),卻沒(méi)有"防止SQL注入"效果(而官方文檔卻說(shuō)可以防止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函數(shù)沒(méi)有實(shí)現(xiàn)SQL過(guò)濾.
原函數(shù):
protected function parseSql($sql,$parse) {
// 分析表達(dá)式
if(true === $parse) {
$options = ?$this->_parseOptions();
$sql ?= ? $this->db->parseSql($sql,$options);
}elseif(is_array($parse)){ // SQL預(yù)處理
$sql ?= vsprintf($sql,$parse);
}else{
$sql ? ?= ? strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>C('DB_PREFIX')));
}
$this->db->setModel($this->name);
return $sql;
}
驗(yàn)證漏洞(舉例):
請(qǐng)求地址: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;
結(jié)果:
表peipeidui所有數(shù)據(jù)被列出,SQL注入語(yǔ)句起效.
解決辦法:
將parseSql函數(shù)修改為:
protected function parseSql($sql,$parse) {
// 分析表達(dá)式
if(true === $parse) {
$options = ?$this->_parseOptions();
$sql ?= ? $this->db->parseSql($sql,$options);
}elseif(is_array($parse)){ // SQL預(yù)處理
$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;
}
總結(jié)
以上是生活随笔為你收集整理的thinkphp日志泄漏漏洞_ThinkPHP框架通杀所有版本的一个SQL注入漏洞详细分析及测试方法...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: hadoop 依赖式job_Hadoop
- 下一篇: 用hundred造句子_6分以上的人句子