|
| 1 | +/** |
| 2 | + * @name Use of deprecated TLS/SSL version |
| 3 | + * @description Using deprecated TLS/SSL versions (SSL3, TLS 1.0, TLS 1.1) weakens transport security. |
| 4 | + * @kind problem |
| 5 | + * @problem.severity error |
| 6 | + * @security-severity 7.5 |
| 7 | + * @precision high |
| 8 | + * @id powershell/deprecated-tls |
| 9 | + * @tags security |
| 10 | + * external/cwe/cwe-327 |
| 11 | + * external/cwe/cwe-757 |
| 12 | + */ |
| 13 | + |
| 14 | +import powershell |
| 15 | +import semmle.code.powershell.ApiGraphs |
| 16 | +import semmle.code.powershell.dataflow.DataFlow |
| 17 | + |
| 18 | +/** |
| 19 | + * Gets the human-readable name for a deprecated protocol. |
| 20 | + */ |
| 21 | +bindingset[protocolName] |
| 22 | +string getProtocolDisplayName(string protocolName) { |
| 23 | + protocolName = "ssl3" and result = "SSL 3.0" |
| 24 | + or |
| 25 | + protocolName = "tls" and result = "TLS 1.0" |
| 26 | + or |
| 27 | + protocolName = "tls11" and result = "TLS 1.1" |
| 28 | +} |
| 29 | + |
| 30 | +abstract class SecurityProtocol extends Expr { |
| 31 | + abstract string getProtocolName(); |
| 32 | +} |
| 33 | + |
| 34 | +/** |
| 35 | + * A reference to a deprecated SecurityProtocolType enum value, e.g. |
| 36 | + * [Net.SecurityProtocolType]::Ssl3 |
| 37 | + */ |
| 38 | +class DeprecatedSecurityProtocolType extends SecurityProtocol { |
| 39 | + string protocolName; |
| 40 | + |
| 41 | + DeprecatedSecurityProtocolType() { |
| 42 | + exists(API::Node node | |
| 43 | + ( |
| 44 | + node = |
| 45 | + API::getTopLevelMember("system") |
| 46 | + .getMember("net") |
| 47 | + .getMember("securityprotocoltype") |
| 48 | + .getMember(protocolName) |
| 49 | + or |
| 50 | + node = |
| 51 | + API::getTopLevelMember("net") |
| 52 | + .getMember("securityprotocoltype") |
| 53 | + .getMember(protocolName) |
| 54 | + ) and |
| 55 | + this = node.asSource().asExpr().getExpr() |
| 56 | + ) |
| 57 | + } |
| 58 | + |
| 59 | + override string getProtocolName() { result = protocolName } |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * A reference to a deprecated SslProtocols enum value, e.g. |
| 64 | + * [System.Security.Authentication.SslProtocols]::Tls |
| 65 | + */ |
| 66 | +class DeprecatedSslProtocols extends SecurityProtocol { |
| 67 | + string protocolName; |
| 68 | + |
| 69 | + DeprecatedSslProtocols() { |
| 70 | + exists(API::Node node | |
| 71 | + node = |
| 72 | + API::getTopLevelMember("system") |
| 73 | + .getMember("security") |
| 74 | + .getMember("authentication") |
| 75 | + .getMember("sslprotocols") |
| 76 | + .getMember(protocolName) and |
| 77 | + this = node.asSource().asExpr().getExpr() |
| 78 | + ) |
| 79 | + } |
| 80 | + |
| 81 | + override string getProtocolName() { result = protocolName } |
| 82 | +} |
| 83 | + |
| 84 | +from SecurityProtocol sp, string protocolName |
| 85 | +where |
| 86 | + protocolName = sp.getProtocolName() and |
| 87 | + protocolName = ["ssl3", "tls", "tls11"] |
| 88 | +select sp, |
| 89 | + "Use of deprecated protocol " + getProtocolDisplayName(protocolName) + |
| 90 | + ". Use TLS 1.2 or TLS 1.3 instead." |
0 commit comments