主要考察的是 文件包含漏洞和代码的审计以及一些文件操作
进入在线场景按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\" />";
}
?> <?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\" />";
}
?>
简略的分析之后,
我们首先尝试第一个二个if通过
用file=hint.php提交试试看
得到flag的线索在如上名称的文件中
选择尝试第三个if
我们分析可以得知第二个if截断了我们提交的file名从开始到第一个?的子字符串
所以我们可以构造一个文件名称
file = hint.php?************
而并不确定我们的目标文件所在的文件目录
所以我们使用文件包含漏洞
hint.php?/../../../../**********(第一个/的作用是让include 的函数 认为我们的hint.php?是一个文件夹,我们再使用../返回上一层目录就可以实现了。接下来我们要做的就是重复加上../来搜索目标文件
最后我们的pay load为 ?file=source.php?/../../../../../ffffllllaaaagggg
选择第四个if
和第一个的唯一区别在于多一了一个url解码。
我们知道我们的url在提交时会被进行一次编码 让?#等符号进行编码,而我们想要在此处出现?而不在第三个问号处出现?就得进行两次的编码
?两次编码后得到%253f
所以我们的第二个pay load 为?file=source.php%253f../../../../../ffffllllaaaagggg