buuoj--[HCTF 2018]WarmUp

buuoj中的第一题:[HCTF 2018]WarmUp

打开题目页面在这里插入图片描述
右键查看源码,发现提示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\" />";
    }  
?> 

上面是一个类(没学过PHP,大同小异嘛)
下面有个判断

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传递的参数的文件,想到可能时任意文件包含。

通过引入文件时,引用的文件名,用户可控,由于传入的文件名没有经过合理的校验,或者检验被绕过,从而操作了预想之外的文件,就可能导致意外的文件泄露甚至恶意的代码注入。

再看if中的判断,file参数不为空&&是个字符串&&通过checkFile方法的检验。去看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;
        }

这里逻辑也不是很复杂。
首先看到了提示的白名单,去看看hint.php
在这里插入图片描述

验证了猜想,任意文件包含漏洞。

checkFIle中有白名单,source.php和hint.php。
下面又是很多条件限制。一步一步看。

$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

首先必须存在并且是字符串(必须使函数返回为true才能访问文件)

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;

然后判断参数是否在白名单中;
mb_strpos()查找字符串在另一个字符串中首次出现的位置,即?在前面字符串中出现的位置
mb_substr()方法截断字符串。
然后和白名单比较。
又重复了一次上面的操作。
这个涉及到phpMyAdmin的一个洞CVE-2018-12613,由于PHP会自动urldecode一次,导致我们提交%253f(?的urlencode的urlencode)的时候自动转成%3f,满足if条件,%253f/就会被认为是一个目录,从而include。

? --> %3f --> %253f
payload: file=hint.php%253f/…/…/…/…/…/…/…/ffffllllaaaagggg
目录需要多跳出几次,慢慢尝试。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值