Skip to content

Commit 125468d

Browse files
chanel-yCopilot
andcommitted
Add deprecated TLS/SSL version detection query for PowerShell
Detects usage of SSL 3.0, TLS 1.0, and TLS 1.1 via SecurityProtocolType and SslProtocols enum references. Covers: Cryptography.10031 (CWE-327, CWE-757) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cccecc4 commit 125468d

4 files changed

Lines changed: 128 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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/microsoft/security/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+
* Holds if `protocolName` is a deprecated TLS/SSL protocol (lowercase).
20+
*/
21+
predicate isDeprecatedProtocol(string protocolName) {
22+
protocolName = ["ssl3", "tls", "tls11"]
23+
}
24+
25+
/**
26+
* Gets the human-readable name for a deprecated protocol.
27+
*/
28+
bindingset[protocolName]
29+
string getProtocolDisplayName(string protocolName) {
30+
protocolName = "ssl3" and result = "SSL 3.0"
31+
or
32+
protocolName = "tls" and result = "TLS 1.0"
33+
or
34+
protocolName = "tls11" and result = "TLS 1.1"
35+
}
36+
37+
/**
38+
* A reference to a deprecated SecurityProtocolType enum value, e.g.
39+
* [Net.SecurityProtocolType]::Ssl3
40+
*/
41+
class DeprecatedSecurityProtocolType extends DataFlow::Node {
42+
string protocolName;
43+
44+
DeprecatedSecurityProtocolType() {
45+
exists(API::Node node |
46+
(
47+
node =
48+
API::getTopLevelMember("system")
49+
.getMember("net")
50+
.getMember("securityprotocoltype")
51+
.getMember(protocolName)
52+
or
53+
node =
54+
API::getTopLevelMember("net")
55+
.getMember("securityprotocoltype")
56+
.getMember(protocolName)
57+
) and
58+
this = node.asSource() and
59+
isDeprecatedProtocol(protocolName)
60+
)
61+
}
62+
63+
string getProtocolName() { result = protocolName }
64+
}
65+
66+
/**
67+
* A reference to a deprecated SslProtocols enum value, e.g.
68+
* [System.Security.Authentication.SslProtocols]::Tls
69+
*/
70+
class DeprecatedSslProtocols extends DataFlow::Node {
71+
string protocolName;
72+
73+
DeprecatedSslProtocols() {
74+
exists(API::Node node |
75+
node =
76+
API::getTopLevelMember("system")
77+
.getMember("security")
78+
.getMember("authentication")
79+
.getMember("sslprotocols")
80+
.getMember(protocolName) and
81+
this = node.asSource() and
82+
isDeprecatedProtocol(protocolName)
83+
)
84+
}
85+
86+
string getProtocolName() { result = protocolName }
87+
}
88+
89+
from DataFlow::Node node, string protocolName
90+
where
91+
exists(DeprecatedSecurityProtocolType d |
92+
node = d and protocolName = d.getProtocolName()
93+
)
94+
or
95+
exists(DeprecatedSslProtocols d | node = d and protocolName = d.getProtocolName())
96+
select node,
97+
"Use of deprecated protocol " + getProtocolDisplayName(protocolName) +
98+
". Use TLS 1.2 or TLS 1.3 instead."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| test.ps1:6:47:6:78 | ssl3 | Use of deprecated protocol SSL 3.0. Use TLS 1.2 or TLS 1.3 instead. |
2+
| test.ps1:9:47:9:77 | tls | Use of deprecated protocol TLS 1.0. Use TLS 1.2 or TLS 1.3 instead. |
3+
| test.ps1:12:47:12:79 | tls11 | Use of deprecated protocol TLS 1.1. Use TLS 1.2 or TLS 1.3 instead. |
4+
| test.ps1:15:54:15:91 | tls | Use of deprecated protocol TLS 1.0. Use TLS 1.2 or TLS 1.3 instead. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/security/cwe-757/DeprecatedTls.ql
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ===================================================================
2+
# ========== TRUE POSITIVES (should trigger alert) ==================
3+
# ===================================================================
4+
5+
# --- Case 1: SSL 3.0 ---
6+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3 # BAD
7+
8+
# --- Case 2: TLS 1.0 ---
9+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls # BAD
10+
11+
# --- Case 3: TLS 1.1 ---
12+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls11 # BAD
13+
14+
# --- Case 4: Full namespace TLS 1.0 ---
15+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls # BAD
16+
17+
# ===================================================================
18+
# ========== TRUE NEGATIVES (should NOT trigger alert) ==============
19+
# ===================================================================
20+
21+
# --- Safe: TLS 1.2 ---
22+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 # GOOD
23+
24+
# --- Safe: TLS 1.3 ---
25+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls13 # GOOD

0 commit comments

Comments
 (0)