php代码审计之熊海CMS

 

X00代码审计之旅

刚接触代码审计,所以找了个入门级别的php源码熊海cms进行审计。如果大佬发现有错误请告知哦~
 
熊海cms下载地址:http://js.down.chinaz.com/201503/xhcms_v1.0.rar

使用的是Seay审计工具,听说误报常用。但是作为新手,也可以培养自己检测误报的能力php代码审计之熊海CMS_第1张图片
开始实验吧~ (先自动审计一波)
php代码审计之熊海CMS_第2张图片

X01文件包含

举以下栗子   /index.php与/admin/index.php


//单一入口模式
error_reporting(0); //关闭错误显示
$file=addslashes($_GET['r']); //接收文件名
$action=$file==''?'index':$file; //判断为空或者等于index
include('files/'.$action.'.php'); //载入相应文件
?>

问题:
这里出现include()函数,存在一个非常明显的文件包含漏洞,参数r只经过了addslashes()的过滤。
addslashes() 函数返回在预定义字符之前添加反斜杠的字符串。
预定义字符是:单引号(’)双引号(")反斜杠(\)NULL
利用:
我们在根目录下创建phpinfo.php文件,内容为,在url里提交?r=…/phpinfo,程序添加.php后缀名后产生了文件包含。
 

X02注入

举以下栗子   /admin/files/adset.php

 <form class="form-horizontal" role="form" method="post" action=""  enctype="multipart/form-data">
        <div class="form-group">
             <label class="col-lg-4 control-label">广告一</label>
                  <div class="col-lg-8">
                       <textarea name="ad1" class="form-control col-lg-12" placeholder="ad-1"> echo $ad['ad1']?></textarea>                                  
                  </div>
        </div>                 
<div class="form-group">
 <label class="col-lg-4 control-label">广告二</label>
<div class="col-lg-8">
<textarea name="ad2" class="form-control col-lg-12" placeholder="ad-2"> echo $ad['ad2']?></textarea>
</div>
</div>     
<div class="form-group">
 <label class="col-lg-4 control-label">广告三</label>
<div class="col-lg-8">
<textarea name="ad3" class="form-control col-lg-12" placeholder="ad-2"> echo $ad['ad3']?></textarea>
</div>
</div>   
#......
#......
$ad1=addslashes($_POST['ad1']);
$ad2=addslashes($_POST['ad2']);
$ad3=addslashes($_POST['ad3']);
if ($save==1){
     
$query = "UPDATE adword SET 
ad1='$ad1',
ad2='$ad2',
ad3='$ad3',
date=now()";              

问题:
delete函数中不存在参数及引号保护过滤,导致注入
利用:
1’ or updatexml(1,concat((select concat(0x7e,[可爆字段],0x7e) from [已知表])),0) #
 

X03文件任意读取

举以下栗子   /files/downloads.php


```php
$fileadd=$down['softadd'];

$sourceFile = $fileadd; //要下载的临时文件名 

$fp = fopen("$sourceFile", "rb");  
//设置指针位置  
fseek($fp, $range);  
//虚幻输出  
while (!feof($fp)) {
       
    //设置文件最长执行时间  
    set_time_limit(0);  
    print (fread($fp, 1024 * 8)); //输出文件  
    flush(); //输出缓冲  
    ob_flush();  
}  
fclose($fp); 

问题:
没进行参数对路径的限制和过滤
利用:
如果猜解出敏感文件或已知文件,可导致信息泄露的安全问题
 

X04任意文件上传

举以下栗子   /inc/up.class.php

/
	if ( move_uploaded_file( $this -> uploadFile[ 'tmp_name' ] , realpath( $this -> accessPath ) . "/" . $newFileName ) ) 
	{
     
		$this -> newFileName = $newFileName;
			return true;
	}else{
     
		return false;
	}
/
} 
function CheckFileExist( $path = NULL)
 {
     
  return ($path == NULL) ? false : ((file_exists($path)) ? true : false);
 }
function GetFileMIME()
 {
     
  return $this->GetFileTypeToString();
 }
function CheckFileMIMEType()
 {
     
  $pass = false;
  $defineTypeList = strtolower( $this ->defineTypeList);
  $MIME = strtolower( $this -> GetFileMIME());
  if (!empty ($defineTypeList))
  {
     
   if (!empty ($MIME))
   {
     
    foreach(explode("|",$defineTypeList) as $tmp)
    {
     
     if ($tmp == $MIME)
     {
     
      $pass = true;
     }
    }
   }
   else
   {
     
    return false;
   }      
   }
   else
   {
     
   return false;
   }
   return $pass;
 }
 function GetFileTypeToString()
 {
     
  if( ! empty( $this -> uploadFile[ 'name' ] ) )
  {
     
   return substr( strtolower( $this -> uploadFile[ 'name' ] ) , strlen( $this -> uploadFile[ 'name' ] ) - 3 , 3 );  
  }
 }
}
?>

问题:
存在任意文件上传漏洞。
explode()函数,使用一个字符串分割另一个字符串,并返回由字符串组成的数组。
substr()函数,返回字符串的一部分。
strtolower()函数,把字符串转换为小写。并不能过滤阻止任意文件的上传漏洞。
利用:
传小马,getshell
 

X05xss

举以下栗子   /seacmseditor/php/controller.php

if (isset($_GET["callback"])) {
     
    if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
     
        echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
    } else {
     
        echo json_encode(array(
            'state'=> 'callback参数不合法'
        ));
    }
} else {
     
    echo $result;
}

误报: htmlspecialchars转义成为了html实体

X06越权访问

举以下栗子   inc/checklogin.php


$user=$_COOKIE['user'];
if ($user==""){
     
header("Location: ?r=login");
exit;	
}
?>

利用:若猜解出管理员权限的user参数值,即可实现越权访问
 
 
**************************************************************
以上是我暂有能力范围内在此cms上找到找出常见的漏洞…

你可能感兴趣的:(代码审计,php,cms)