第一题——[HCTF 2018]WarmUp

题目地址:https://buuoj.cn/challenges

解题思路

第一步:进入题目,迎面而来的是一张滑稽图片,按f12查看,发现提示:source.php

在这里插入图片描述

第二步:在URL一栏输入访问提示给出的php页面

http://c0717382-8c47-4aa3-b308-1972e1173f7a.node3.buuoj.cn/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\" />";
    }  
?>

第四步:分析代码

  1. 先查看主函数
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\" />";
    } 

       提取页面提交过来的file参数,并判断file参数是否为为空,是否为字符串,以及是否通过了checkFile函数,三项检测都通过了则使用include函数将file参数指定的内容插入到当前页面中。没有通过则打印之前看到的那张滑稽图片。
       结论:需要在URL栏添加?file=xxx内容。其中xxx指向flag所在文件,且要通过三重检测。

  1. 之后查看checkFile函数
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判断xxx内容是否为空是否为字符串。
第二个if判断xxx内容是否包含白名单里的内容。
之后对xxx内容进行截断,从开头阶段到?之前。
第三个if判断截断后的内容里是否包含有白名单里面的内容。
之后对xxx进行解码,再截断。
第四个if执行第三个if同样功能。
结论:需要构造?file=source.php?/…/…/…/…/xxx,在第二个if中返回true通过验证然后将xxx输出到当前页面。其中xxx指向flag所在页面。
使用多个…/是利用一个漏洞。漏洞地址:phpmyadmin 4.8.1 远程文件包含漏洞(CVE-2018-12613)

第五步:确定flag所在

在第四步中发现除了可以访问source.php以外,还可以访问hint.php。访问hint.php之后得到flag所在地。
在这里插入图片描述

第六步:获得flag

在URL一栏输入
http://c0717382-8c47-4aa3-b308-1972e1173f7a.node3.buuoj.cn/source.php?file=hint.php?/../../../../../ffffllllaaaagggg
得到flag:c4f4e88f-69c5-487a-8168-3c8c187d080a
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37589805/article/details/115349750