PHP代码审计-[HCTF 2018]WarmUp

课设里有php代码审计的题目,但是合天网安实验室推荐的zzcms的css有问题,不想弄它了,就搜到了写buu上面的代码审计题目算了
题目:/source.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\" />";
    }  
?>

提示:/hint.php

flag not here, and flag in ffffllllaaaagggg

我这里只提一些注意的地方

  • isset() — 检测变量是否设置。是则返回 TRUE,否则返回 FALSE。
  • is_string() 函数用于检测变量是否是字符串。是则返回 TRUE,否则返回 FALSE。
  • strpos() 函数查找字符串在另一字符串中第一次出现的位置。
  • in_array() 函数搜索数组中是否存在指定的值。是则返回 TRUE,否则返回 FALSE。
    in_array(search,array,type)

PHP代码审计-[HCTF 2018]WarmUp_第1张图片

  • mb_substr() 函数返回字符串的一部分,之前我们学过 substr() 函数,它只针对英文字符,如果要分割的中文文字则需要使用 mb_substr()。
    注释:如果 start 参数是负数且 length 小于或等于 start,则 length 为 0。

echo mb_substr("just do you job", 0, 4);
// 输出:just
?>
  • urldecode()就是url编码
  • “./”:代表目前所在的目录。" . ./“代表上一层目录。”/":代表根目录。

结题思路

两次?截断,这里有个隐藏点,PHP中_GET、_POST、_REQUEST这类函数在提取参数值时会URL解码一次,所以我们应当对”?"进行两次编码
所以payload

/source.php?file=source.php%253F/../../../../ffffllllaaaagggg

你可能感兴趣的:(代码审计)