1
+ package unsafedeserialization ;
2
+
1
3
import java .io .*;
2
4
import java .net .Socket ;
3
5
import java .beans .XMLDecoder ;
6
+ import com .example .MyObjectInput ;
4
7
import com .thoughtworks .xstream .XStream ;
5
8
import com .esotericsoftware .kryo .Kryo ;
6
9
import com .esotericsoftware .kryo .io .Input ;
10
13
import org .nibblesec .tools .SerialKiller ;
11
14
12
15
public class A {
13
- public Object deserialize1 (Socket sock ) throws java .io .IOException , ClassNotFoundException {
16
+ public Object deserialize1a (Socket sock ) throws java .io .IOException , ClassNotFoundException {
14
17
InputStream inputStream = sock .getInputStream (); // $ Source
15
18
ObjectInputStream in = new ObjectInputStream (inputStream );
16
19
return in .readObject (); // $ Alert
17
20
}
18
21
19
- public Object deserialize2 (Socket sock ) throws java .io .IOException , ClassNotFoundException {
22
+ public Object deserialize2 () throws java .io .IOException , ClassNotFoundException {
23
+ ObjectInput objectInput = A .getTaintedObjectInput (); // $ Source
24
+ return objectInput .readObject (); // $ Alert
25
+ }
26
+
27
+ public Object deserialize3 () throws java .io .IOException , ClassNotFoundException {
28
+ MyObjectInput objectInput = A .getTaintedMyObjectInput (); // $ Source
29
+ return objectInput .readObject (); // $ Alert
30
+ }
31
+
32
+ public Object deserialize4 (Socket sock ) throws java .io .IOException , ClassNotFoundException {
20
33
InputStream inputStream = sock .getInputStream (); // $ Source
21
34
ObjectInputStream in = new ObjectInputStream (inputStream );
22
35
return in .readUnshared (); // $ Alert
@@ -28,20 +41,20 @@ public Object deserializeWithSerialKiller(Socket sock) throws java.io.IOExceptio
28
41
return in .readUnshared (); // OK
29
42
}
30
43
31
- public Object deserialize3 (Socket sock ) throws java .io .IOException {
44
+ public Object deserialize5 (Socket sock ) throws java .io .IOException {
32
45
InputStream inputStream = sock .getInputStream (); // $ Source
33
46
XMLDecoder d = new XMLDecoder (inputStream );
34
47
return d .readObject (); // $ Alert
35
48
}
36
49
37
- public Object deserialize4 (Socket sock ) throws java .io .IOException {
50
+ public Object deserialize6 (Socket sock ) throws java .io .IOException {
38
51
XStream xs = new XStream ();
39
52
InputStream inputStream = sock .getInputStream (); // $ Source
40
53
Reader reader = new InputStreamReader (inputStream );
41
54
return xs .fromXML (reader ); // $ Alert
42
55
}
43
56
44
- public void deserialize5 (Socket sock ) throws java .io .IOException {
57
+ public void deserialize7 (Socket sock ) throws java .io .IOException {
45
58
Kryo kryo = new Kryo ();
46
59
Input input = new Input (sock .getInputStream ()); // $ Source
47
60
A a1 = kryo .readObject (input , A .class ); // $ Alert
@@ -56,7 +69,7 @@ private Kryo getSafeKryo() throws java.io.IOException {
56
69
return kryo ;
57
70
}
58
71
59
- public void deserialize6 (Socket sock ) throws java .io .IOException {
72
+ public void deserialize8 (Socket sock ) throws java .io .IOException {
60
73
Kryo kryo = getSafeKryo ();
61
74
Input input = new Input (sock .getInputStream ());
62
75
Object o = kryo .readClassAndObject (input ); // OK
@@ -101,4 +114,8 @@ public void deserializeSnakeYaml4(Socket sock) throws java.io.IOException {
101
114
A o4 = yaml .loadAs (input , A .class ); // $ Alert
102
115
A o5 = yaml .loadAs (new InputStreamReader (input ), A .class ); // $ Alert
103
116
}
117
+
118
+ static ObjectInput getTaintedObjectInput () { return null ; }
119
+
120
+ static MyObjectInput getTaintedMyObjectInput () { return null ; }
104
121
}
0 commit comments