1
+ import java .io .ObjectInputStream ;
1
2
import java .rmi .Naming ;
2
3
import java .rmi .Remote ;
3
4
import java .rmi .RemoteException ;
@@ -10,15 +11,47 @@ public class RmiUnsafeDeserialization {
10
11
public static void testRegistryBindWithObjectParameter () throws Exception {
11
12
Registry registry = LocateRegistry .createRegistry (1099 );
12
13
registry .bind ("test" , new RemoteObjectWithObject ());
14
+ registry .rebind ("test" , new RemoteObjectWithObject ());
15
+ }
16
+
17
+ // GOOD (bind a remote object that has methods that takes safe parameters)
18
+ public static void testRegistryBindWithIntParameter () throws Exception {
19
+ Registry registry = LocateRegistry .createRegistry (1099 );
20
+ registry .bind ("test" , new SafeRemoteObject ());
21
+ registry .rebind ("test" , new SafeRemoteObject ());
22
+ }
23
+
24
+ // BAD (bind a remote object that has a vulnerable method that takes Object)
25
+ public static void testNamingBindWithObjectParameter () throws Exception {
26
+ Naming .bind ("test" , new RemoteObjectWithObject ());
27
+ Naming .rebind ("test" , new RemoteObjectWithObject ());
28
+ }
29
+
30
+ // GOOD (bind a remote object that has methods that takes safe parameters)
31
+ public static void testNamingBindWithIntParameter () throws Exception {
32
+ Naming .bind ("test" , new SafeRemoteObject ());
33
+ Naming .rebind ("test" , new SafeRemoteObject ());
13
34
}
14
35
}
15
36
16
37
interface RemoteObjectWithObjectInterface extends Remote {
17
-
18
38
void take (Object obj ) throws RemoteException ;
19
39
}
20
40
21
41
class RemoteObjectWithObject implements RemoteObjectWithObjectInterface {
22
-
23
42
public void take (Object obj ) throws RemoteException {}
24
43
}
44
+
45
+ interface SafeRemoteObjectInterface extends Remote {
46
+ void take (int n ) throws RemoteException ;
47
+ void take (double n ) throws RemoteException ;
48
+ void take (String s ) throws RemoteException ;
49
+ void take (ObjectInputStream ois ) throws RemoteException ;
50
+ }
51
+
52
+ class SafeRemoteObject implements SafeRemoteObjectInterface {
53
+ public void take (int n ) throws RemoteException {}
54
+ public void take (double n ) throws RemoteException {}
55
+ public void take (String s ) throws RemoteException {}
56
+ public void take (ObjectInputStream ois ) throws RemoteException {}
57
+ }
0 commit comments