BUUCTF-[HCTF 2018]WarmUp

时间:2020-04-21
本文章向大家介绍BUUCTF-[HCTF 2018]WarmUp,主要包括BUUCTF-[HCTF 2018]WarmUp使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

0x00:写在前面

最近把ctf捡起来 好久没写题目了,准备刷刷ctf题目

冲啊!!!

0x01:解题思路

首先打开页面 查看源代码发现线索。

 打开source.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)) {//第一次判断 page是否在白名单中,是则返回true
                return true;
            }

            $_page = mb_substr(//page后面加上?进行 mb_substr截取(此时就是一个利用点)
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {//第二次判断截取后的是否在白名单中,是则返回true)
                return true;
            }

            $_page = urldecode($page);(url解码一下,暗示我们要二次url编码)
            $_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'])//要满足以上三个条件,第一个第二个很好满足,就差最后一个checkfile的true了
    ) {
        include $_REQUEST['file'];//满足以上三个条件则直接包含
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?>

那么通过观察源码,发现还存在另一个hint.php文件,打开文件发现是一串提示

 那么flag就存在ffffllllaaaagggg

题目意思很明确 我们去包含这个flag文件 读文件即可

那么看到include 和上面的checkfile我们就很敏感的得知是利用include(hint.php?ffffllllaaaagggg)

那么进行构造即可payload如上

in_array() 这里hint.php#可以绕过第一个if检测,但对我们拿flag没用,必须要hint.php?才可以,那么此时第一个if无法利用

看第二个,有个问好截取

直接利用第二个if即可(可能是出题人失误吧,倒不用第三个if也可以解题)

需要用到目录跳转

经过尝试得到

?file=hint.php?../../../../../ffffllllaaaagggg

原文地址:https://www.cnblogs.com/Tkitn/p/12743700.html