forked from JoyChou93/java-sec-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRce.java
More file actions
55 lines (45 loc) · 1.5 KB
/
Rce.java
File metadata and controls
55 lines (45 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package org.joychou.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* @author: JoyChou (joychou@joychou.org)
* @date: 2018.05.24
* @desc: java xxe vuls code
* @fix: 过滤造成命令执行的参数
*/
@Controller
@RequestMapping("/rce")
public class Rce {
@RequestMapping("/exec")
@ResponseBody
public String CommandExec(HttpServletRequest request) {
String cmd = request.getParameter("cmd").toString();
Runtime run = Runtime.getRuntime();
String lineStr = "";
try {
Process p = run.exec(cmd);
BufferedInputStream in = new BufferedInputStream(p.getInputStream());
BufferedReader inBr = new BufferedReader(new InputStreamReader(in));
String tmpStr;
while ((tmpStr = inBr.readLine()) != null) {
lineStr += tmpStr + "\n";
System.out.println(tmpStr);
}
if (p.waitFor() != 0) {
if (p.exitValue() == 1)
return "command exec failed";
}
inBr.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
return "Except";
}
return lineStr;
}
}