[SWPUCTF2018] SimplePHP
[SWPUCTF2018] SimplePHP
考点
代码审计
phar反序列化
pop链构造
wp
源码
打开靶机,在查看文件这里可以看到 url 为 http://f292dcfd-887b-4ebb-b292-7d78df57cc52.node3.buuoj.cn/file.php?file= 不难想到文件包含
试试 php://filter/ 发现没有反应,但是直接输入文件名可以读取文件,分别获取 file.php function.php class.php upload_file.php base.php
<?php
header("content-type:text/html;charset=utf-8");
include 'function.php';
include 'class.php';
ini_set('open_basedir','/var/www/html/');
$file = $_GET["file"] ? $_GET['file'] : "";
if(empty($file)) {
echo "<h2>There is no file to show!<h2/>";
}
$show = new Show();
if(file_exists($file)) {
$show->source = $file;
$show->_show();
} else if (!empty($file)){
die('file doesn\'t exists.');
} phar反序列化
拿到源码后进行审计,发现在对上传文件检查( upload_file_check )时,采用了白名单的方式

这样我们能够选择的绕过方式就不多了,可以去考虑 phar ,然后在 file.php 中发现调用了file_exists()函数,这给构造 phar 反序列化提供了条件

接下来就是读取文件了,在 Test 类的 file_get() 调用了 file_get_contents 获取文件内容,或许这就是突破口。file_get() 被调用的前提是 Test 类的实例化对象调用了未定义的属性或没有权限访问的属性,即 __get() 函数被调用

如何让 Test 类的 __get() 函数被调用,在 Show 类的 __toString() 方法中,$this->str['str']->source 访问了自己的 source 变量,这个变量 Test 类可没有,所以这就是让 $this->str['str'] 为 Test 类的实例化对象。

如何让 Show 类的 __toString() 方法被调用,可以看到在 C1e4r 中的 __destruct() 函数调用了 echo $this->test; 让 test 是 Show 类的实例化对象即可

最后是上传的路径,在 upload_file_do() 中给出了文件存储位置,实际上可以选择直接访问 /upload 寻找
上传路径为 /upload/md5(filename+ip+.jpg)

flag 的位置在 Show 类的 _show() 函数也可以看到提示,file.php 页面的注释中也有
要注意的是读取 flag 只能用绝对路径,不能使用相对路径
访问file.php?file=phar://upload/8adc336297a3d5eb2550edc08aa372a8.jpg即可
最后更新于