Day24

welcome to bugkuctf

http://123.206.87.240:8006/test1/

本题要点:代码审计,PHP://filter ,  php://input ,  base64解密,反序列化

 
 
查看一下源码
 
审计源码,我们可以发现~
 
(1)get方式传递三个参数,分别是txt、file、password
 
(2)读取的$user文件内容===welcome to the bugkuctf
 
(3) $file要求为hint.php
 
接下来,我们需要了解
php:// - 访问各种I / O流

 
查一下php的手册~~~
参考:https://www.php.net/manual/en/wrappers.php.php
 
php://filter是PHP语言中特有的协议流,作用是作为一个“中间流”来处理其他流。
 
用法1:将POST内容转换成base64编码并输出:
readfile("php://filter/read=convert.base64-encode/resource=php://input"):
 
用法2:将PHP等容易引发冲突的文件流用php://filter协议流处理一遍
php://filter/read=convert.base64-encode/resource=./xxx.php
 
下面我们
构造payload~
 
 
base64解密
 
 
解出来的源码如下:
分析一下~
 
<?php  
  
class Flag{          //flag.php         
 
 // 这里 定义了一个类Flag
 
    public $file;  
    public function __tostring(){     
 //注意到下面有一个  __tostring 方法,可以理解为将这个类作为字符串执行时会自动执行的一个函数
 
        if(isset($this->file)){  
            echo file_get_contents($this->file);
            echo "<br>";
        return ("good");
        }  
    }  
}  
?>  
 
 
再用同样的方法看一下 index.php   ~
 
解出源码 ~
分析一下~
 
 
<?php  
$txt = $_GET["txt"];  
$file = $_GET["file"];  
$password = $_GET["password"];  
  
if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){  
    echo "hello friend!<br>";  
    if(preg_match("/flag/",$file)){
//这里可以看到对关键词flag进行了preg_match
 
 
        echo "不能现在就给你flag哦";
        exit();  
    }else{  
        include($file);   
        $password = unserialize($password);       // 反序列化
        echo $password;  
    }  
}else{  
    echo "you are not the number of bugku ! ";  
}  
  
?>  
  
<!--  
$user = $_GET["txt"];  
$file = $_GET["file"];  
$pass = $_GET["password"];  
  
if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){  
    echo "hello admin!<br>";  
    include($file); //hint.php  
//结合__tostring 方法,执行时,将变量$file作为文件名输出文件内容 猜想flag.php文件在此打开
}else{  
    echo "you are not admin ! ";  
}  
-->  
 
还注意到~
 
password=unserialize(password=unserialize(password);
 
因此知道需要构造序列化对象payload为
 
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
 
 
 
 
完成!

ps:这道题很灵活的运用了php://filter和php://input,值得反复思考哦~

参考资料:

https://www.php.net/manual/en/wrappers.php.php

https://blog.csdn.net/csu_vc/article/details/78375203

Bugku-CTF之welcome to bugkuctf(php://filter和php://input的妙用)的更多相关文章

  1. Bugku CTF练习题---MISC---贝斯手

    Bugku CTF练习题---MISC---贝斯手 flag:flag{this_is_md5_and_base58} 解题步骤: 1.观察题目,下载附件 2.下载后进行解压,得到了一张图片.一个压缩 ...

  2. Bugku CTF练习题---MISC---telnet

    Bugku CTF练习题---MISC---telnet flag:flag{d316759c281bf925d600be698a4973d5} 解题步骤: 1.观察题目,下载附件 2.拿到手以后发现 ...

  3. Bugku CTF练习题---MISC---眼见非实

    Bugku CTF练习题---MISC---眼见非实 flag:flag{F1@g} 解题步骤: 1.观察题目,下载附件 2.拿到手以后发现是一个压缩包,打开是一个Word文档,观察其中的内容,除了开 ...

  4. Bugku CTF练习题---MISC---宽带信息泄露

    Bugku CTF练习题---MISC---宽带信息泄露 flag:053700357621 解题步骤: 1.观察题目,下载附件 2.下载到电脑里发现是一个bin文件,二进制文件的一个种类,再看名称为 ...

  5. Bugku CTF练习题---MISC---这是一张单纯的图片

    Bugku CTF练习题---MISC---这是一张单纯的图片 flag:key{you are right} 解题步骤: 1.观察题目,下载附件 2.打开以后发现是一张图片,修改文件扩展名,查看属性 ...

  6. Bugku CTF练习题---加密---ok

    Bugku CTF练习题---加密---ok flag:flag{ok-ctf-1234-admin} 解题步骤: 1.观察题目,发现规律 2.发现所有内容都是ook写的, 直接上网搜索一下原因,发现 ...

  7. Bugku CTF练习题---加密---聪明的小羊

    Bugku CTF练习题---加密---聪明的小羊 flag:KEY{sad23jjdsa2} 解题步骤: 1.观察题目,发现其中的信息 2.经过题目判断,得知该题属于栅栏密码的一种,并且介绍中表明了 ...

  8. Bugku CTF练习题---分析---flag被盗

    Bugku CTF练习题---分析---flag被盗 flag:flag{This_is_a_f10g} 解题步骤: 1.观察题目,下载附件 2.下载的文件是一个数据包,果断使用wireshark打开 ...

  9. Bugku CTF练习题---杂项---隐写3

    Bugku CTF练习题---杂项---隐写3 flag:flag{He1l0_d4_ba1} 解题步骤: 1.观察题目,下载附件 2.打开图片,发现是一张大白,仔细观察一下总感觉少了点东西,这张图好 ...

随机推荐

  1. Python全栈-magedu-2018-笔记10

    第三章 - Python 内置数据结构 集set 约定 set 翻译为集合 collection 翻译为集合类型,是一个大概念 set 可变的.无序的.不重复的元素的集合 set定义 初始化 set( ...

  2. 严重:one or more listeners failed. Full details will be found in the appropriate container log file

    one or more listeners failed. Full details will be found in the appropriate container log file   这句话 ...

  3. js导航栏单击事件背景颜色变换

    <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8&quo ...

  4. fiddler 安装证书问题,和安装完后,浏览器无法访问问题

    安装证书问题 https://blog.csdn.net/l1336037686/article/details/78322014 浏览器无法访问问题 https://blog.csdn.net/u0 ...

  5. matlab中CRC的函数使用

    先学习一下matlab中CRC函数. 语法如下: h = crc.generator(‘Polynomial', polynomial, ‘param1', val1, etc.) 再看一个例子就比较 ...

  6. .Net Core知识点

    1:const,readonly,和get访问器,三者都可在自己的生命域里赋值,但是编译器也是可以在构造函数里进行初始化赋值的 2:Debugger.IsAttached 属性 http://msdn ...

  7. allegro17.2 gerber 步骤

    1.Manufacture -> NC -> Drill Customization... 先点击 Auto generate symbols,出来对话框后点击 YES .然后在Symbo ...

  8. filter与map函数

    ·filter()函数filter()函数包括两个参数,分别是function和list.该函数根据function参数返回的结果是否为真来过滤list参数中的项,最后返回一个新列表,如下例所示:&g ...

  9. ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:

    问题 ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set r ...

  10. 学习DButils笔记

    DBUtills: *********************** 1:创建对象:QueryRunner的对象,其中创建的方式有两种: ①QueryRunner qr = new QueryRunne ...