Skip to content

Commit efa4b4f

Browse files
Cover Registry in RmiUnsafeDeserialization.ql
1 parent 8b96ff9 commit efa4b4f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

java/ql/src/experimental/Security/CWE/CWE-502/RmiUnsafeDeserialization.ql

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
* @name Unsafe deserialization with RMI.
3-
* @description TBD
3+
* @description Java RMI uses native Java serialization mechanism.
4+
* If a registered remote object has a method that takes a complex object,
5+
* an attacker can take advantage of unsafe Java deserialization mechanism.
6+
* In the worst case, it results in remote code execution.
47
* @kind problem
58
* @problem.severity error
69
* @precision high
@@ -16,13 +19,22 @@ private class ObjectInputStream extends RefType {
1619
ObjectInputStream() { hasQualifiedName("java.io", "ObjectInputStream") }
1720
}
1821

22+
/**
23+
* A method that binds a name to a remote object.
24+
*/
1925
private class BindMethod extends Method {
2026
BindMethod() {
21-
getDeclaringType().hasQualifiedName("java.rmi", "Naming") and
27+
(
28+
getDeclaringType().hasQualifiedName("java.rmi", "Naming") or
29+
getDeclaringType().hasQualifiedName("java.rmi.registry", "Registry")
30+
) and
2231
hasName(["bind", "rebind"])
2332
}
2433
}
2534

35+
/**
36+
* Looks for a vulnerable method in a `Remote` object.
37+
*/
2638
private Method getVulnerableMethod(Type type) {
2739
type.(RefType).getASupertype*() instanceof TypeRemote and
2840
exists(Method m, Type parameterType |
@@ -35,6 +47,9 @@ private Method getVulnerableMethod(Type type) {
3547
)
3648
}
3749

50+
/**
51+
* A method call that registers a remote object that has a vulnerable method.
52+
*/
3853
private class UnsafeRmiBinding extends MethodAccess {
3954
Method vulnerableMethod;
4055

@@ -46,7 +61,5 @@ private class UnsafeRmiBinding extends MethodAccess {
4661
Method getVulnerableMethod() { result = vulnerableMethod }
4762
}
4863

49-
// TODO: Cover Registry.bind() and rebind() -- test these sinks first
50-
5164
from UnsafeRmiBinding call
5265
select call, "Unsafe deserialization with RMI in '" + call.getVulnerableMethod() + "' method"

0 commit comments

Comments
 (0)