XCTF:warmup[WriteUP]

    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\" />";
}  

?>




---


### 访问hint.php


只有一串文字,考虑flag很有可能就在这个‘ffffllllaaaagggg’文件中


![](https://img-blog.csdnimg.cn/direct/b096d0c836f5496fa734b8b8ad340bbc.png)



回到source.php代码中


分析这段有包含命令的代码:**include $\_REQUEST['file'];**



if (! empty(KaTeX parse error: Expected 'EOF', got '&' at position 27: …ile']) &̲& is_string(_REQUEST[‘file’])
&& emmm::checkFile($_REQUEST[‘file’])
) {
include $_REQUEST[‘file’];
exit;
} else {
echo “
<img src=“https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg” />”;
}


1. `!empty($_REQUEST['file']:**请求是否非空**`
2. `is_string($_REQUEST['file']:**请求是否为字符串**`
3. `emmm::checkFile($_REQUEST['file']):**能否通过checkFile()函数的判定**`


`**当三个条件同时为真时,对文件‘file’执行包含**`




---


### 审计`checkFile函数`



class emmm
{
public static function checkFile(&$page)
{
w h i t e l i s t = [ " s o u r c e " = > " s o u r c e . p h p " , " h i n t " = > " h i n t . p h p " ] ; i f ( ! i s s e t ( whitelist = ["source"=>"source.php","hint"=>"hint.php"]; if (! isset( 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;
    }
}

1. `!isset($page) || !is_string($page):**$page变量不存在或者不是字符串**`
2. `in_array($page, $whitelist):**$page变量存在于$whitelist数组中**`
3. `$_page = mb_substr:**截取出一段字符串并串赋值给$\_page**`
4. `in_array($_page, $whitelist):**$\_page变量存在于$whitelist数组中**`
5. `$_page = urldecode($page):**对$page进行url解码后赋值给$\_page**`



$_page = mb_substr(
p a g e , 0 , m b s t r p o s ( page, 0, mb_strpos( page,0,mbstrpos(page . ‘?’, ‘?’)
);


在上述代码中,新建了一个$\_page变量


截取函数:mb\_substr选定$page变量为被截取的字符串


从位置下标0开始进行字符串截取,mb\_strpos则是字符串查找函数


mb\_strpos($page.'?','?'),代表查找$page变量中的‘?’字符并返回‘?’的位置


如果没找到‘?’,则假设‘?’在$page字符最后一位,以此保证该函数有返回值


所以整个mb\_substr函数代表者:如果$page中存在‘?’则截取出‘?’之前的字符串


如果‘?’不存在,则$page整体都将被截取出来,则‘?file=\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*’


## 学习路线:

这个方向初期比较容易入门一些,掌握一些基本技术,拿起各种现成的工具就可以开黑了。不过,要想从脚本小子变成黑客大神,这个方向越往后,需要学习和掌握的东西就会越来越多以下是网络渗透需要学习的内容:  
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/7a04c5d629f1415a9e35662316578e07.png#pic_center)



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值