[
  {
    "path": ".github/ISSUE_TEMPLATE/bug_report.md",
    "content": "---\nname: Bug report\nabout: Create a report to help us improve\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Describe the bug**\nA clear and concise description of what the bug is.\n\n**To Reproduce**\nSteps to reproduce the behavior:\n1. Go to '...'\n2. Click on '....'\n3. Scroll down to '....'\n4. See error\n\n**Expected behavior**\nA clear and concise description of what you expected to happen.\n\n**Screenshots**\nIf applicable, add screenshots to help explain your problem.\n\n**Desktop (please complete the following information):**\n - OS: [e.g. iOS]\n - Browser [e.g. chrome, safari]\n - Version [e.g. 22]\n\n**Smartphone (please complete the following information):**\n - Device: [e.g. iPhone6]\n - OS: [e.g. iOS8.1]\n - Browser [e.g. stock browser, safari]\n - Version [e.g. 22]\n\n**Additional context**\nAdd any other context about the problem here.\n"
  },
  {
    "path": ".gitignore",
    "content": "/.idea/\n/libs/\n/out/\n/target/\n*.iml\n.DS_Store\ndependency-reduced-pom.xml"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "content": "# Contributor Covenant Code of Conduct\n\n## Our Pledge\n\nWe as members, contributors, and leaders pledge to make participation in our\ncommunity a harassment-free experience for everyone, regardless of age, body\nsize, visible or invisible disability, ethnicity, sex characteristics, gender\nidentity and expression, level of experience, education, socio-economic status,\nnationality, personal appearance, race, religion, or sexual identity\nand orientation.\n\nWe pledge to act and interact in ways that contribute to an open, welcoming,\ndiverse, inclusive, and healthy community.\n\n## Our Standards\n\nExamples of behavior that contributes to a positive environment for our\ncommunity include:\n\n* Demonstrating empathy and kindness toward other people\n* Being respectful of differing opinions, viewpoints, and experiences\n* Giving and gracefully accepting constructive feedback\n* Accepting responsibility and apologizing to those affected by our mistakes,\n  and learning from the experience\n* Focusing on what is best not just for us as individuals, but for the\n  overall community\n\nExamples of unacceptable behavior include:\n\n* The use of sexualized language or imagery, and sexual attention or\n  advances of any kind\n* Trolling, insulting or derogatory comments, and personal or political attacks\n* Public or private harassment\n* Publishing others' private information, such as a physical or email\n  address, without their explicit permission\n* Other conduct which could reasonably be considered inappropriate in a\n  professional setting\n\n## Enforcement Responsibilities\n\nCommunity leaders are responsible for clarifying and enforcing our standards of\nacceptable behavior and will take appropriate and fair corrective action in\nresponse to any behavior that they deem inappropriate, threatening, offensive,\nor harmful.\n\nCommunity leaders have the right and responsibility to remove, edit, or reject\ncomments, commits, code, wiki edits, issues, and other contributions that are\nnot aligned to this Code of Conduct, and will communicate reasons for moderation\ndecisions when appropriate.\n\n## Scope\n\nThis Code of Conduct applies within all community spaces, and also applies when\nan individual is officially representing the community in public spaces.\nExamples of representing our community include using an official e-mail address,\nposting via an official social media account, or acting as an appointed\nrepresentative at an online or offline event.\n\n## Enforcement\n\nInstances of abusive, harassing, or otherwise unacceptable behavior may be\nreported to the community leaders responsible for enforcement at\nr00t4dm@gmail.com.\nAll complaints will be reviewed and investigated promptly and fairly.\n\nAll community leaders are obligated to respect the privacy and security of the\nreporter of any incident.\n\n## Enforcement Guidelines\n\nCommunity leaders will follow these Community Impact Guidelines in determining\nthe consequences for any action they deem in violation of this Code of Conduct:\n\n### 1. Correction\n\n**Community Impact**: Use of inappropriate language or other behavior deemed\nunprofessional or unwelcome in the community.\n\n**Consequence**: A private, written warning from community leaders, providing\nclarity around the nature of the violation and an explanation of why the\nbehavior was inappropriate. A public apology may be requested.\n\n### 2. Warning\n\n**Community Impact**: A violation through a single incident or series\nof actions.\n\n**Consequence**: A warning with consequences for continued behavior. No\ninteraction with the people involved, including unsolicited interaction with\nthose enforcing the Code of Conduct, for a specified period of time. This\nincludes avoiding interactions in community spaces as well as external channels\nlike social media. Violating these terms may lead to a temporary or\npermanent ban.\n\n### 3. Temporary Ban\n\n**Community Impact**: A serious violation of community standards, including\nsustained inappropriate behavior.\n\n**Consequence**: A temporary ban from any sort of interaction or public\ncommunication with the community for a specified period of time. No public or\nprivate interaction with the people involved, including unsolicited interaction\nwith those enforcing the Code of Conduct, is allowed during this period.\nViolating these terms may lead to a permanent ban.\n\n### 4. Permanent Ban\n\n**Community Impact**: Demonstrating a pattern of violation of community\nstandards, including sustained inappropriate behavior,  harassment of an\nindividual, or aggression toward or disparagement of classes of individuals.\n\n**Consequence**: A permanent ban from any sort of public interaction within\nthe community.\n\n## Attribution\n\nThis Code of Conduct is adapted from the [Contributor Covenant][homepage],\nversion 2.0, available at\nhttps://www.contributor-covenant.org/version/2/0/code_of_conduct.html.\n\nCommunity Impact Guidelines were inspired by [Mozilla's code of conduct\nenforcement ladder](https://github.com/mozilla/diversity).\n\n[homepage]: https://www.contributor-covenant.org\n\nFor answers to common questions about this code of conduct, see the FAQ at\nhttps://www.contributor-covenant.org/faq. Translations are available at\nhttps://www.contributor-covenant.org/translations.\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2020 r00t4dm\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# aLIEz\n\nEnglish\n\nUse reflection to dynamically load JDK dependencies, and do not directly use transformers to modify bytecode. Now it is directly dumped and researchers are required to analyze it themselves.\n\nKill the memory of various JavaEE containers and middleware\n\nUsage: java -jar aLIEz.jar JVMID aLIEz-agent-1.0-SNAPSHOT.jar\n\nUsage\n````\n➜ java -jar aLIEz.jar\nusage: java -jar clearMemShell.jar <JVMID> \"AgentLocate\"\n32866: org.jetbrains.idea.maven.server.RemoteMavenServer36\n43237: org.jetbrains.jps.cmdline.Launcher /Applications/IntelliJ IDEA.app/Contents/lib/netty-common-4.1.52.Final.jar:/Applications/IntelliJ IDEA.app/Contents/lib/netty-resolver-4.1.52.Final.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/java/lib/javac2.jar:/Applications/IntelliJ IDEA.app/Contents/lib/httpclient-4.5.12.jar:/Applications/IntelliJ IDEA.app/Contents/lib/plexus-component-annotations-1.7.1.jar:/Applications/IntelliJ IDEA.app/Contents/lib/maven-resolver-spi-1.3.3.jar:/Applications/IntelliJ IDEA.app/Contents/lib/util.jar:/Applications/IntelliJ IDEA.app/Contents/lib/platform-api.jar:/Applications/IntelliJ IDEA.app/Contents/lib/qdox-2.0-M10.jar:/Applications/IntelliJ IDEA.app/Contents/lib/asm-all-9.0.jar:/Applications/IntelliJ IDEA.app/Contents/lib/commons-lang3-3.10.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jna.jar:/Applications/IntelliJ IDEA.app/Contents/lib/trove4j.jar:/Applications/IntelliJ IDEA.app/Contents/lib/nanoxml-2.2.3.jar:/Applications/IntelliJ IDEA.app/Contents/lib/maven-resolver-api\n45253: org.jetbrains.idea.maven.server.RemoteMavenServer36\n69401: org.jetbrains.idea.maven.server.RemoteMavenServer36\n51529: Behinder_v3.0_Beta6_mac.jar\n56185: org.apache.catalina.startup.Bootstrap start\n57449: aLIEz.jar\n37197:\n64783: org.jetbrains.idea.maven.server.RemoteMavenServer36\n56879: Godzilla-V2.96.jar\n\n15:18:23 in out/artifacts/aLIEz_jar\n➜ java -jar aLIEz.jar 56185 \"/Users/r00t4dm/Downloads/JavaAgent_CleanMemShell/target/aLIEz-agent-1.0-SNAPSHOT.jar\"\n[+]OK.i find a jvm.org.apache.catalina.startup.Bootstrap start\n[+]agent is injected.\n````\n\n中文版本\n\n采用反射动态加载JDK依赖，不会直接transformer去改bytecode 现在是直接dump出来依赖研究人员自己分析\n\n杀各个JavaEE容器、中间件的内存马\n\n使用方法：java -jar aLIEz.jar JVMID aLIEz-agent-1.0-SNAPSHOT.jar\n\n![img.png](img.png)\n\n\n使用方法\n````\n➜ java -jar aLIEz.jar\nusage: java -jar clearMemShell.jar <JVMID> \"AgentLocate\"\n32866: org.jetbrains.idea.maven.server.RemoteMavenServer36\n43237: org.jetbrains.jps.cmdline.Launcher /Applications/IntelliJ IDEA.app/Contents/lib/netty-common-4.1.52.Final.jar:/Applications/IntelliJ IDEA.app/Contents/lib/netty-resolver-4.1.52.Final.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/java/lib/javac2.jar:/Applications/IntelliJ IDEA.app/Contents/lib/httpclient-4.5.12.jar:/Applications/IntelliJ IDEA.app/Contents/lib/plexus-component-annotations-1.7.1.jar:/Applications/IntelliJ IDEA.app/Contents/lib/maven-resolver-spi-1.3.3.jar:/Applications/IntelliJ IDEA.app/Contents/lib/util.jar:/Applications/IntelliJ IDEA.app/Contents/lib/platform-api.jar:/Applications/IntelliJ IDEA.app/Contents/lib/qdox-2.0-M10.jar:/Applications/IntelliJ IDEA.app/Contents/lib/asm-all-9.0.jar:/Applications/IntelliJ IDEA.app/Contents/lib/commons-lang3-3.10.jar:/Applications/IntelliJ IDEA.app/Contents/lib/jna.jar:/Applications/IntelliJ IDEA.app/Contents/lib/trove4j.jar:/Applications/IntelliJ IDEA.app/Contents/lib/nanoxml-2.2.3.jar:/Applications/IntelliJ IDEA.app/Contents/lib/maven-resolver-api\n45253: org.jetbrains.idea.maven.server.RemoteMavenServer36\n69401: org.jetbrains.idea.maven.server.RemoteMavenServer36\n51529: Behinder_v3.0_Beta6_mac.jar\n56185: org.apache.catalina.startup.Bootstrap start\n57449: aLIEz.jar\n37197:\n64783: org.jetbrains.idea.maven.server.RemoteMavenServer36\n56879: Godzilla-V2.96.jar\n\n15:18:23 in out/artifacts/aLIEz_jar\n➜ java -jar aLIEz.jar 56185 \"/Users/r00t4dm/Downloads/JavaAgent_CleanMemShell/target/aLIEz-agent-1.0-SNAPSHOT.jar\"\n[+]OK.i find a jvm.org.apache.catalina.startup.Bootstrap start\n[+]agent is injected.\n"
  },
  {
    "path": "SECURITY.md",
    "content": "# Security Policy\n\n## Supported Versions\n\nUse this section to tell people about which versions of your project are\ncurrently being supported with security updates.\n\n| Version | Supported          |\n| ------- | ------------------ |\n| 5.1.x   | :white_check_mark: |\n| 5.0.x   | :x:                |\n| 4.0.x   | :white_check_mark: |\n| < 4.0   | :x:                |\n\n## Reporting a Vulnerability\n\nUse this section to tell people how to report a vulnerability.\n\nTell them where to go, how often they can expect to get an update on a\nreported vulnerability, what to expect if the vulnerability is accepted or\ndeclined, etc.\n"
  },
  {
    "path": "pom.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n    <modelVersion>4.0.0</modelVersion>\n\n    <groupId>org.example</groupId>\n    <artifactId>aLIEz-agent</artifactId>\n    <version>1.0-SNAPSHOT</version>\n\n    <properties>\n        <maven.compiler.source>8</maven.compiler.source>\n        <maven.compiler.target>8</maven.compiler.target>\n    </properties>\n\n<dependencies>\n\n    <dependency>\n        <groupId>com.sun</groupId>\n        <artifactId>tools</artifactId>\n        <version>1.8.0</version>\n        <scope>system</scope>\n        <systemPath>/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home/lib/tools.jar</systemPath>\n<!--        <systemPath>/Users/r00t4dm/Downloads/JavaAgent_CleanMemShell/tools.jar</systemPath>-->\n    </dependency>\n\n    <dependency>\n        <groupId>org.javassist</groupId>\n        <artifactId>javassist</artifactId>\n        <version>3.20.0-GA</version>\n    </dependency>\n\n\n\n</dependencies>\n\n    <build>\n        <plugins>\n            <plugin>\n                <groupId>org.apache.maven.plugins</groupId>\n                <artifactId>maven-compiler-plugin</artifactId>\n                <version>3.6.2</version>\n                <configuration>\n                    <source>1.8</source>\n                    <target>1.8</target>\n                    <encoding>utf-8</encoding>\n                </configuration>\n            </plugin>\n            <plugin>\n                <groupId>org.apache.maven.plugins</groupId>\n                <artifactId>maven-shade-plugin</artifactId>\n                <version>3.2.4</version>\n                <executions>\n                    <execution>\n                        <phase>package</phase>\n                        <goals>\n                            <goal>shade</goal>\n                        </goals>\n                        <configuration>\n                            <transformers>\n                                <transformer implementation=\"org.apache.maven.plugins.shade.resource.ManifestResourceTransformer\">\n                                    <manifestEntries>\n                                        <Agent-Class>com.r00t4dm.CleanMemShellAgentmain</Agent-Class>\n                                        <Can-Retransform-Classes>true</Can-Retransform-Classes>\n<!--                                        <Premain-Class>com.r00t4dm.MyPremain</Premain-Class>-->\n                                    </manifestEntries>\n                                </transformer>\n                            </transformers>\n                        </configuration>\n                    </execution>\n                </executions>\n            </plugin>\n        </plugins>\n    </build>\n</project>"
  },
  {
    "path": "src/META-INF/MANIFEST.MF",
    "content": "Manifest-Version: 1.0\r\nMain-Class: com.r00t4dm.CleanMemShellAgentMainAttach\r\n\r\n"
  },
  {
    "path": "src/main/java/META-INF/MANIFEST.MF",
    "content": "Manifest-Version: 1.0\r\nMain-Class: com.r00t4dm.CleanMemShellAgentMainAttach\r\n\r\n"
  },
  {
    "path": "src/main/java/com/r00t4dm/CleanMemShellAgentMainAttach.java",
    "content": "package com.r00t4dm;\n\nimport com.sun.tools.attach.*;\n\nimport java.io.File;\nimport java.io.IOException;\nimport java.lang.reflect.InvocationTargetException;\nimport java.lang.reflect.Method;\nimport java.net.MalformedURLException;\nimport java.net.URL;\nimport java.net.URLClassLoader;\nimport java.util.List;\n\npublic class CleanMemShellAgentMainAttach {\n    private static final String TOOLS_CLASS_NAME = \"com.sun.tools.attach.VirtualMachine\";\n    private static final String VMD_CLASS_NAME = \"com.sun.tools.attach.VirtualMachineDescriptor\";\n\n    public static void main(String[] args) throws ClassNotFoundException, InvocationTargetException,\n            NoSuchMethodException, IllegalAccessException, MalformedURLException {\n        if (args.length == 0) {\n            System.err.println(\"usage: java -jar aLIEz.jar <JVMID> \\\"Agent-Locate\\\"\");\n            listTargetVMs();\n        } else {\n            String vmdId = args[0];\n            String agentLocate = args[1];\n            attachToTargetVM(vmdId, agentLocate);\n\n        }\n    }\n    private static void attachToTargetVM(String vmdId, String agentLocate) throws ClassNotFoundException,\n            NoSuchMethodException, InvocationTargetException, IllegalAccessException, MalformedURLException {\n\n        File jarFile = new File(System.getProperty(\"java.home\"));\n        System.out.println(\"java.home : \" +System.getProperty(\"java.home\"));\n        File toolsJar  = new File(jarFile.getParentFile() + \"/lib/\", \"tools.jar\");\n        System.out.println(\"tools.jar path: \" + toolsJar.getAbsolutePath());\n\n\n        URL[] urls = new URL[] {toolsJar.toURI().toURL()};\n        Class<?> vmClass = new URLClassLoader(urls).loadClass(TOOLS_CLASS_NAME);\n        Method attachMethod = vmClass.getDeclaredMethod(\"attach\", String.class);\n        Object vmInstance = attachMethod.invoke(null, vmdId);\n        Method loadAgentMethod = vmClass.getDeclaredMethod(\"loadAgent\", String.class);\n        loadAgentMethod.invoke(vmInstance, agentLocate);\n        System.out.println(\"[+]agent is injected.\");\n\n        Method detachMethod = vmClass.getDeclaredMethod(\"detach\");\n        detachMethod.invoke(vmInstance);\n    }\n\n    private static void listTargetVMs() throws ClassNotFoundException, NoSuchMethodException,\n            InvocationTargetException, IllegalAccessException, MalformedURLException {\n\n\n        File jarFile = new File(System.getProperty(\"java.home\"));\n        File toolsJar  = new File(jarFile.getParentFile() + \"/lib/\", \"tools.jar\");\n\n        System.out.println(\"java.home: \" + System.getProperty(\"java.home\"));\n        System.out.println(\"tools.jar path: \" + toolsJar.getAbsolutePath());\n        URL[] urls = new URL[] {toolsJar.toURI().toURL()};\n        Class<?> vmClass = new URLClassLoader(urls).loadClass(TOOLS_CLASS_NAME);\n        Method listMethod = vmClass.getDeclaredMethod(\"list\");\n        List<?> vms = (List<?>) listMethod.invoke(null);\n        for (Object vmObject : vms) {\n            Class<?> vmdClass = vmObject.getClass();\n            Method idMethod = vmdClass.getMethod(\"id\");\n            Method displayNameMethod = vmdClass.getMethod(\"displayName\");\n            String id = (String) idMethod.invoke(vmObject);\n            String displayName = (String) displayNameMethod.invoke(vmObject);\n            System.out.println(id + \" : \" + displayName);\n        }\n    }\n\n}\n"
  },
  {
    "path": "src/main/java/com/r00t4dm/CleanMemShellAgentmain.java",
    "content": "package com.r00t4dm;\n\nimport java.io.File;\nimport java.io.FileNotFoundException;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.lang.instrument.Instrumentation;\nimport java.lang.instrument.UnmodifiableClassException;\nimport java.lang.management.ManagementFactory;\nimport java.util.HashSet;\nimport java.util.Set;\n\npublic class CleanMemShellAgentmain {\n\n    private static final Set<Class> setClasses = new HashSet<>();\n\n    public static String getCurrentPID() {\n        try {\n            String name = ManagementFactory.getRuntimeMXBean().getName();\n            return name.split(\"@\")[0];\n        } catch (Exception e) {\n            return \"\";\n        }\n    }\n\n    /**\n     * @param agentOps 类名\n     * @param inst\n     * @throws UnmodifiableClassException\n     */\n    public static void agentmain(String agentOps, Instrumentation inst)\n            throws UnmodifiableClassException, ClassNotFoundException, IOException {\n\n        for (Class clazz : inst.getAllLoadedClasses()) {\n            Class[] classes = clazz.getInterfaces();\n            for (int i = 0; i < classes.length; i++) {\n                if (classes[i].getName().equalsIgnoreCase(\"javax.servlet.Servlet\") ||\n                classes[i].getName().equalsIgnoreCase(\"javax.servlet.Filter\") ||\n                classes[i].getName().equalsIgnoreCase(\"javax.servlet.ServletRequestListener\")) {\n                    System.out.println(\"符合条件的类 ：\" + clazz.getName());\n                    setClasses.add(clazz);\n                }\n            }\n\n            try {\n                if (clazz.getSuperclass().getName().contains(\"AbstractTranslet\")) {\n                    System.out.println(\"符合条件的类 ：\" + clazz.getName());\n                    setClasses.add(clazz);\n                }\n            }\n            catch (NullPointerException nullPointerException) {\n                // not print\n            }\n        }\n\n        inst.addTransformer(new CleanMemShellTransformer(inst), true);\n        inst.retransformClasses(setClasses.toArray(new Class[setClasses.size()]));\n\n    }\n\n\n}\n"
  },
  {
    "path": "src/main/java/com/r00t4dm/CleanMemShellTransformer.java",
    "content": "package com.r00t4dm;\n\nimport javassist.*;\nimport java.io.*;\nimport java.lang.instrument.ClassFileTransformer;\nimport java.lang.instrument.Instrumentation;\nimport java.security.ProtectionDomain;\n\npublic class CleanMemShellTransformer implements ClassFileTransformer {\n\n    private static final String CLASSNAME = \"javax.servlet.Servlet\";\n    private static final String FILTERNAME = \"javax.servlet.Filter\";\n    private static final String LISTENERNAME = \"javax.servlet.ServletRequestListener\";\n    private static final String TEMPLATENAME = \"com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet\";\n\n    private final Instrumentation inst;\n\n    public CleanMemShellTransformer(Instrumentation inst) {\n        this.inst = inst;\n    }\n\n    @Override\n    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,\n                            ProtectionDomain protectionDomain, byte[] classfileBuffer)  {\n        try {\n            if (isMemshell(loader, classBeingRedefined, classfileBuffer)) {\n                return dumpClasses(classBeingRedefined, classfileBuffer);\n            }\n        } catch (NotFoundException | IOException | ClassNotFoundException | NoSuchMethodException e) {\n            System.out.println(\"dump MemShell Error : \" + e.getMessage());\n        } catch (Exception e) {\n            e.printStackTrace();\n        }\n        // 不是内存马不修改字节码并返回\n        return classfileBuffer;\n    }\n\n    /**\n     * dump bytecode to class file.\n     * @param classBeingRedefined\n     * @param classfileBuffer\n     * @return\n     */\n    private byte[] dumpClasses(Class<?> classBeingRedefined, byte[] classfileBuffer) throws IOException {\n        String className = classBeingRedefined.getName();\n        File file = new File(\"/tmp/memshell/\"+className);\n\n        file.mkdirs();\n        File newFile = new File(file, classBeingRedefined.getSimpleName() + \".class\");\n        FileOutputStream fos = new FileOutputStream(newFile);\n        fos.write(classfileBuffer);\n        fos.flush();\n        fos.close();\n        return classfileBuffer;\n    }\n\n    /**\n     * 根据特征判断是否是内存马\n     * @param loader\n     * @param aClass\n     * @param bytes\n     * @return true代表是内存马，false代表不是\n     */\n    private static boolean isMemshell(ClassLoader loader, Class aClass, byte[] bytes) throws NotFoundException,\n            ClassNotFoundException, IOException, NoSuchMethodException {\n\n\n        Class servletClass = loader.loadClass(CLASSNAME);\n        Class filterClass = loader.loadClass(FILTERNAME);\n        Class listenerClass = loader.loadClass(LISTENERNAME);\n        Class templateClass = loader.loadClass(TEMPLATENAME);\n\n\n        if (templateClass.isAssignableFrom(aClass)) {\n            return true;\n        }\n\n        if (servletClass.isAssignableFrom(aClass) ||\n                filterClass.isAssignableFrom(aClass) ||\n                listenerClass.isAssignableFrom(aClass)) {\n\n\n            return true;\n\n        }\n\n        return false;\n    }\n\n    /**\n     *\n     * @param MemShell 内存马\n     * @param byteMemShell 内存马的字节码\n     * @return 清理后的字节码\n     * @throws NotFoundException\n     * @throws CannotCompileException\n     * @throws IOException\n     */\n    private static byte[] killMemShell (Class MemShell, byte[] byteMemShell)\n            throws IOException {\n        String className = MemShell.getName();\n        File file = new File(\"/tmp/\"+className);\n\n        file.mkdirs();\n        File newFile = new File(file, MemShell.getSimpleName() + \".class\");\n        FileOutputStream fos = new FileOutputStream(newFile);\n        fos.write(byteMemShell);\n        fos.flush();\n        fos.close();\n        return byteMemShell;\n\n    }\n\n\n}\n"
  }
]