0x01:介绍

PHPCMS V9(后面简称V9)采用PHP5+MYSQL做为技术基础进行开发。V9采用OOP(面向对象)方式进行基础运行框架搭建。模块化开发方式做为功能开发形式。框架易于功能扩展,代码维护,优秀的二次开发能力,可满足所有网站的应用需求。 5年开发经验的优秀团队,在掌握了丰富的WEB开发经验和CMS产品开发经验的同时,勇于创新追求完美的设计理念,为全球多达10万网站提供助力,并被更多的政府机构、教育机构、事业单位、商业企业、个人站长所认可。

0x02:漏洞分析

在中 v9phpcmsmodulesmemberindex.php381行处

public function account_manage_avatar() {
  
$memberinfo = $this->memberinfo;
  
//初始化phpsso
  
$phpsso_api_url = $this->_init_phpsso();
  
$ps_auth_key = pc_base::load_config('system', 'phpsso_auth_key');
  
$auth_data = $this->client->auth_data(array('uid'=>$this->memberinfo['phpssouid'], 'ps_auth_key'=>$ps_auth_key), '', $ps_auth_key);
  
$upurl = base64_encode($phpsso_api_url.'/index.php?m=phpsso&c=index&a=uploadavatar&auth_data='.$auth_data);
  
//获取头像数组
  
$avatar = $this->client->ps_getavatar($this->memberinfo['phpssouid']);
  
  
  
include template('member', 'account_manage_avatar');
  
}

这里是一个上传头像的功能模块,我们继续跟踪上传地址为

v9/phpsso_server/index.php?m=phpsso&c=index&a=uploadavatar

读取v9phpsso_serverphpcmsmodulesphpssoindex.php文件

其中uploadavatar为我们处理上传头像函数

具体函数如下

public function uploadavatar() {

//根据用户id创建文件夹
  
if(isset($this->data['uid']) && isset($this->data['avatardata'])) {
  
$this->uid = $this->data['uid'];
  
$this->avatardata = $this->data['avatardata'];
  
} else {
  
exit('0');
  
}
  
  
  
$dir1 = ceil($this->uid / 10000);
  
$dir2 = ceil($this->uid % 10000 / 1000);
  
  
  
//创建图片存储文件夹
  
$avatarfile = pc_base::load_config('system', 'upload_path').'avatar/';
  
$dir = $avatarfile.$dir1.'/'.$dir2.'/'.$this->uid.'/';
  
if(!file_exists($dir)) {
  
mkdir($dir, 0777, true);
  
}
  
  
  
//存储flashpost图片
  
$filename = $dir.$this->uid.'.zip';
  
file_put_contents($filename, $this->avatardata);
  
echo $filename;exit();
  
//解压缩文件
  
pc_base::load_app_class('pclzip', 'phpsso', 0);
  
$archive = new PclZip($filename);
  
if ($archive->extract(PCLZIP_OPT_PATH, $dir) == 0) {
  
die("Error : ".$archive->errorInfo(true));
  
}
  
  
  
//判断文件安全,删除压缩包和非jpg图片
  
$avatararr = array('180x180.jpg', '30x30.jpg', '45x45.jpg', '90x90.jpg');
  
if($handle = opendir($dir)) {
  
   while(false !== ($file = readdir($handle))) {
  
if($file !== '.' && $file !== '..') {
  
if(!in_array($file, $avatararr)) {
  
@unlink($dir.$file);
  
} else {
  
$info = @getp_w_picpathsize($dir.$file);
  
if(!$info || $info[2] !=2) {
  
@unlink($dir.$file);
  
}
  
}
  
}
  
   }
  
   closedir($handle);    
  
}
  
$this->db->update(array('avatar'=>1), array('uid'=>$this->uid));
  
exit('1');
  
}
  
  
其中关键代码
  
pc_base::load_app_class('pclzip', 'phpsso', 0);
  
$archive = new PclZip($filename);
  
if ($archive->extract(PCLZIP_OPT_PATH, $dir) == 0) {
  
die("Error : ".$archive->errorInfo(true));
  
}

这里为解压缩文件

接下来为判断是否为图片类型

//判断文件安全,删除压缩包和非jpg图片
  
$avatararr = array('180x180.jpg', '30x30.jpg', '45x45.jpg', '90x90.jpg');
  
if($handle = opendir($dir)) {
  
   while(false !== ($file = readdir($handle))) {
  
if($file !== '.' && $file !== '..') {
  
if(!in_array($file, $avatararr)) {
  
@unlink($dir.$file);
  
} else {
  
$info = @getp_w_picpathsize($dir.$file);
  
if(!$info || $info[2] !=2) {
  
@unlink($dir.$file);
  
} 
} 
}
   }
   closedir($handle);    
}

为180×180.jpg’, ’30×30.jpg’, ’45×45.jpg’, ’90×90.jpg ,如果不为这几种,则就删除,但是他考虑到的仅仅是当前目录下的,没做循环遍历,导致我们可以新建一个目录,然后里面放入我们的PHP***,然后压缩成zip,然后再上传,然后即可达到任意上传文件,直接前台无限制getshell

0x03:漏洞利用

新建一个如图文件

新建一个22目录,目录里面放入我们的test.php文件,test.php里面放入我们的一句话,然后压缩成zip文件

20140126180714.jpg

然后上传一个正常头像,获取一个路径,如正常头像地址为http://127.0.0.1/v9/phpsso_server/uploadfile/avatar/1/1/3/90×90.jpg

然后我们再次上传,通过burpsuit抓包,将其中post的内容用paste from file替换掉

20140126180805.jpg

然后发送

最好获取shell路径为 在之前的正常路径下面加上我们的解压路径,如http://127.0.0.1/v9/phpsso_server/uploadfile/avatar/1/1/3/22/test.php

20140126180849.jpg