| 
 
 buuctf web WarmUp  得到一张滑稽图片     查看网页源代码,发现注释了一个source.php,在url中输入source.php得到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\" />";
    }  
?>
  
首先设置了白名单source.php和hint.php。于是进入hint.php查看得到:flag not here, and flag in ffffllllaaaagggg。flag应该就在ffffllllaaaagggg中,不过现在还不知道这是什么意思,继续看source.php码源。  
第一个if条件变量不为空且变量要为字符串;第二个if条件in_array()函数检验page变量是否在白名单中;第三个if条件检验_page变量是否在白名单中。可以看出checkFile函数只要有一个if条件为真就会返回true,便不会在往下执行。  
这里借鉴别人的博客构造payload  
   file=source.php%253f/../../../../../../ffffllllaaaagggg经过两次解码后会得到source.php?/../../../../../../ffffllllaaaagggg,两次解码是因为前面的urldecode函数以及$_REQUEST均会对传入参数进行解码。  
这里…/的个数可以自己测试得出,依次添加知道出现flag,或者可以直接写入多个,一般情况下可以直接切换至ffffllllaaaagggg目录中。 
                
                
                
        
    
 
 |