Skip to content

Commit decbe38

Browse files
committed
make abstract class, remove microsoft from id, add qhelp
1 parent 125468d commit decbe38

4 files changed

Lines changed: 70 additions & 23 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE qhelp PUBLIC "-//Semmle//qhelp//EN" "qhelp.dtd">
2+
<qhelp>
3+
<overview>
4+
<p>
5+
TLS (Transport Layer Security) and its predecessor SSL (Secure Sockets Layer) are protocols
6+
used to secure network communications. Older versions of these protocols have known
7+
vulnerabilities that can be exploited by attackers to compromise the confidentiality and
8+
integrity of data in transit.
9+
</p>
10+
<p>
11+
The following versions are considered deprecated:
12+
</p>
13+
<ul>
14+
<li>SSL 3.0 is vulnerable to the POODLE attack and other weaknesses.</li>
15+
<li>TLS 1.0 has known vulnerabilities including the BEAST attack and weak cipher suites.</li>
16+
<li>TLS 1.1 lacks support for modern cryptographic algorithms and is deprecated by RFC 8996.</li>
17+
</ul>
18+
</overview>
19+
<recommendation>
20+
<p>
21+
Use TLS 1.2 or TLS 1.3 for all secure communications. TLS 1.3 is preferred as it removes
22+
support for legacy cryptographic features and provides improved performance. When configuring
23+
<code>SecurityProtocolType</code>, use <code>Tls12</code> or <code>Tls13</code>.
24+
</p>
25+
</recommendation>
26+
<example>
27+
<p>
28+
In the following example, the script enables the deprecated SSL 3.0 and TLS 1.0 protocols:
29+
</p>
30+
<sample src="examples/DeprecatedTls/DeprecatedTlsBad.ps1" />
31+
<p>
32+
The following example shows the corrected code using TLS 1.2:
33+
</p>
34+
<sample src="examples/DeprecatedTls/DeprecatedTlsGood.ps1" />
35+
</example>
36+
<references>
37+
<li>IETF, RFC 8996: <a href="https://datatracker.ietf.org/doc/html/rfc8996">Deprecating TLS 1.0 and TLS 1.1</a>.</li>
38+
<li>NIST, SP 800-52 Rev. 2: <a href="https://csrc.nist.gov/publications/detail/sp/800-52/rev-2/final">Guidelines for the Selection, Configuration, and Use of TLS Implementations</a>.</li>
39+
<li>OWASP: <a href="https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Security_Cheat_Sheet.html">Transport Layer Security Cheat Sheet</a>.</li>
40+
<li>CWE-757: <a href="https://cwe.mitre.org/data/definitions/757.html">Selection of Less-Secure Algorithm During Negotiation ('Algorithm Downgrade')</a>.</li>
41+
</references>
42+
</qhelp>

powershell/ql/src/queries/security/cwe-757/DeprecatedTls.ql

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @problem.severity error
66
* @security-severity 7.5
77
* @precision high
8-
* @id powershell/microsoft/security/deprecated-tls
8+
* @id powershell/deprecated-tls
99
* @tags security
1010
* external/cwe/cwe-327
1111
* external/cwe/cwe-757
@@ -15,13 +15,6 @@ import powershell
1515
import semmle.code.powershell.ApiGraphs
1616
import semmle.code.powershell.dataflow.DataFlow
1717

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-
2518
/**
2619
* Gets the human-readable name for a deprecated protocol.
2720
*/
@@ -34,11 +27,15 @@ string getProtocolDisplayName(string protocolName) {
3427
protocolName = "tls11" and result = "TLS 1.1"
3528
}
3629

30+
abstract class SecurityProtocol extends Expr {
31+
abstract string getProtocolName();
32+
}
33+
3734
/**
3835
* A reference to a deprecated SecurityProtocolType enum value, e.g.
3936
* [Net.SecurityProtocolType]::Ssl3
4037
*/
41-
class DeprecatedSecurityProtocolType extends DataFlow::Node {
38+
class DeprecatedSecurityProtocolType extends SecurityProtocol {
4239
string protocolName;
4340

4441
DeprecatedSecurityProtocolType() {
@@ -55,19 +52,18 @@ class DeprecatedSecurityProtocolType extends DataFlow::Node {
5552
.getMember("securityprotocoltype")
5653
.getMember(protocolName)
5754
) and
58-
this = node.asSource() and
59-
isDeprecatedProtocol(protocolName)
55+
this = node.asSource().asExpr().getExpr()
6056
)
6157
}
6258

63-
string getProtocolName() { result = protocolName }
59+
override string getProtocolName() { result = protocolName }
6460
}
6561

6662
/**
6763
* A reference to a deprecated SslProtocols enum value, e.g.
6864
* [System.Security.Authentication.SslProtocols]::Tls
6965
*/
70-
class DeprecatedSslProtocols extends DataFlow::Node {
66+
class DeprecatedSslProtocols extends SecurityProtocol {
7167
string protocolName;
7268

7369
DeprecatedSslProtocols() {
@@ -78,21 +74,17 @@ class DeprecatedSslProtocols extends DataFlow::Node {
7874
.getMember("authentication")
7975
.getMember("sslprotocols")
8076
.getMember(protocolName) and
81-
this = node.asSource() and
82-
isDeprecatedProtocol(protocolName)
77+
this = node.asSource().asExpr().getExpr()
8378
)
8479
}
8580

86-
string getProtocolName() { result = protocolName }
81+
override string getProtocolName() { result = protocolName }
8782
}
8883

89-
from DataFlow::Node node, string protocolName
84+
from SecurityProtocol sp, string protocolName
9085
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,
86+
protocolName = sp.getProtocolName() and
87+
protocolName = ["ssl3", "tls", "tls11"]
88+
select sp,
9789
"Use of deprecated protocol " + getProtocolDisplayName(protocolName) +
9890
". Use TLS 1.2 or TLS 1.3 instead."
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# BAD: Using deprecated SSL 3.0
2+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3
3+
4+
# BAD: Using deprecated TLS 1.0
5+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls
6+
7+
# BAD: Using deprecated TLS 1.1
8+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls11
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# GOOD: Using TLS 1.2
2+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
3+
4+
# GOOD: Using TLS 1.3
5+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls13

0 commit comments

Comments
 (0)