Skip to content

Commit 94bd12c

Browse files
FloLinsic0ns
authored andcommitted
Psk test files (#406)
* changes for PskAttack Tool * catch NoSuchAlgortihm Exception * fixed Logger output * Handler Test Files + little Change in one Handler * Introduced PSK Tests * Bug fix for TLS SRP * Fixed compact string of ECDH ClientKeyExchange message * Added missing ciphersuites to the list of implemented ciphersuites and added a test which checks for duplicates * fixed debug output and changed vuln. detection of psk bruteforcer's * Refactored PskClientBruteforcer Increased Usability Introduced GuessProvider to easily change the guessing Strategy * Refactored PskServerBruteforcer Increased Usability * Removed unnecessary config overwrites * Removed unnecessary functions
1 parent d9ff3ce commit 94bd12c

File tree

34 files changed

+1824
-335
lines changed

34 files changed

+1824
-335
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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.bruteforce;
10+
11+
public abstract class GuessProvider {
12+
13+
private final GuessProviderType type;
14+
15+
public GuessProvider(GuessProviderType type) {
16+
this.type = type;
17+
}
18+
19+
public abstract byte[] getGuess();
20+
21+
public GuessProviderType getType() {
22+
return type;
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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.bruteforce;
10+
11+
import java.io.InputStream;
12+
13+
public class GuessProviderFactory {
14+
15+
public static GuessProvider createGuessProvider(GuessProviderType type, InputStream guessSource) {
16+
switch (type) {
17+
case INCREMENTING:
18+
return new IncrementingGuessProvider();
19+
case WORDLIST:
20+
return new WordListGuessProvider(guessSource);
21+
default:
22+
throw new UnsupportedOperationException("Guess provider \"" + type + "\" is not supported");
23+
}
24+
}
25+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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.bruteforce;
10+
11+
/**
12+
*
13+
* @author Robert Merget <robert.merget@rub.de>
14+
*/
15+
public enum GuessProviderType {
16+
INCREMENTING,
17+
WORDLIST
18+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.bruteforce;
10+
11+
public class IncrementingGuessProvider extends GuessProvider {
12+
13+
private byte[] lastGuess = null;
14+
15+
private int size = 0;
16+
17+
public IncrementingGuessProvider() {
18+
super(GuessProviderType.INCREMENTING);
19+
}
20+
21+
@Override
22+
public byte[] getGuess() {
23+
byte[] guess = getIncrementedGuess();
24+
return guess;
25+
}
26+
27+
public byte[] getIncrementedGuess() {
28+
if (lastGuess == null) {
29+
lastGuess = new byte[size];
30+
} else {
31+
lastGuess = createdIncrementedAtPosition(lastGuess, 0);
32+
if (lastGuess == null) {
33+
size++;
34+
lastGuess = new byte[size];
35+
}
36+
}
37+
return lastGuess;
38+
}
39+
40+
public byte[] createdIncrementedAtPosition(byte[] array, int position) {
41+
if (array.length > position) {
42+
array[position] = (byte) (array[position] + 1);
43+
if (array[position] == 0) {
44+
return createdIncrementedAtPosition(array, position + 1);
45+
}
46+
return array;
47+
} else {
48+
return null;
49+
}
50+
}
51+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.bruteforce;
10+
11+
import de.rub.nds.modifiablevariable.util.ArrayConverter;
12+
import java.io.BufferedReader;
13+
import java.io.IOException;
14+
import java.io.InputStream;
15+
import java.io.InputStreamReader;
16+
17+
public class WordListGuessProvider extends GuessProvider {
18+
19+
private final BufferedReader bufferedReader;
20+
21+
public WordListGuessProvider(InputStream stream) {
22+
super(GuessProviderType.WORDLIST);
23+
bufferedReader = new BufferedReader(new InputStreamReader(stream));
24+
}
25+
26+
@Override
27+
public byte[] getGuess() {
28+
try {
29+
String line = bufferedReader.readLine();
30+
if (line == null) {
31+
return null;
32+
}
33+
return ArrayConverter.hexStringToByteArray(line);
34+
} catch (IOException ex) {
35+
return null;
36+
}
37+
}
38+
}

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

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,92 @@
1010

1111
import com.beust.jcommander.ParametersDelegate;
1212
import com.beust.jcommander.Parameter;
13+
import de.rub.nds.tlsattacker.attacks.bruteforce.GuessProviderType;
1314
import de.rub.nds.tlsattacker.attacks.config.delegate.AttackDelegate;
15+
import de.rub.nds.tlsattacker.attacks.exception.WordlistNotFoundException;
1416
import de.rub.nds.tlsattacker.core.config.Config;
1517
import de.rub.nds.tlsattacker.core.config.delegate.CiphersuiteDelegate;
16-
import de.rub.nds.tlsattacker.core.config.delegate.ClientDelegate;
1718
import de.rub.nds.tlsattacker.core.config.delegate.GeneralDelegate;
18-
import de.rub.nds.tlsattacker.core.config.delegate.HostnameExtensionDelegate;
19-
import de.rub.nds.tlsattacker.core.config.delegate.ProtocolVersionDelegate;
2019
import de.rub.nds.tlsattacker.core.config.delegate.ServerDelegate;
2120
import de.rub.nds.tlsattacker.core.constants.CipherSuite;
22-
import java.util.LinkedList;
23-
import java.util.List;
21+
import de.rub.nds.tlsattacker.core.constants.ProtocolVersion;
22+
import java.io.File;
23+
import java.io.FileInputStream;
24+
import java.io.FileNotFoundException;
25+
import java.io.InputStream;
2426
import org.apache.logging.log4j.Level;
2527
import org.apache.logging.log4j.core.config.Configurator;
2628

2729
public class PskBruteForcerAttackClientCommandConfig extends AttackConfig {
30+
2831
public static final String ATTACK_COMMAND = "pskbruteforcerclient";
2932

3033
@ParametersDelegate
3134
private ServerDelegate serverDelegate;
3235
@ParametersDelegate
33-
private HostnameExtensionDelegate hostnameExtensionDelegate;
36+
private AttackDelegate attackDelegate;
3437
@ParametersDelegate
3538
private CiphersuiteDelegate ciphersuiteDelegate;
36-
@ParametersDelegate
37-
private ProtocolVersionDelegate protocolVersionDelegate;
38-
@ParametersDelegate
39-
private AttackDelegate attackDelegate;
40-
@Parameter(names = "-usePskTable", description = "Enables the use of the PskTable")
41-
private boolean usePskTable = false;
39+
@Parameter(names = "-guessProviderType", description = "Chooses how the BruteForcer will choose the keys to guess")
40+
private GuessProviderType guessProviderType = GuessProviderType.INCREMENTING;
41+
@Parameter(names = "-guessProviderInputFile", description = "Set the path to an input file which can be used in the guess provider eg. a path to a wordlist")
42+
private String guessProviderInputFile = null;
4243

4344
@Override
4445
public Config createConfig() {
4546
Config config = super.createConfig();
46-
if (ciphersuiteDelegate.getCipherSuites() == null) {
47-
List<CipherSuite> cipherSuites = new LinkedList<>();
48-
cipherSuites.add(CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA);
49-
config.setDefaultClientSupportedCiphersuites(cipherSuites);
50-
}
5147
config.setQuickReceive(true);
5248
config.setEarlyStop(true);
49+
5350
return config;
5451
}
5552

5653
public PskBruteForcerAttackClientCommandConfig(GeneralDelegate delegate) {
5754
super(delegate);
5855
serverDelegate = new ServerDelegate();
59-
hostnameExtensionDelegate = new HostnameExtensionDelegate();
60-
ciphersuiteDelegate = new CiphersuiteDelegate();
61-
protocolVersionDelegate = new ProtocolVersionDelegate();
6256
attackDelegate = new AttackDelegate();
57+
ciphersuiteDelegate = new CiphersuiteDelegate();
6358
addDelegate(serverDelegate);
64-
addDelegate(hostnameExtensionDelegate);
65-
addDelegate(ciphersuiteDelegate);
66-
addDelegate(protocolVersionDelegate);
6759
addDelegate(attackDelegate);
60+
addDelegate(ciphersuiteDelegate);
61+
62+
if (delegate.getLogLevel() != Level.ALL && delegate.getLogLevel() != Level.TRACE) {
63+
Configurator.setAllLevels("de.rub.nds.tlsattacker.core", Level.ERROR);
64+
}
6865
}
6966

7067
@Override
7168
public boolean isExecuteAttack() {
7269
return attackDelegate.isExecuteAttack();
7370
}
7471

75-
public boolean getUsePskTable() {
76-
return usePskTable;
72+
public String getGuessProviderInputFile() {
73+
return guessProviderInputFile;
74+
}
75+
76+
public InputStream getGuessProviderInputStream() {
77+
if (this.guessProviderInputFile == null) {
78+
if (guessProviderType == GuessProviderType.WORDLIST) {
79+
return (PskBruteForcerAttackClientCommandConfig.class.getClassLoader()
80+
.getResourceAsStream("psk_common_passwords.txt"));
81+
} else {
82+
return System.in;
83+
}
84+
} else {
85+
File file = new File(getGuessProviderInputFile());
86+
try {
87+
return new FileInputStream(file);
88+
} catch (FileNotFoundException ex) {
89+
throw new WordlistNotFoundException("Wordlist not found: " + file.getAbsolutePath(), ex);
90+
}
91+
}
92+
}
93+
94+
public GuessProviderType getGuessProviderType() {
95+
return guessProviderType;
96+
}
97+
98+
public void setGuessProviderType(GuessProviderType guessProviderType) {
99+
this.guessProviderType = guessProviderType;
77100
}
78101
}

0 commit comments

Comments
 (0)