加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Thinkphp 缓存RCE

发布时间:2020-12-13 17:33:47 所属栏目:PHP教程 来源:网络整理
导读:? 5.0.0=ThinkPHP5=5.0.10 ? 。 ? 漏洞利用条件: 1. 基于 tp5 开发的代码中使用了 Cache::set 进行缓存 2. 在利用版本范围内 3.runtime 目录可以访问 ? 扩展 : 1. 不可访问,可以考虑包含。前提要找到包含处。 //Tp 有一个 Cache 一个包含 2. 利用缓存,做

?5.0.0<=ThinkPHP5<=5.0.10?

?

漏洞利用条件:

1.基于tp5开发的代码中使用了Cache::set 进行缓存

2.在利用版本范围内

3.runtime目录可以访问

?

扩展:

1.不可访问,可以考虑包含。前提要找到包含处。//Tp有一个Cache一个包含

2.利用缓存,做一个长期的shell动态生成。

?

漏洞原因:缓存名,可以预测,缓存内容用户可控。

?

造成漏洞代码

<?php

namespace appindexcontroller;

use thinkCache;

class Index

{

public function index()

{

Cache::set("name",input("get.username"));

return ‘Cache success‘;

}

}

?

use thinkCache; 跟到thinkCache.php

thinkCache.php 文件内容

use thinkcacheDriver;

set 方法

缓存写入次数

return self::init()->set($name,$value,$expire);

?

自动缓存

?

init 方法里

?

?

Config::get(‘cache.type‘)

?

?

默认为File类型

程序获取cache type 以后

?

?

这样就加载了 thinkcachedriverFile.php

?

?

return self::init()->set($name,$expire);

通过Init() 调用file 下的set方法

if (is_null($expire)) {
$expire = $this->options[‘expire‘];

}

?

那么$expire=0

?

目录名以及文件名:

protected function getCacheKey($name,$auto = false)
{
$name = md5($name);
if ($this->options[‘cache_subdir‘]) {
//
使用子目录
$name = substr($name,2) . DS . substr($name,2); //
目录名取md5$name)的前2位,文件名为后30
}
if ($this->options[‘prefix‘]) {
$name = $this->options[‘prefix‘] . DS . $name;
}
$filename = $this->options[‘path‘] . $name . ‘.php‘;
$dir = dirname($filename);

if ($auto && !is_dir($dir)) {
mkdir($dir,0755,true);
}
return $filename;
}

?

$filename

找到set 的缓存名 就可以了 进行md5加密

2 为目录名,后30 为文件名

?

Set 只是对value做了一个序列化的操作,并没有做过滤。

dump一下 serialize 前后变化

?

?

文件的写入,这里为tp5.0.15 版本,作者对$data 进行了位置修改,并在$data 前,做了

exit()来避免用户输入的数据,被代码执行。 并且在$expire 这处,做了一个%012d强制的类型转换

?

tp5.0.10 之前,这段代码是这样的

?

?

写入的数据,之前没有exit,并且对$data 没有做过滤

导致利用%0a换行,进行代码执行。

我们访问一下文件

成功可以代码执行

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读