环境搭建
安装好composer
安装教程:https://blog.csdn.net/qq_15941409/article/details/81233168
composer create-project topthink/think=6.0.x-dev thinkphp-v6.0
cd thinkphp-v6.0
php think run
正常的逻辑都是从__destruct方法入手,这里全局搜素一下
vendor\league\flysystem-cached-adapter\src\Storage\AbstractCache.php下找到了一个___destruct,
public function __destruct()
{
if (! $this->autosave) {
$this->save();
}
}
找一个类掉用了save方法,并且有可以利用的地方
在vendor/league/flysystem-cached-adapter/src/Storage/Adapter.php找到了一个save方法
public function save()
{
$config = new Config();
$contents = $this->getForStorage();
if ($this->adapter->has($this->file)) {
$this->adapter->update($this->file, $contents, $config);
} else {
$this->adapter->write($this->file, $contents, $config);
}
}
这里
t
h
i
s
−
>
a
d
a
p
t
e
r
−
>
h
a
s
(
this->adapter->has(
this−>adapter−>has(this->file)判断文件是否存在
可以看到这里可以使用write进行写文件,其实update跟write的构造链是一样的,如果存在的话就给他覆盖了
我们找找哪一个类调用了write方法
\League\Flysystem\Adapter\Local
public function write($path, $contents, Config $config)
{
$location = $this->applyPathPrefix($path);
$this->ensureDirectory(dirname($location));
if (($size = file_put_contents($location, $contents, $this->writeFlags)) === false) {
return false;
}
$type = 'file';
$result = compact('contents', 'type', 'size', 'path');
if ($visibility = $config->get('visibility')) {
$result['visibility'] = $visibility;
$this->setVisibility($path, $visibility);
}
由file_put_contents函数可以看到这里进行了写文件的操作
我们继续看看参数是否可控
$path是我们传进来的文件名
applyPathPrefix()将文件左边的斜杠(“/”)去除
ensureDirectory 保证目录存在
l
o
c
a
t
i
o
n
我们已经控制了继续看看
location我们已经控制了 继续看看
location我们已经控制了继续看看contents怎么进行控制
$contents = $this->getForStorage();
public function getForStorage()
{
$cleaned =
t
h
i
s
−
>
c
l
e
a
n
C
o
n
t
e
n
t
s
(
this->cleanContents(
this−>cleanContents(this->cache);
return json_encode([$cleaned, $this->complete, $this->expire]);
}
这里我们只需要将complete赋值为我们的一句话木马,也就实现了我们的写马操作