intval函数绕过
$num="3e3";
if(intval($num) < 2020 && intval($num + 1) > 2021)
{
echo "yes";
}
else
{
echo "no";
}
basename函数绕过
1. 函数作用
basename() 函数返回路径中的文件名部分。
$path="/www/index.php";
echo basename($path)."<br />";
//output: index.php
echo basename($path,".php")."<br />";
//output: index
2. 函数漏洞
在使用默认语言环境设置时,basename() 会删除文件名开头的非 ASCII 字符。
例如:
$path1="/www/%ffindex.php";
echo basename($path1)."<br />";
//output: index.php
$path2="/www/index.php%ff";
echo basename($path2)."<br />";
//output: index.php
$path3="/www/index.php/%ff";
echo basename($path3)."<br />";
//output: index.php
$path4="/www/index.php/+";
echo basename($path4)."<br />";
//output: +
我们可以这样利用:(Apeach限定)
//$_SERVER['PHP_SELF']="flag.php/%ff"
$path=$_SERVER['PHP_SELF'];
//限制不能以flag.php结尾
if (preg_match('/flag\.php\/*$/i', $path))
{
exit("die");
}
echo basename($path);
//output: flag.php
PS. Apeach解析问题
这个问题不会出现在Nginx(1.15.11)上,我测试了Apeach(2.4.39),$_SERVER['PHP_SELF']
中的值取决于url。
测试代码:
//test.php
echo $_SERVER['PHP_SELF'];
- 访问
http://127.0.0.1/test.php
- Output: test.php
- 访问
http://127.0.0.1/test.php/flag.php
- Output: test.php/flag.php
- 访问
http://127.0.0.1/test.php/flag.php?source
- Output: test.php/flag.php
这个特性保证了我们正常访问了test.php
也能操作$_SERVER['PHP_SELF']
的值。这使得在这个题中我们可以改变highlight_file()
的文件,实现SSRF。
会结合basename函数绕过考察
preg_match绕过
因为preg_match只会去匹配第一行,所以这里可以用多行进行绕过
在需要绕过的位置前添加%0A(换行符)
array_search($str, $arr)绕过
这个函数的作用是在数组中寻找是否存在某一值,但是他寻找的比较方法使用的是PHP的弱比较。
如果搜寻的$str是一个字符串,想要该函数返回true,则只需要$arr中存在一个数值0即可。
原理:bool("abcd" == 0) => True