<?php
include 'utils.php';
if (isset($_POST['guess'])) {
$guess = (string) $_POST['guess'];
if ($guess === $secret) {
$message = 'Congratulations! The flag is: ' . $flag;
} else {
$message = 'Wrong. Try Again';
}
}
if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
exit("hacker :)");
}
if (preg_match('/show_source/', $_SERVER['REQUEST_URI'])){
exit("hacker :)");
}
if (isset($_GET['show_source'])) {
highlight_file(basename($_SERVER['PHP_SELF']));
exit();
}else{
show_source(__FILE__);
}
?>
挺有意思的一道文件包含题
首先先了解每一个函数的作用:
函数preg_match来判断规则返回0和1
假如https://plustop.top/php/index.php/test/tt?user=xiao
$_SERVER['PHP_SELF']得到:/php/index.php/test/tt
$_SERVER['REQUEST_URL']得到:/php/index.php/test/tt?user=xiao
其次$_SERVER['REQUEST_URL']并不会对参数中的特殊符号进行解密
所以$_SERVER['REQUEST_URL']可以用url编码绕过(也可以加号(+) 左中括号([) 空格( ) 点号(.)绕过'_')
其次我们可以发现
if (preg_match('/utils\.php\/*$/i', $_SERVER['PHP_SELF'])) {
exit("hacker :)");
}
这里对utils/php进行了一个过滤,说明flag或许就在utils.php这个文件里面,这个如何绕过呢,这段代码的意思很简单就是不能以utils.php结尾,否则退出,要读取utils.php但是不以utils.php结尾的话,只能用废话来绕过了,其次可以注意到
basename函数会过滤掉非ASCII的参数
这里就可以对他进行一个利用,例如一些中文字符,来将结尾的字符删除,从而实现utils.php的读取
还需要添加一个index.php来当做跳板请求