1
1
package com .websocket .findMemShell ;
2
2
3
+ import java .net .URL ;
3
4
import java .util .ArrayList ;
4
5
import java .util .List ;
5
6
import java .util .Map ;
6
7
import java .util .Stack ;
7
8
9
+ import com .websocket .findMemShell .checkAndDel .getControllerResult ;
10
+ import com .websocket .findMemShell .checkAndDel .getWsConfigResult ;
11
+
8
12
public class SearchCallsThread extends Thread {
9
13
Map <String ,List <String >> discoveredCalls ;
10
14
String sinkMethod = "java/lang/Runtime#exec" ;
@@ -16,34 +20,75 @@ public SearchCallsThread(Map<String,List<String>> discoveredCalls) {
16
20
this .discoveredCalls = discoveredCalls ;
17
21
}
18
22
23
+ public void checkWsConfig (ConfigPath cp ) {
24
+ //System.out.println("WsConfig Class: \n"+cp.getClassName().replaceAll("\\.", "/")+"#onMessage"+"\n");
25
+
26
+ if (discoveredCalls .containsKey (cp .getClassName ().replaceAll ("\\ ." , "/" )+"#onMessage" )) {
27
+ List <String > list = discoveredCalls .get (cp .getClassName ().replaceAll ("\\ ." , "/" )+"#onMessage" );
28
+ for (String str : list ) {
29
+ if (dfsSearchSink (str )) {
30
+ stack .push (str );
31
+ stack .push (cp .getClassName ().replaceAll ("\\ ." , "/" )+"#onMessage" );
32
+ StringBuilder sb = new StringBuilder ();
33
+ while (!stack .empty ()) {
34
+ sb .append ("->" );
35
+ sb .append (stack .pop ());
36
+ }
37
+ System .out .println ("CallEdge: " +sb .toString ());
38
+ if (getWsConfigResult .deleteConfig (cp .getPath ())) {
39
+ System .out .println ("Delete Class " +cp .getPath ()+" Succeed" );
40
+ }else {
41
+ System .out .println ("Delete Class " +cp .getPath ()+" Failed" );
42
+ }
43
+ break ;
44
+ }
45
+ }
46
+ }
47
+ }
48
+
49
+ public void checkControllerPath (ConfigPath cp ) {
50
+ // //内存马常规检测方式
51
+ // String className = cp.getClassName().split("#")[0];
52
+ // String classNamePath = className.replace(".", "/") + ".class";
53
+ // URL is = App.servletContext.getClass().getClassLoader().getResource(classNamePath);
54
+ // if (is == null) {
55
+ // return "在磁盘上没有对应class文件,可能是内存马";
56
+ // } else {
57
+ // return is.getPath();
58
+ // }
59
+
60
+ //System.out.println("Controller Class: \n"+cp.getClassName().replaceAll("\\.", "/"));
61
+
62
+ if (discoveredCalls .containsKey (cp .getClassName ().replaceAll ("\\ ." , "/" ))) {
63
+ List <String > list = discoveredCalls .get (cp .getClassName ().replaceAll ("\\ ." , "/" ));
64
+ for (String str : list ) {
65
+ if (dfsSearchSink (str )) {
66
+ stack .push (str );
67
+ stack .push (cp .getClassName ().replaceAll ("\\ ." , "/" ));
68
+ StringBuilder sb = new StringBuilder ();
69
+ while (!stack .empty ()) {
70
+ sb .append ("->" );
71
+ sb .append (stack .pop ());
72
+ }
73
+ System .out .println ("Controller CallEdge: " +sb .toString ());
74
+ break ;
75
+ }
76
+ }
77
+ }
78
+ }
79
+
19
80
@ Override
20
81
public void run () {
21
82
while (true ) {
22
83
List <ConfigPath > result = getWsConfigResult .getWsConfig ();
84
+ getControllerResult .getControllerMemShell (result );
23
85
if (result != null && result .size () != 0 ) {
24
86
for (ConfigPath cp : result ) {
25
- System .out .println ("WsConfig Class: \n " +cp .getClassName ().replaceAll ("\\ ." , "/" )+"#onMessage" +"\n " );
26
-
27
- if (discoveredCalls .containsKey (cp .getClassName ().replaceAll ("\\ ." , "/" )+"#onMessage" )) {
28
- List <String > list = discoveredCalls .get (cp .getClassName ().replaceAll ("\\ ." , "/" )+"#onMessage" );
29
- for (String str : list ) {
30
- if (dfsSearchSink (str )) {
31
- stack .push (str );
32
- stack .push (cp .getClassName ().replaceAll ("\\ ." , "/" )+"#onMessage" );
33
- StringBuilder sb = new StringBuilder ();
34
- while (!stack .empty ()) {
35
- sb .append ("->" );
36
- sb .append (stack .pop ());
37
- }
38
- System .out .println ("CallEdge: " +sb .toString ());
39
- if (getWsConfigResult .deleteConfig (cp .getPath ())) {
40
- System .out .println ("Delete Class " +cp .getPath ()+" Succeed" );
41
- }else {
42
- System .out .println ("Delete Class " +cp .getPath ()+" Failed" );
43
- }
44
- break ;
45
- }
46
- }
87
+ if (!cp .getClassName ().contains ("#" )) {
88
+ checkWsConfig (cp ); //Check WebSocket Memory Shell
89
+ }else {
90
+ //Normal Memory Shell Checked
91
+ checkControllerPath (cp );
47
92
}
48
93
}
49
94
}
0 commit comments