- f12发现源码
<?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\" />";
}
?>
整体逻辑
- 请求参数
file
不为空且不为数字 emmm.checkFile
方法返回true- 利用include读取文件
再看hint
flag not here, and flag in ffffllllaaaagggg
目标读取ffffllllaaaagggg
- emmm.checkFile
class emmm
{
public static function checkFile(&$page)
{
// page为 ?file=xxxx
$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;
}
// mb_substr(str,start,end) 返回str[start,end)的字符
$_page = mb_substr(
$page,
0,
// mb_strpos — 查找字符串在另一个字符串中首次出现的位置
mb_strpos($page . '?', '?')
);
// 如果_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;
}
}
分析代码知道只需要checkFile第二个if返回true或者是第三个if,并且读取ffffllllaaaagggg
构造payload
?file=source.php?../…/…/…/…/ffffllllaaaagggg
多写几层…/