Skip to content

Commit 2fa37e0

Browse files
author
threedr3am
committed
feat:增加dubbo-hessian2安全加固demo & 优化jackson
1 parent 215942c commit 2fa37e0

File tree

29 files changed

+889
-26
lines changed

29 files changed

+889
-26
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ package:com.threedr3am.bug.jackson
1313
3. com.threedr3am.bug.dubbo.XBeanPoc 利用条件:存在org.apache.xbean:xbean-naming依赖
1414
4. com.threedr3am.bug.dubbo.SpringAbstractBeanFactoryPointcutAdvisorPoc 利用条件:存在org.springframework:spring-aop依赖
1515

16+
### dubbo/dubbo-hessian2-safe-reinforcement
17+
dubbo hessian2安全加固demo,使用黑名单方式禁止部分gadget
18+
1619
### padding-oracle-cbc
1720
1. com.threedr3am.bug.paddingoraclecbc.PaddingOracle ```padding oracle java实现(多组密文实现)```
1821
2. com.threedr3am.bug.paddingoraclecbc.PaddingOracleCBC ```padding oracle cbc java实现(单组 <= 16bytes 密文实现)```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<artifactId>dubbo-hessian2-safe-reinforcement</artifactId>
8+
<groupId>com.threedr3am</groupId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>learn-dubbo-client-boot</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>learn-dubbo-client-boot</name>
15+
<description>Demo project for Spring Boot</description>
16+
17+
<properties>
18+
<java.version>1.8</java.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.threedr3am</groupId>
24+
<artifactId>learn-dubbo-server-boot</artifactId>
25+
<version>0.0.1-SNAPSHOT</version>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-maven-plugin</artifactId>
34+
</plugin>
35+
</plugins>
36+
</build>
37+
38+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.threedr3am.learn.client.boot;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class LearnDubboClientBootApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(LearnDubboClientBootApplication.class, args);
11+
}
12+
13+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.threedr3am.learn.client.boot;
2+
3+
import com.threedr3am.learn.server.boot.A;
4+
import com.threedr3am.learn.server.boot.DemoService;
5+
import java.sql.SQLException;
6+
import javax.annotation.PostConstruct;
7+
import org.apache.dubbo.config.annotation.Reference;
8+
import org.springframework.stereotype.Service;
9+
10+
/**
11+
* @author xuanyh
12+
*/
13+
@Service
14+
public class Test {
15+
16+
@Reference(version = "1.0")
17+
private DemoService demoService;
18+
19+
@PostConstruct
20+
private void init() throws SQLException {
21+
A a = new A();
22+
a.setName("xuanyh");
23+
new Thread(() -> {
24+
while (true) {
25+
System.out.println(demoService.hello(a));
26+
try {
27+
Thread.currentThread().sleep(5000);
28+
} catch (InterruptedException e) {
29+
e.printStackTrace();
30+
}
31+
}
32+
}).start();
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.threedr3am.learn.serialize;
2+
3+
import com.alibaba.com.caucho.hessian.io.Hessian2Input;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.lang.reflect.Field;
7+
import java.util.List;
8+
9+
/**
10+
* @author xuanyh
11+
*/
12+
public class MyHessian2Input extends Hessian2Input {
13+
14+
/**
15+
* Creates a new Hessian input stream, initialized with an underlying input stream.
16+
*
17+
* @param is the underlying input stream.
18+
*/
19+
public MyHessian2Input(InputStream is) {
20+
super(is);
21+
}
22+
23+
@Override
24+
public Object readObject(Class cl) throws IOException {
25+
return super.readObject(cl);
26+
}
27+
28+
@Override
29+
public Object readObject(Class expectedClass, Class<?>... expectedTypes) throws IOException {
30+
return super.readObject(expectedClass, expectedTypes);
31+
}
32+
33+
@Override
34+
public Object readObject() throws IOException {
35+
return super.readObject();
36+
}
37+
38+
@Override
39+
public Object readObject(List<Class<?>> expectedTypes) throws IOException {
40+
return super.readObject(expectedTypes);
41+
}
42+
43+
void checkClassDef() {
44+
if (_classDefs.isEmpty())
45+
return;
46+
for (Object c : _classDefs) {
47+
Field[] fields = c.getClass().getDeclaredFields();
48+
System.out.println();
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.threedr3am.learn.serialize;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.lang.reflect.Type;
22+
import org.apache.dubbo.common.serialize.ObjectInput;
23+
import org.apache.dubbo.common.serialize.hessian2.Hessian2SerializerFactory;
24+
25+
/**
26+
* Hessian2 object input implementation
27+
*/
28+
public class MyHessian2ObjectInput implements ObjectInput {
29+
private final MyHessian2Input mH2i;
30+
31+
public MyHessian2ObjectInput(InputStream is) {
32+
mH2i = new MyHessian2Input(is);
33+
mH2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
34+
}
35+
36+
@Override
37+
public boolean readBool() throws IOException {
38+
return mH2i.readBoolean();
39+
}
40+
41+
@Override
42+
public byte readByte() throws IOException {
43+
return (byte) mH2i.readInt();
44+
}
45+
46+
@Override
47+
public short readShort() throws IOException {
48+
return (short) mH2i.readInt();
49+
}
50+
51+
@Override
52+
public int readInt() throws IOException {
53+
return mH2i.readInt();
54+
}
55+
56+
@Override
57+
public long readLong() throws IOException {
58+
return mH2i.readLong();
59+
}
60+
61+
@Override
62+
public float readFloat() throws IOException {
63+
return (float) mH2i.readDouble();
64+
}
65+
66+
@Override
67+
public double readDouble() throws IOException {
68+
return mH2i.readDouble();
69+
}
70+
71+
@Override
72+
public byte[] readBytes() throws IOException {
73+
return mH2i.readBytes();
74+
}
75+
76+
@Override
77+
public String readUTF() throws IOException {
78+
return mH2i.readString();
79+
}
80+
81+
@Override
82+
public Object readObject() throws IOException {
83+
return mH2i.readObject();
84+
}
85+
86+
@Override
87+
@SuppressWarnings("unchecked")
88+
public <T> T readObject(Class<T> cls) throws IOException,
89+
ClassNotFoundException {
90+
return (T) mH2i.readObject(cls);
91+
}
92+
93+
@Override
94+
public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
95+
return readObject(cls);
96+
}
97+
98+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.threedr3am.learn.serialize;
18+
19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.io.OutputStream;
22+
import org.apache.dubbo.common.URL;
23+
import org.apache.dubbo.common.serialize.ObjectInput;
24+
import org.apache.dubbo.common.serialize.ObjectOutput;
25+
import org.apache.dubbo.common.serialize.Serialization;
26+
import org.apache.dubbo.common.serialize.hessian2.Hessian2ObjectOutput;
27+
28+
/**
29+
* Hessian2 serialization implementation, hessian2 is the default serialization protocol for dubbo
30+
*
31+
* <pre>
32+
* e.g. &lt;dubbo:protocol serialization="hessian2" /&gt;
33+
* </pre>
34+
*/
35+
public class MyHessian2Serialization implements Serialization {
36+
37+
@Override
38+
public byte getContentTypeId() {
39+
return 22;
40+
}
41+
42+
@Override
43+
public String getContentType() {
44+
return "x-application/hessian2";
45+
}
46+
47+
@Override
48+
public ObjectOutput serialize(URL url, OutputStream out) throws IOException {
49+
return new Hessian2ObjectOutput(out);
50+
}
51+
52+
@Override
53+
public ObjectInput deserialize(URL url, InputStream is) throws IOException {
54+
return new MyHessian2ObjectInput(is);
55+
}
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MyHessian2=com.threedr3am.learn.serialize.MyHessian2Serialization
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
spring.application.name=dubbo-consumer
2+
server.port=9990
3+
spring.main.allow-bean-definition-overriding=true
4+
5+
# Dubbo Application
6+
# The default value of dubbo.application.name is ${spring.application.name}
7+
# dubbo.application.name=${spring.application.name}
8+
9+
# 扫描dubbo服务(@Service.. @Reference..)
10+
dubbo.scan.basePackages=com.threedr3am.learn.client.boot
11+
12+
# 注册中心
13+
dubbo.registry.id=dubboRegistry
14+
dubbo.registry.timeout=5000
15+
dubbo.registry.address=zookeeper://127.0.0.1:2181
16+
dubbo.registry.client=curator
17+
# 元数据地址
18+
dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
19+
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.threedr3am.learn.client.boot;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
//@RunWith(SpringRunner.class)
9+
//@SpringBootTest
10+
public class LearnDubboClientBootApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)