1
1
import cpp
2
2
import WindowsCng
3
3
4
- predicate vulnerableCngFunctionName ( string name ) {
5
- name in [ "BCryptSignHash" , "BCryptEncrypt" ]
6
- }
4
+ predicate vulnerableCngFunctionName ( string name ) { name in [ "BCryptSignHash" , "BCryptEncrypt" ] }
7
5
8
- predicate vulnerableCngFunction ( Function f )
9
- {
10
- exists ( string name | f .hasGlobalName ( name ) and vulnerableCngFunctionName ( name ) )
6
+ predicate vulnerableCngFunction ( Function f ) {
7
+ exists ( string name | f .hasGlobalName ( name ) and vulnerableCngFunctionName ( name ) )
11
8
}
12
9
13
10
//TODO: Verify NCrypt calls (parameters) & find all other APIs that should be included (i.e. decrypt, etc.)
14
- predicate isExprKeyHandleForBCryptSignHash ( Expr e ) {
15
- exists ( FunctionCall call |
16
- e = call .getArgument ( 0 )
17
- and
18
- vulnerableCngFunction ( call .getTarget ( ) )
19
- )
11
+ predicate isExprKeyHandleForBCryptSignHash ( Expr e ) {
12
+ exists ( FunctionCall call |
13
+ e = call .getArgument ( 0 ) and
14
+ vulnerableCngFunction ( call .getTarget ( ) )
15
+ )
20
16
}
21
17
22
18
class BCryptSignHashArgumentSink extends BCryptOpenAlgorithmProviderSink {
23
- BCryptSignHashArgumentSink ( ) {
24
- isExprKeyHandleForBCryptSignHash ( this .asExpr ( ) )
25
- }
19
+ BCryptSignHashArgumentSink ( ) { isExprKeyHandleForBCryptSignHash ( this .asExpr ( ) ) }
26
20
}
27
21
28
22
class BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource extends BCryptOpenAlgorithmProviderSource {
29
- BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource ( ) {
30
- this .asExpr ( ) instanceof StringLiteral and
31
- (
32
- this .asExpr ( ) .getValue ( ) in [ "DH" , "DSA" , "ECDSA" , "ECDH" ]
33
- or this .asExpr ( ) .getValue ( ) .matches ( "ECDH%" )
34
- or this .asExpr ( ) .getValue ( ) .matches ( "RSA%" )
35
- )
36
- }
23
+ BCryptOpenAlgorithmProviderPqcVulnerableAlgorithmsSource ( ) {
24
+ this .asExpr ( ) instanceof StringLiteral and
25
+ (
26
+ this .asExpr ( ) .getValue ( ) in [ "DH" , "DSA" , "ECDSA" , "ECDH" ] or
27
+ this .asExpr ( ) .getValue ( ) .matches ( "ECDH%" ) or
28
+ this .asExpr ( ) .getValue ( ) .matches ( "RSA%" )
29
+ )
30
+ }
37
31
}
38
32
39
- predicate stepOpenAlgorithmProvider ( DataFlow:: Node node1 , DataFlow:: Node node2 )
40
- {
41
- exists ( FunctionCall call |
42
- // BCryptOpenAlgorithmProvider 2nd argument specifies the algorithm to be used
43
- node1 .asExpr ( ) = call .getArgument ( 1 )
44
- and
45
- call .getTarget ( ) .hasGlobalName ( "BCryptOpenAlgorithmProvider" )
46
- and
47
- node2 .asDefiningArgument ( ) = call .getArgument ( 0 )
48
- )
33
+ predicate stepOpenAlgorithmProvider ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
34
+ exists ( FunctionCall call |
35
+ // BCryptOpenAlgorithmProvider 2nd argument specifies the algorithm to be used
36
+ node1 .asExpr ( ) = call .getArgument ( 1 ) and
37
+ call .getTarget ( ) .hasGlobalName ( "BCryptOpenAlgorithmProvider" ) and
38
+ node2 .asDefiningArgument ( ) = call .getArgument ( 0 )
39
+ )
49
40
}
50
41
51
- predicate stepImportGenerateKeyPair ( DataFlow:: Node node1 , DataFlow:: Node node2 )
52
- {
53
- exists ( FunctionCall call |
54
- node1 .asExpr ( ) = call .getArgument ( 0 )
55
- and
56
- ( call .getTarget ( ) .hasGlobalName ( "BCryptImportKeyPair" ) or
57
- call .getTarget ( ) .hasGlobalName ( "BCryptGenerateKeyPair" ) )
58
- and
59
- node2 .asDefiningArgument ( ) = call .getArgument ( 1 )
60
- )
42
+ predicate stepImportGenerateKeyPair ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
43
+ exists ( FunctionCall call |
44
+ node1 .asExpr ( ) = call .getArgument ( 0 ) and
45
+ (
46
+ call .getTarget ( ) .hasGlobalName ( "BCryptImportKeyPair" ) or
47
+ call .getTarget ( ) .hasGlobalName ( "BCryptGenerateKeyPair" )
48
+ ) and
49
+ node2 .asDefiningArgument ( ) = call .getArgument ( 1 )
50
+ )
61
51
}
62
52
63
53
predicate isWindowsCngAsymmetricKeyAdditionalTaintStep ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
64
- stepOpenAlgorithmProvider ( node1 , node2 )
65
- or
66
- stepImportGenerateKeyPair ( node1 , node2 )
67
- }
54
+ stepOpenAlgorithmProvider ( node1 , node2 )
55
+ or
56
+ stepImportGenerateKeyPair ( node1 , node2 )
57
+ }
0 commit comments