打开网页后,发现除了一个大滑稽什么也没有,所以只能去看网页源代码,并在源代码中发现了一行注释”<–source.php–>”。
由于注释后缀名为“php”所以想到想网址后添加该注释,然后就得到了一堆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\" />";
}
?>
通过代码大概可知此网站的白名单中包含两个文件:“source.php”和“hint.php”。输入另一个文件名看看得到一个新的提示:
再次观察得到的那一大串php代码大概了解到了此网站的拥有3个函数检查,且必须绕过这3个检查才能得到flag。
第一个函数检查为必须保护白名单中两个文件中的任意一个。
第二个为向php页面传入参数,由函数”mb_strpos”可知此函数可返回“?”前字符。所以需将“?”进行两次ulr编码。
第三次为需要携带字符名“file”
所以此时构造payload了,传递一个参数?
,并将?进行两次ulr编码进行目录穿越,最后得到flag。file=source.php?/../../../../../../ffffllllaaaagggg