/
use_weak_rng_for_keygeneration.yaml
48 lines (48 loc) · 1.71 KB
/
use_weak_rng_for_keygeneration.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
rules:
- id: use_weak_rng_for_keygeneration
message: You are using an insecure random number generator (RNG) to create a cryptographic key. System.Random
must never be used for cryptographic purposes. Use System.Security.Cryptography.RandomNumberGenerator
instead.
severity: ERROR
metadata:
likelihood: HIGH
impact: MEDIUM
confidence: HIGH
category: security
cwe:
- 'CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)'
owasp:
- A02:2021 - Cryptographic Failures
references:
- https://learn.microsoft.com/en-us/dotnet/api/system.random?view=net-6.0#remarks
- https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.randomnumbergenerator?view=net-6.0
- https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.aesgcm?view=net-6.0#constructors
- https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.symmetricalgorithm.key?view=net-6.0#system-security-cryptography-symmetricalgorithm-key
subcategory:
- vuln
technology:
- .net
languages:
- csharp
mode: taint
pattern-sources:
- patterns:
- pattern-inside: (System.Random $RNG).NextBytes($KEY); ...
- pattern: $KEY
pattern-sinks:
- pattern-either:
- patterns:
- pattern: ($KEYTYPE $CIPHER).Key = $SINK;
- focus-metavariable: $SINK
- metavariable-pattern:
metavariable: $KEYTYPE
pattern-either:
- pattern: SymmetricAlgorithm
- pattern: Aes
- pattern: Rijndael
- pattern: DES
- pattern: TripleDES
- pattern: RC2
- pattern: new AesGcm(...)
- pattern: new AesCcm(...)
- pattern: new ChaCha20Poly1305(...)