Skip to content

Commit 3b68d4d

Browse files
committed
Minor Improvements and removed Padding Check
Added descriptions Added SessionTicketZeroKey details in SiteReportPrinter Refactored checkForMasterSecret Removed Padding Check
1 parent 627e725 commit 3b68d4d

File tree

4 files changed

+71
-35
lines changed

4 files changed

+71
-35
lines changed

src/main/java/de/rub/nds/tlsscanner/probe/SessionTicketZeroKeyProbe.java

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import java.util.ArrayList;
1212
import java.util.Arrays;
13+
import java.util.Collections;
1314
import java.util.LinkedList;
1415
import java.util.List;
1516

@@ -18,6 +19,8 @@
1819
import javax.crypto.spec.IvParameterSpec;
1920
import javax.crypto.spec.SecretKeySpec;
2021

22+
import org.apache.commons.lang3.ArrayUtils;
23+
2124
import de.rub.nds.modifiablevariable.util.ArrayConverter;
2225
import de.rub.nds.tlsattacker.core.config.Config;
2326
import de.rub.nds.tlsattacker.core.constants.CipherSuite;
@@ -38,14 +41,55 @@
3841
import de.rub.nds.tlsscanner.report.result.ProbeResult;
3942
import de.rub.nds.tlsscanner.report.result.SessionTicketZeroKeyResult;
4043

44+
/**
45+
*
46+
* The Probe checks for CVE-2020-13777.
47+
*
48+
* Quote: "GnuTLS 3.6.x before 3.6.14 uses incorrect cryptography for encrypting
49+
* a session ticket (a loss of confidentiality in TLS 1.2, and an authentication
50+
* bypass in TLS 1.3). The earliest affected version is 3.6.4 (2018-09-24)
51+
* because of an error in a 2018-09-18 commit. Until the first key rotation, the
52+
* TLS server always uses wrong data in place of an encryption key derived from
53+
* an application."[1]
54+
*
55+
* Reference [1]: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-13777
56+
* Reference [2]: https://www.gnutls.org/security-new.html
57+
*
58+
*/
4159
public class SessionTicketZeroKeyProbe extends TlsProbe {
4260

61+
/**
62+
* Magic Bytes the plaintext state in GnuTls starts with
63+
*/
4364
public static final byte[] GNU_TLS_MAGIC_BYTES = ArrayConverter.hexStringToByteArray("FAE1C0EA");
65+
66+
/**
67+
* Offset of the IV according to the ticket struct in rfc5077
68+
*/
4469
public static final int IV_OFFSET = 16;
70+
71+
/**
72+
* Length of the IV according to the ticket struct in rfc5077
73+
*/
4574
public static final int IV_LEN = 16;
75+
76+
/**
77+
* Offset of the length field for the in the encrypted state according to
78+
* the ticket struct in rfc5077
79+
*/
4680
public static final int SESSION_STATE_LENFIELD_OFFSET = 32;
81+
82+
/**
83+
* Length of the length field for the in the encrypted state according to
84+
* the ticket struct in rfc5077
85+
*/
4786
public static final int SESSION_STATE_LENFIELD_LEN = 2;
87+
88+
/**
89+
* Offset of the encrypted state according to the ticket struct in rfc5077
90+
*/
4891
public static final int SESSION_STATE_OFFSET = 34;
92+
4993
private List<CipherSuite> supportedSuites;
5094

5195
public SessionTicketZeroKeyProbe(ScannerConfig scannerConfig, ParallelExecutor parallelExecutor) {
@@ -79,13 +123,11 @@ public ProbeResult executeTest() {
79123
executeState(state);
80124
} catch (Exception E) {
81125
LOGGER.error("Could not scan for " + getProbeName(), E);
82-
return new SessionTicketZeroKeyResult(TestResult.ERROR_DURING_TEST, TestResult.ERROR_DURING_TEST,
83-
TestResult.ERROR_DURING_TEST);
126+
return new SessionTicketZeroKeyResult(TestResult.ERROR_DURING_TEST, TestResult.ERROR_DURING_TEST);
84127
}
85128

86129
if (!WorkflowTraceUtil.didReceiveMessage(HandshakeMessageType.NEW_SESSION_TICKET, state.getWorkflowTrace())) {
87-
return new SessionTicketZeroKeyResult(TestResult.UNSUPPORTED, TestResult.UNSUPPORTED,
88-
TestResult.UNSUPPORTED);
130+
return new SessionTicketZeroKeyResult(TestResult.UNSUPPORTED, TestResult.UNSUPPORTED);
89131
}
90132

91133
byte[] ticket = null;
@@ -96,8 +138,7 @@ public ProbeResult executeTest() {
96138
}
97139
}
98140

99-
byte[] key = ArrayConverter
100-
.hexStringToByteArray("0000000000000000000000000000000000000000000000000000000000000000");
141+
byte[] key = new byte[32];
101142
byte[] iv, encryptedSessionState;
102143
byte[] decryptedSessionState = null;
103144

@@ -114,9 +155,8 @@ public ProbeResult executeTest() {
114155
decryptedSessionState = cipher.doFinal(encryptedSessionState);
115156
LOGGER.debug("decryptedSsessionState" + ArrayConverter.bytesToHexString(decryptedSessionState));
116157
} catch (Exception e) {
117-
return new SessionTicketZeroKeyResult(TestResult.FALSE, TestResult.FALSE, TestResult.FALSE);
158+
return new SessionTicketZeroKeyResult(TestResult.FALSE, TestResult.FALSE);
118159
}
119-
TestResult hasCorrectPadding = TestResult.TRUE;
120160
TestResult hasDecryptableMasterSecret;
121161
TestResult hasGnuTlsMagicBytes;
122162

@@ -125,14 +165,15 @@ public ProbeResult executeTest() {
125165
} else {
126166
hasDecryptableMasterSecret = TestResult.FALSE;
127167
}
168+
128169
if (checkForGnuTlsMagicBytes(decryptedSessionState)) {
129170
hasGnuTlsMagicBytes = TestResult.TRUE;
130171

131172
} else {
132173
hasGnuTlsMagicBytes = TestResult.FALSE;
133174
}
134175

135-
return new SessionTicketZeroKeyResult(hasCorrectPadding, hasDecryptableMasterSecret, hasGnuTlsMagicBytes);
176+
return new SessionTicketZeroKeyResult(hasDecryptableMasterSecret, hasGnuTlsMagicBytes);
136177
}
137178

138179
@Override
@@ -141,20 +182,12 @@ public boolean canBeExecuted(SiteReport report) {
141182
}
142183

143184
private boolean checkForMasterSecret(byte[] decState, TlsContext context) {
144-
boolean found = false;
145-
byte[] ms = context.getMasterSecret();
146-
for (int i = 0; i < decState.length - ms.length; i++) {
147-
found = true;
148-
for (int j = 0; j < ms.length; j++) {
149-
if (decState[i + j] != ms[j]) {
150-
found = false;
151-
break;
152-
}
153-
}
154-
if (found)
155-
return true;
185+
List<Byte> target = Arrays.asList(ArrayUtils.toObject(context.getMasterSecret()));
186+
List<Byte> source = Arrays.asList(ArrayUtils.toObject(decState));
187+
if (Collections.indexOfSubList(source, target) == -1) {
188+
return false;
156189
}
157-
return false;
190+
return true;
158191
}
159192

160193
private boolean checkForGnuTlsMagicBytes(byte[] decState) {
@@ -170,13 +203,12 @@ private boolean checkForGnuTlsMagicBytes(byte[] decState) {
170203

171204
@Override
172205
public ProbeResult getCouldNotExecuteResult() {
173-
return new SessionTicketZeroKeyResult(TestResult.COULD_NOT_TEST, TestResult.COULD_NOT_TEST,
174-
TestResult.COULD_NOT_TEST);
206+
return new SessionTicketZeroKeyResult(TestResult.COULD_NOT_TEST, TestResult.COULD_NOT_TEST);
175207
}
176208

177209
@Override
178210
public void adjustConfig(SiteReport report) {
179-
supportedSuites = new ArrayList<>(report.getCipherSuites());
211+
supportedSuites = new ArrayList<>(report.getCipherSuites());
180212
}
181213

182-
}
214+
}

src/main/java/de/rub/nds/tlsscanner/report/AnalyzedProperty.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ public enum AnalyzedProperty {
187187
REUSES_DH_PUBLICKEY(AnalyzedPropertyCategory.FRESHNESS),
188188
REUSES_GCM_NONCES(AnalyzedPropertyCategory.FRESHNESS),
189189
REQUIRES_SNI(AnalyzedPropertyCategory.SNI),
190-
191-
HAS_CORRECT_TICKET_PADDING(AnalyzedPropertyCategory.SESSION_TICKET),
192190
HAS_GNU_TLS_MAGIC_BYTES(AnalyzedPropertyCategory.SESSION_TICKET);
193191

194192
private AnalyzedPropertyCategory category;

src/main/java/de/rub/nds/tlsscanner/report/SiteReportPrinter.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public String getFullReport() {
117117
appendAttackVulnerabilities(builder);
118118
appendBleichenbacherResults(builder);
119119
appendPaddingOracleResults(builder);
120+
sessionTicketZeroKeyDetails(builder);
120121
//appendGcm(builder);
121122
appendRfc(builder);
122123
appendCertificate(builder);
@@ -576,7 +577,7 @@ private StringBuilder appendAttackVulnerabilities(StringBuilder builder) {
576577
prettyAppend(builder, "DROWN", AnalyzedProperty.VULNERABLE_TO_DROWN);
577578
prettyAppend(builder, "Heartbleed", AnalyzedProperty.VULNERABLE_TO_HEARTBLEED);
578579
prettyAppend(builder, "EarlyCcs", AnalyzedProperty.VULNERABLE_TO_EARLY_CCS);
579-
prettyAppend(builder, "SessionTicketZeroKey", AnalyzedProperty.VULNERABLE_TO_SESSION_TICKET_ZERO_KEY);
580+
prettyAppend(builder, "CVE-2020-13777 (Zero key)", AnalyzedProperty.VULNERABLE_TO_SESSION_TICKET_ZERO_KEY);
580581
return builder;
581582
}
582583

@@ -1417,5 +1418,14 @@ private void appendPerformanceData(StringBuilder builder) {
14171418
LOGGER.debug("Not printing performance data.");
14181419
}
14191420
}
1421+
1422+
private StringBuilder sessionTicketZeroKeyDetails(StringBuilder builder) {
1423+
if (report.getResult(AnalyzedProperty.VULNERABLE_TO_SESSION_TICKET_ZERO_KEY) == TestResult.TRUE) {
1424+
prettyAppendHeading(builder, "Session Ticket Zero Key Attack Details");
1425+
prettyAppend(builder, "Has GnuTls magic bytes:", AnalyzedProperty.HAS_GNU_TLS_MAGIC_BYTES);
1426+
}
1427+
return builder;
1428+
}
1429+
14201430
}
14211431

src/main/java/de/rub/nds/tlsscanner/report/result/SessionTicketZeroKeyResult.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,20 @@
1515

1616
public class SessionTicketZeroKeyResult extends ProbeResult {
1717

18-
private TestResult hasCorrectTicketPadding;
1918
private TestResult hasDecryptableMasterSecret;
2019
private TestResult hasGnuTlsMagicBytes;
2120

22-
public SessionTicketZeroKeyResult(TestResult hasCorrectTicketPadding, TestResult hasDecryptableMasterSecret,
23-
TestResult hasGnuTlsMagicBytes) {
21+
public SessionTicketZeroKeyResult(TestResult hasDecryptableMasterSecret, TestResult hasGnuTlsMagicBytes) {
2422
super(ProbeType.SESSION_TICKET_ZERO_KEY);
25-
this.hasCorrectTicketPadding = hasCorrectTicketPadding;
2623
this.hasDecryptableMasterSecret = hasDecryptableMasterSecret;
2724
this.hasGnuTlsMagicBytes = hasGnuTlsMagicBytes;
2825

2926
}
3027

3128
@Override
3229
protected void mergeData(SiteReport report) {
33-
report.putResult(AnalyzedProperty.HAS_CORRECT_TICKET_PADDING, this.hasCorrectTicketPadding);
3430
report.putResult(AnalyzedProperty.VULNERABLE_TO_SESSION_TICKET_ZERO_KEY, this.hasDecryptableMasterSecret);
3531
report.putResult(AnalyzedProperty.HAS_GNU_TLS_MAGIC_BYTES, this.hasGnuTlsMagicBytes);
3632
}
3733

38-
}
34+
}

0 commit comments

Comments
 (0)