其他分享
首页 > 其他分享> > 【[HCTF 2018]WarmUp 1】BUUCTF

【[HCTF 2018]WarmUp 1】BUUCTF

作者:互联网

这个题主要是考察代码审计,打开容器

 

 

 就一张滑稽表情包,我们先查看网页源码

发现有一点被注释掉了,尝试访问这个文件

<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {  //is_string() 函数用于检测变量是否是字符串。
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {  //in_array() 函数搜索数组中是否存在指定的值。
                return true;
            }

            $_page = mb_substr(   //mb_substr() 函数返回字符串的一部分,之前我们学过 substr() 函数,它只针对英文字符,如果要分割的中文文字则需要使用 mb_substr()。
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);    //
urldecode():解码已编码的 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'])  //empty() 函数用于检查一个变量是否为空。
        && is_string($_REQUEST['file'])  //is_string() 函数用于检测变量是否是字符串。
        && emmm::checkFile($_REQUEST['file'])
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?>

看到如上图的PHP代码

 

 可以看到这个地方有两个PHP,我们已经用了一个,那么就先尝试一下另一个

 

 这样我们就知道了flag所在的地方

我们开始直接尝试查找flag

.代表当前目录..代表上级目录

 

 

 

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

标签:BUUCTF,return,WarmUp,mb,whitelist,REQUEST,HCTF,file,page
来源: https://www.cnblogs.com/joker-qi/p/16029102.html