CTF_[HCTF 2018]WarmUp 1

source.php分析

<?php
highlight_file(__FILE__);
//display the source code of the file.
class emmm
{
    public static function checkFile(&$page)
    //传入了变量page,也就是我们刚刚传进来的file

    {
        // 这里定义了白名单,包括source.php和hint.php
        $whitelist = ["source" => "source.php", "hint" => "hint.php"];

        if (!isset($page) || !is_string($page)) {
            // $page != null and $page is a string
            echo "you can't see it";
            return false;
        }

        if (in_array($page, $whitelist)) {
            // $page is in the whitelist (source.php or hint.php) 不包含key
            return true;
        }

        // 从page中截取出?前面的字符串
        // 例如page=source.php?file=hint.php 截取出source.php
        $_page = mb_substr(
            $page,
            0,
            mb_strpos($page . '?',  '?')
           // The dot (.) is used to concatenate the two strings
           // mb_strpos() returns the position of the first occurrence of ?
        );
 
        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;
    }
}
// The $_REQUEST variable is used to collect data after submitting an HTML form.
if (
    !empty($_REQUEST['file'])
    && is_string($_REQUEST['file'])
    && emmm::checkFile($_REQUEST['file'])
) {
    include $_REQUEST['file'];
    //执行file中的代码
    exit;
} else {
    echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
}

任务分析:

绕过过滤:file=source.php?和file=hint.php?都可以绕过过滤
利用include函数的漏洞,include xxx.php 会执行xxx.php的代码,include xxx.php/ 此时xxxx.php是目录名include如果找不到目录会跳过/前的内容,继续向/后执行。
/…/…/…/…/…/…/flag.php 查找

小疑问:

为什么执行source.php 然后 include source.php 不会一直自己调用自己无限循环,file=source.php 只出现了一次源代码。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值