Skip to content

Commit 7c0d145

Browse files
committed
Updated Lucky13 Attack to fit current coding style
1 parent 3d74041 commit 7c0d145

File tree

5 files changed

+94
-84
lines changed

5 files changed

+94
-84
lines changed

Attacks/src/main/java/de/rub/nds/tlsattacker/attacks/config/Lucky13CommandConfig.java

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
import com.beust.jcommander.Parameter;
1212
import com.beust.jcommander.ParametersDelegate;
13+
import de.rub.nds.tlsattacker.attacks.config.delegate.ProxyDelegate;
1314
import de.rub.nds.tlsattacker.core.config.Config;
1415
import de.rub.nds.tlsattacker.core.config.delegate.*;
1516

16-
import java.util.HashMap;
1717
import java.util.LinkedList;
1818
import java.util.List;
1919

@@ -26,31 +26,20 @@ public class Lucky13CommandConfig extends AttackConfig {
2626

2727
public static final String ATTACK_COMMAND = "lucky13";
2828

29-
protected List<CipherSuite> cipherSuites;
30-
31-
protected static HashMap<CipherSuite, Integer> blockSizeForCipherSuite;
32-
static {
33-
blockSizeForCipherSuite = new HashMap<>();
34-
blockSizeForCipherSuite.put(CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA, 16);
35-
blockSizeForCipherSuite.put(CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA, 16);
36-
blockSizeForCipherSuite.put(CipherSuite.TLS_RSA_WITH_DES_CBC_SHA, 8);
37-
blockSizeForCipherSuite.put(CipherSuite.TLS_RSA_WITH_3DES_EDE_CBC_SHA, 8);
38-
}
39-
4029
@Parameter(names = "-measurements", description = "Number of timing measurement iterations")
41-
Integer measurements = 100;
30+
private Integer measurements = 100;
4231

4332
@Parameter(names = "-mona_file", description = "File output for Mona timing lib. If set, the output is generated and written.")
44-
String monaFile;
33+
private String monaFile;
4534

4635
@Parameter(names = "-mona_jar", description = "Location of the ReportingTool.jar file.")
47-
String monaJar = "ReportingTool.jar";
36+
private String monaJar = "ReportingTool.jar";
4837

4938
@Parameter(names = "-paddings", description = "Paddings to check for differences, column separated.")
50-
String paddings = "0,255";
39+
private String paddings = "0,255";
5140

5241
@Parameter(names = "-blocks", description = "Number of blocks to encrypt (default is set to the value from the Lucky 13 paper, Section 3)")
53-
Integer blocks = 18;
42+
private Integer blocks = 18;
5443

5544
@ParametersDelegate
5645
private ClientDelegate clientDelegate;
@@ -62,6 +51,8 @@ public class Lucky13CommandConfig extends AttackConfig {
6251
private ProtocolVersionDelegate protocolVersionDelegate;
6352
@ParametersDelegate
6453
private StarttlsDelegate starttlsDelegate;
54+
@ParametersDelegate
55+
private ProxyDelegate proxyDelegate;
6556

6657
/**
6758
*
@@ -79,17 +70,7 @@ public Lucky13CommandConfig(GeneralDelegate delegate) {
7970
addDelegate(ciphersuiteDelegate);
8071
addDelegate(protocolVersionDelegate);
8172
addDelegate(starttlsDelegate);
82-
cipherSuites = new LinkedList<>();
83-
cipherSuites.add(CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA);
84-
cipherSuites.add(CipherSuite.TLS_RSA_WITH_AES_256_CBC_SHA);
85-
}
86-
87-
public Integer getBlockSizeForCiphersuite(CipherSuite suite) {
88-
return blockSizeForCipherSuite.get(suite);
89-
}
90-
91-
public List<CipherSuite> getCipherSuites() {
92-
return cipherSuites;
73+
addDelegate(proxyDelegate);
9374
}
9475

9576
public Integer getMeasurements() {
@@ -153,11 +134,11 @@ public Config createConfig() {
153134
* No explicit cipher suites are set. Use the default cipher suites
154135
* for this attack
155136
*/
156-
config.setDefaultServerSupportedCiphersuites(cipherSuites);
157-
config.setDefaultClientSupportedCiphersuites(cipherSuites);
158-
config.setDefaultSelectedCipherSuite(cipherSuites.get(0));
159-
} else {
160-
cipherSuites = ciphersuiteDelegate.getCipherSuites();
137+
List<CipherSuite> suiteList = new LinkedList<>();
138+
suiteList.add(CipherSuite.TLS_RSA_WITH_AES_128_CBC_SHA);
139+
config.setDefaultServerSupportedCiphersuites(suiteList);
140+
config.setDefaultClientSupportedCiphersuites(suiteList);
141+
config.setDefaultSelectedCipherSuite(suiteList.get(0));
161142
}
162143
return config;
163144
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
3+
*
4+
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
package de.rub.nds.tlsattacker.attacks.config.delegate;
10+
11+
import com.beust.jcommander.Parameter;
12+
import com.beust.jcommander.ParameterException;
13+
import de.rub.nds.tlsattacker.core.config.Config;
14+
import de.rub.nds.tlsattacker.core.config.delegate.Delegate;
15+
import de.rub.nds.tlsattacker.core.connection.OutboundConnection;
16+
17+
/**
18+
*
19+
* @author ic0ns
20+
*/
21+
public class ProxyDelegate extends Delegate {
22+
23+
@Parameter(names = "-proxyData", description = "Specify the host and port for data used in the proxy. Syntax: localhost:4444")
24+
private String proxyData = "localhost:4444";
25+
26+
@Parameter(names = "-proxyControl", description = "Specify the host and port for control messafes used in the proxy. Syntax: localhost:5555")
27+
private String proxyControl = "localhost:5555";
28+
29+
@Override
30+
public void applyDelegate(Config config) {
31+
32+
OutboundConnection con = config.getDefaultClientConnection();
33+
if (con == null) {
34+
con = new OutboundConnection();
35+
config.setDefaultClientConnection(con);
36+
}
37+
if (proxyData != null) {
38+
String[] parsedProxyData = proxyData.split(":");
39+
switch (parsedProxyData.length) {
40+
case 1:
41+
con.setProxyDataHostname(proxyData);
42+
break;
43+
case 2:
44+
con.setProxyDataHostname(parsedProxyData[0]);
45+
con.setProxyDataPort(parsePort(parsedProxyData[1]));
46+
break;
47+
default:
48+
throw new ParameterException("Could not parse provided proxyData: " + proxyData);
49+
}
50+
}
51+
52+
if (proxyControl != null) {
53+
String[] parsedProxyControl = proxyControl.split(":");
54+
switch (parsedProxyControl.length) {
55+
case 1:
56+
con.setProxyControlHostname(proxyControl);
57+
break;
58+
case 2:
59+
con.setProxyControlHostname(parsedProxyControl[0]);
60+
con.setProxyControlPort(parsePort(parsedProxyControl[1]));
61+
break;
62+
default:
63+
throw new ParameterException("Could not parse provided proxyControl: " + proxyControl);
64+
}
65+
}
66+
}
67+
68+
private int parsePort(String portStr) {
69+
int port = Integer.parseInt(portStr);
70+
if (port < 0 || port > 65535) {
71+
throw new ParameterException("port must be in interval [0,65535], but is " + port);
72+
}
73+
return port;
74+
}
75+
}

Attacks/src/main/java/de/rub/nds/tlsattacker/attacks/impl/Lucky13Attacker.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import de.rub.nds.modifiablevariable.VariableModification;
3030
import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory;
3131
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
32+
import de.rub.nds.tlsattacker.core.config.delegate.CiphersuiteDelegate;
3233
import java.io.FileWriter;
3334
import java.io.IOException;
3435
import java.util.*;
@@ -89,8 +90,6 @@ public void executeAttackRound(Record record) {
8990
ReceiveAction action = new ReceiveAction();
9091

9192
AlertMessage alertMessage = new AlertMessage(tlsConfig);
92-
alertMessage.setDescription(AlertDescription.BAD_RECORD_MAC.getValue());
93-
alertMessage.setLevel(AlertLevel.FATAL.getValue());
9493
List<ProtocolMessage> messages = new LinkedList<>();
9594
messages.add(alertMessage);
9695
action.setExpectedMessages(messages);
@@ -122,7 +121,7 @@ public void executeAttackRound(Record record) {
122121

123122
private Record createRecordWithPadding(int p, CipherSuite suite) {
124123
byte[] padding = createPaddingBytes(p);
125-
int recordLength = config.getBlockSizeForCiphersuite(suite) * config.getBlocks();
124+
int recordLength = AlgorithmResolver.getCipher(suite).getBlocksize() * config.getBlocks();
126125
if (recordLength < padding.length) {
127126
throw new ConfigurationException("Padding too large");
128127
}
@@ -156,7 +155,7 @@ private byte[] createPaddingBytes(int padding) {
156155
protected Boolean isVulnerable() {
157156
Boolean vulnerable = false;
158157
StringBuilder commands = new StringBuilder();
159-
List<CipherSuite> suites = config.getCipherSuites();
158+
List<CipherSuite> suites = tlsConfig.getDefaultClientSupportedCiphersuites();
160159
for (CipherSuite suite : suites) {
161160
results.clear();
162161
LOGGER.info("Testing ciphersuite {}", suite);
@@ -168,7 +167,7 @@ protected Boolean isVulnerable() {
168167
for (int i = 0; i < paddingStrings.length; i++) {
169168
paddings[i] = Integer.parseInt(paddingStrings[i]);
170169
}
171-
for (int i = 0; i < ((int) config.getMeasurements() * 1.25); i++) {
170+
for (int i = 0; i < config.getMeasurements(); i++) {
172171
LOGGER.info("Starting round {}", i);
173172
for (int p : paddings) {
174173
Record record = createRecordWithPadding(p, suite);
@@ -200,7 +199,7 @@ protected Boolean isVulnerable() {
200199
for (int j = i + 1; j < paddings.length; j++) {
201200
String fileName = config.getMonaFile() + "-" + paddings[i] + "-" + paddings[j] + "-"
202201
+ suite.name() + ".csv";
203-
String[] delimiters = { (";" + paddings[i] + ";"), (";" + paddings[j] + ";") };
202+
String[] delimiters = {(";" + paddings[i] + ";"), (";" + paddings[j] + ";")};
204203
createMonaFile(fileName, delimiters, results.get(paddings[i]), results.get(paddings[j]));
205204
String command = "java -jar " + config.getMonaJar() + " --inputFile=" + fileName
206205
+ " --name=lucky13-" + suite.name().replace('_', '-') + "-" + paddings[i] + "-"
@@ -211,7 +210,6 @@ protected Boolean isVulnerable() {
211210
}
212211
}
213212
}
214-
// vulnerable |= false;
215213
}
216214
LOGGER.info("All commands at once: \n{}", commands);
217215
LOGGER.warn("Vulnerability has to be tested using the mona timing lib.");

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ public class ClientDelegate extends Delegate {
1919
@Parameter(names = "-connect", required = true, description = "Who to connect to. Syntax: localhost:4433")
2020
private String host = null;
2121

22-
@Parameter(names = "-proxyData", description = "Specify the host and port for data used in the proxy. Syntax: localhost:4444")
23-
private String proxyData = "localhost:4444";
24-
25-
@Parameter(names = "-proxyControl", description = "Specify the host and port for control messafes used in the proxy. Syntax: localhost:5555")
26-
private String proxyControl = "localhost:5555";
27-
2822
public ClientDelegate() {
2923
}
3024

@@ -64,36 +58,6 @@ public void applyDelegate(Config config) {
6458
default:
6559
throw new ParameterException("Could not parse provided host: " + host);
6660
}
67-
68-
if (proxyData != null) {
69-
String[] parsedProxyData = proxyData.split(":");
70-
switch (parsedProxyData.length) {
71-
case 1:
72-
con.setProxyDataHostname(proxyData);
73-
break;
74-
case 2:
75-
con.setProxyDataHostname(parsedProxyData[0]);
76-
con.setProxyDataPort(parsePort(parsedProxyData[1]));
77-
break;
78-
default:
79-
throw new ParameterException("Could not parse provided proxyData: " + proxyData);
80-
}
81-
}
82-
83-
if (proxyControl != null) {
84-
String[] parsedProxyControl = proxyControl.split(":");
85-
switch (parsedProxyControl.length) {
86-
case 1:
87-
con.setProxyControlHostname(proxyControl);
88-
break;
89-
case 2:
90-
con.setProxyControlHostname(parsedProxyControl[0]);
91-
con.setProxyControlPort(parsePort(parsedProxyControl[1]));
92-
break;
93-
default:
94-
throw new ParameterException("Could not parse provided proxyControl: " + proxyControl);
95-
}
96-
}
9761
}
9862

9963
private int parsePort(String portStr) {

TLS-Core/src/main/resources/default_config.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,10 @@
8888
<alias>client</alias>
8989
<port>443</port>
9090
<hostname>localhost</hostname>
91-
<proxyDataPort>8080</proxyDataPort>
92-
<proxyDataHostname>localhost</proxyDataHostname>
93-
<proxyControlPort>8080</proxyControlPort>
94-
<proxyControlHostname>localhost</proxyControlHostname>
9591
</defaultClientConnection>
9692
<defaultServerConnection>
9793
<alias>server</alias>
9894
<port>443</port>
99-
<proxyDataPort>8080</proxyDataPort>
100-
<proxyDataHostname>localhost</proxyDataHostname>
101-
<proxyControlPort>8080</proxyControlPort>
102-
<proxyControlHostname>localhost</proxyControlHostname>
10395
</defaultServerConnection>
10496
<defaultRunningMode>CLIENT</defaultRunningMode>
10597
<clientAuthentication>false</clientAuthentication>

0 commit comments

Comments
 (0)