首先查看源码看到提示source.php
查看source.php看到源码

需要一个file参数,并且需要checkFile函数返回真才可以执行文件包含

checkFile函数中看到hint.php,请求后得到flag not here, and flag in ffffllllaaaagggg
然后继续往后看

首先字符串最后拼接一个问号,然后mb_strpos返回第一次出现问号时字符串的长度,然后mb_substr把字符串第一次出现问号之前的内容截取出来。
如果截取下来的部分在白名单中,也就是source.php或者hint.php,就会返回true
所以我们构造了字符串为/source.php?file=source.php?ffffllllaaaagggg
虽然没有直接返回flag,但是没有看到这个函数最后echo出的you can't see it

说明代码在前面就返回true出去了,没有执行到最后面,那么证明我们想法对了,但是include包含读取的文件位置不对
然后就加../来进行目录变换,最后加到5个得到Flag。
即:/source.php?file=source.php?../../../../../ffffllllaaaagggg
参考资料:https://blog.csdn.net/u014029795/article/details/105232104/
源码:
<?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\" />";
}
?>
|