15
15
import java
16
16
import semmle.code.java.dataflow.DataFlow
17
17
import semmle.code.java.dataflow.TaintTracking
18
+
19
+ ControlFlowNode getControlFlowNodeSuccessor ( ControlFlowNode node )
20
+ {
21
+ result = node .getASuccessor ( )
22
+ }
18
23
19
- predicate doesPackageContextLeadToInvokeMethod (
20
- DataFlow:: Node sinkPackageContext , MethodAccess maInvoke
21
-
22
- )
24
+ MethodAccess getClassLoaderReachableMethodAccess ( DataFlow:: Node node )
23
25
{
24
26
exists (
25
- MethodAccess maGetClassLoader ,
26
- MethodAccess maLoadClass ,
27
- MethodAccess maGetMethod |
27
+ MethodAccess maGetClassLoader , ControlFlowNode cfnGetClassLoader , ControlFlowNode cfnSuccessor |
28
28
maGetClassLoader .getCallee ( ) .getName ( ) = "getClassLoader" and
29
- maGetClassLoader .getQualifier ( ) = sinkPackageContext .asExpr ( ) and
30
- maLoadClass .getCallee ( ) .getName ( ) = "loadClass" and
31
- maLoadClass .getQualifier ( ) = maGetClassLoader and
32
- // check for arbitray code execution
33
- maGetMethod .getCallee ( ) .getName ( ) = "getMethod" and
34
- maGetMethod .getQualifier ( ) = maLoadClass and
35
- maInvoke .getCallee ( ) .getName ( ) = "invoke" and
36
- maInvoke .getQualifier ( ) = maGetMethod
29
+ maGetClassLoader .getQualifier ( ) = node .asExpr ( ) and
30
+ maGetClassLoader .getControlFlowNode ( ) = cfnGetClassLoader and
31
+ //cfnGetClassLoader.getASuccessor+() = cfnSuccessor and
32
+ getControlFlowNodeSuccessor + ( cfnGetClassLoader ) = cfnSuccessor and
33
+ cfnSuccessor instanceof MethodAccess and
34
+ result = cfnSuccessor .( MethodAccess )
37
35
)
38
36
}
39
37
38
+ MethodAccess getDangerousReachableMethodAccess ( MethodAccess ma )
39
+ {
40
+ ( ma .getCallee ( ) .hasName ( "getMethod" ) or
41
+ ma .getCallee ( ) .hasName ( "getDeclaredMethod" ) ) and
42
+ ( (
43
+ exists ( MethodAccess maInvoke |
44
+ //ma.getControlFlowNode().getASuccessor*() = maInvoke and
45
+ getControlFlowNodeSuccessor + ( ma .getControlFlowNode ( ) ) = maInvoke and
46
+ maInvoke .getCallee ( ) .hasName ( "invoke" ) and
47
+ result = maInvoke
48
+ )
49
+ ) or
50
+ (
51
+ exists ( AssignExpr ae , VarAccess va1 , VarAccess va2 , MethodAccess maInvoke |
52
+ ae .getSource ( ) = ma and
53
+ ae .getDest ( ) = va1 and
54
+ maInvoke .getQualifier ( ) = va2 and
55
+ va1 .getVariable ( ) = va2 .getVariable ( ) and
56
+ result = maInvoke
57
+ )
58
+ ) )
59
+ }
60
+
40
61
predicate isSignaturesChecked ( MethodAccess maCreatePackageContext )
41
62
{
42
63
exists (
@@ -49,22 +70,26 @@ predicate isSignaturesChecked(MethodAccess maCreatePackageContext)
49
70
DataFlow:: exprNode ( maCreatePackageContext .getArgument ( 0 ) ) )
50
71
)
51
72
}
52
-
73
+
53
74
from
54
75
MethodAccess maCreatePackageContext ,
55
76
LocalVariableDeclExpr lvdePackageContext ,
56
77
DataFlow:: Node sinkPackageContext ,
57
- MethodAccess maInvoke
78
+ MethodAccess maGetMethod ,
79
+ MethodAccess maInvoke
58
80
where
59
- maCreatePackageContext .getCallee ( ) .getDeclaringType ( ) .getQualifiedName ( ) = "android.content.ContextWrapper" and
81
+ ( maCreatePackageContext .getCallee ( ) .getDeclaringType ( ) .getQualifiedName ( ) = "android.content.ContextWrapper" or
82
+ maCreatePackageContext .getCallee ( ) .getDeclaringType ( ) .getQualifiedName ( ) = "android.content.Context" ) and
60
83
maCreatePackageContext .getCallee ( ) .getName ( ) = "createPackageContext" and
61
84
not isSignaturesChecked ( maCreatePackageContext ) and
62
85
lvdePackageContext .getEnclosingStmt ( ) = maCreatePackageContext .getEnclosingStmt ( ) and
63
86
TaintTracking:: localTaint ( DataFlow:: exprNode ( lvdePackageContext .getAnAccess ( ) ) , sinkPackageContext ) and
64
- doesPackageContextLeadToInvokeMethod ( sinkPackageContext , maInvoke )
87
+ getClassLoaderReachableMethodAccess ( sinkPackageContext ) = maGetMethod and
88
+ getDangerousReachableMethodAccess ( maGetMethod ) = maInvoke
65
89
select
66
90
lvdePackageContext ,
67
91
sinkPackageContext ,
92
+ maGetMethod ,
68
93
maInvoke ,
69
94
"Potential arbitary code execution due to class loading without package signature checking."
70
-
95
+
0 commit comments