打开题目首先看到的是这样的,然后通过f12找到了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\" />";
}
?>
然后看到提示hint.php,访问后得到flag在ffffllllaaaagggg下,然后开始审计一波代码。
首先它先判定了传入的是不是空或者是不是字符串,然后进行了三次白名单判断。
里面涉及到mb_substr(),mb_strpos(),urldecode()三个函数。
mb_substr(str,start,length,encoding):返回从start位置开始的长度为length的字符串。
mb_strpos(str,find_str,offset,encoding):返回str中从offset(默认为0)开始第一次出现find_str的位置。
urlcode():对其传入的str参数进行str解码。
根据代码分析得到,在第一次$_page取的是从0开始到第一次出现?之间的字符串,所以我们在参数中传入一个?绕过白名单。
最后的payload为:
http://3d60ae22-b588-48ca-b084-541dc4f6eb37.node4.buuoj.cn/source.php?file=hint.php?/../../../../ffffllllaaaagggg
$_page第一次取值为hint.php在白名单,返回true,然后包含hint.php?/…/…/…/…/ffffllllaaaagggg这个文件得到flag。
这里解释一下为什么要这么多…/ ?
在include包含路径中,可以随便输入一个字符串,然后再输入一个…/就可以抵消,否则就会报错不存在此路径,这里多个…/就是不断的返回上一级目录查找ffffllllaaaagggg,最后返回flag。