zoukankan      html  css  js  c++  java
  • [HCTF 2018]WarmUp 1【BUUCFT】【代码审计】

    查看 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" />";
        }  
    ?>
    
    

    分析原理: 字符串 -> 加上 “?” -> 截取 从开始到 第一个出现 “?” 作为名字 变量 -> 检查是否在白名单中 -> 返回true

    hook : 字符串 先加上 在白名单之后先加上 “?” 再拼接地址-> 截取的一定是 白名单中的 -> 利用 / 使得 hint.php? 变为不存在的目录 最后include利用../../跳转目录读取flag [1]

     ?file=hint.php?/../../ff....
    

    1. ../ 是跳转到上级目录 ↩︎

  • 相关阅读:
    考研_数据结构
    快速排序模板
    nginx设置跳转https
    PHP 构造函数
    js scroll事件
    php获取url中的参数
    js 的cookie问题
    yii2关联表
    sql优化之concat/concat_ws/group_concat
    yii2.0 url美化-apache服务器
  • 原文地址:https://www.cnblogs.com/borber/p/Warm_Up_1.html
Copyright © 2011-2022 走看看