hctf2018

作者: 蓝小俊 | 来源:发表于2018-12-23 17:22 被阅读24次

打开题目,f12发现

<!--source.php-->

以及hint和link:http://warmup.2018.hctf.io/index.php?file=hint.php
网页内容:

hint.png
访问source.php,发现源代码
<?php
    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)) {  //in_array(search,array,type)   函数搜索数组中是否存在指定的值。
                return true;
            }

            $_page = mb_substr(  //mb_substr — 获取部分字符串
                $page,
                0,
                mb_strpos($page . '?', '?') //mb_strpos — 查找字符串在另一个字符串中首次出现的位置
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page); //urldecode — 解码已编码的 URL 字符串
            $_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\" />";
    }  
?>
  • 思路
    发现checkFile函数$_page取file参数第一个问号之前的字段检查文件名是否在白名单内
    是构造file参数为hint.php?/../../../../../ffffllllaaaagggg
  • 原理
    原理是hint.php?/被当作目录,之后上跳目录就好了(这个只适用于linux)


    image.png

相关文章

  • BUUOJ刷题

    0x01 WarmUp 出处:HCTF2018 要使emmm::checkFile($_REQUEST['fil...

  • hctf2018

    打开题目,f12发现 以及hint和link:http://warmup.2018.hctf.io/index.p...

  • HCTF2018 WarmUp

    buuctf第一题。打开页面看到一个滑稽表情,f12发现提示source.php进入该页面,发现是代码审计,代码如...

  • HCTF2018 Finals

    prepare Router: Something for pwn: Something wrong with ...

  • HCTF2018-easy_exp

    easy_exp 前些天参加了HCTF2018的线上赛,一如既往的被大佬们吊打。赛后结合大佬的讲解发现这道题就是u...

网友评论

    本文标题:hctf2018

    本文链接:https://www.haomeiwen.com/subject/nqmnkqtx.html