Wombat: one more Bleichenbacher attack toolkit Olivier Levillain - - PowerPoint PPT Presentation

wombat one more bleichenbacher attack toolkit
SMART_READER_LITE
LIVE PREVIEW

Wombat: one more Bleichenbacher attack toolkit Olivier Levillain - - PowerPoint PPT Presentation

Wombat: one more Bleichenbacher attack toolkit Olivier Levillain Aina Toky Rasoamanana Tlcom SudParis GreHack 2019 15 novembre 2019 Levillain & Rasoamanana Wombat 1/27 Plan RSA and PKCS#1 v1.5 in a nutshell Bleichenbacher : the


slide-1
SLIDE 1

Wombat: one more Bleichenbacher attack toolkit

Olivier Levillain Aina Toky Rasoamanana

Télécom SudParis

GreHack 2019 15 novembre 2019

Levillain & Rasoamanana Wombat 1/27

slide-2
SLIDE 2

Plan

RSA and PKCS#1 v1.5 in a nutshell Bleichenbacher : the million-message attack Wombat : one more Bleichenbacher toolkit Current results and future work Conclusion

Levillain & Rasoamanana Wombat 2/27

slide-3
SLIDE 3

RSA and PKCS#1 v1.5 in a nutshell

Plan

RSA and PKCS#1 v1.5 in a nutshell Bleichenbacher : the million-message attack Wombat : one more Bleichenbacher toolkit Current results and future work Conclusion

Levillain & Rasoamanana Wombat 3/27

slide-4
SLIDE 4

RSA and PKCS#1 v1.5 in a nutshell

RSA 101

RSA ◮ a pervasive cryptosystem ◮ asymmetric encryption and signature

Levillain & Rasoamanana Wombat 4/27

slide-5
SLIDE 5

RSA and PKCS#1 v1.5 in a nutshell

RSA 101

RSA ◮ a pervasive cryptosystem ◮ asymmetric encryption and signature Details ◮ public key n = p · q, e ◮ private key d ◮ raw encryption : C = Me[n] ◮ raw decryption : Cd = Med = M[n]

Levillain & Rasoamanana Wombat 4/27

slide-6
SLIDE 6

RSA and PKCS#1 v1.5 in a nutshell

RSA 101

RSA ◮ a pervasive cryptosystem ◮ asymmetric encryption and signature Details ◮ public key n = p · q, e ◮ private key d ◮ raw encryption : C = Me[n] ◮ raw decryption : Cd = Med = M[n] Problems with raw RSA operations ◮ if e and M are small ◮ malleability w.r.t. the multiplication

Levillain & Rasoamanana Wombat 4/27

slide-7
SLIDE 7

RSA and PKCS#1 v1.5 in a nutshell

The need for a padding scheme

We thus need to format the message before encrypting (or signing) it ◮ PKCS#1 standardize how to use RSA ◮ in particular, the document defines different padding scheme

Levillain & Rasoamanana Wombat 5/27

slide-8
SLIDE 8

RSA and PKCS#1 v1.5 in a nutshell

The need for a padding scheme

We thus need to format the message before encrypting (or signing) it ◮ PKCS#1 standardize how to use RSA ◮ in particular, the document defines different padding scheme In this talk, we are most interested in padding type 2, described in version 1.5 of the standard, and used for encryption : ← − − − − − − − − − − − − − − − − − − − − n bytes − − − − − − − − − − − − − − − − − − − − → 00 02 non zero random bytes 00 Encapsulated data ← − − − 8+ bytes − − − →

Levillain & Rasoamanana Wombat 5/27

slide-9
SLIDE 9

RSA and PKCS#1 v1.5 in a nutshell

Other padding schemes

PKCS#1 v1.5 also describes two other schemes, which are deterministic ◮ padding type 0 (zero bytes, rarely used) ◮ padding type 1 (ff bytes, used for signature) PKCS#1 v2.1 ◮ OAEP (Optimal Asymmetric Encryption Padding) for encryption ◮ PSS (Probabilistic Signature Scheme) for signature ◮ these schemes have better security properties... ◮ ... but are not always used in standards

Levillain & Rasoamanana Wombat 6/27

slide-10
SLIDE 10

Bleichenbacher : the million-message attack

Plan

RSA and PKCS#1 v1.5 in a nutshell Bleichenbacher : the million-message attack Wombat : one more Bleichenbacher toolkit Current results and future work Conclusion

Levillain & Rasoamanana Wombat 7/27

slide-11
SLIDE 11

Bleichenbacher : the million-message attack

An observation about padding type 2

← − − − − − − − − − − − − − − − − − − − − n bytes − − − − − − − − − − − − − − − − − − − − → 00 02 non zero random bytes 00 Encapsulated data ← − − − 8+ bytes − − − →

Levillain & Rasoamanana Wombat 8/27

slide-12
SLIDE 12

Bleichenbacher : the million-message attack

An observation about padding type 2

← − − − − − − − − − − − − − − − − − − − − n bytes − − − − − − − − − − − − − − − − − − − − → 00 02 non zero random bytes 00 Encapsulated data ← − − − 8+ bytes − − − → With a correctly formated message to be encrypted ◮ the raw plaintext M starts with 00 02 ◮ interpreted as an integer, this means that M is an integer between 2B and 3B

◮ with B = 2(|n|−16) ◮ where |n| is the size of the modulus n in bits

Levillain & Rasoamanana Wombat 8/27

slide-13
SLIDE 13

Bleichenbacher : the million-message attack

Attack principle (CRYPTO 1998)

We assume there exists an oracle which ◮ accepts to decrypt messages ◮ returns true when the padding was correct, false otherwise ◮ (the decrypted message will be kept secret)

Levillain & Rasoamanana Wombat 9/27

slide-14
SLIDE 14

Bleichenbacher : the million-message attack

Attack principle (CRYPTO 1998)

We assume there exists an oracle which ◮ accepts to decrypt messages ◮ returns true when the padding was correct, false otherwise ◮ (the decrypted message will be kept secret) An attacker wishing to recover m = cd can then ◮ send altered messages c · se (with s known) ◮ let the server handle (c · se)d = cd · sed = ms ◮ infer that 2B ≤ ms < 3B in case the oracle returns true ◮ repeat the operations, and recover m with these equations ◮ (this is an adaptive chosen ciphertext attack)

Levillain & Rasoamanana Wombat 9/27

slide-15
SLIDE 15

Bleichenbacher : the million-message attack

Different oracle types (1/2)

In practice, the attacker wants to find messages starting with 00 02

Levillain & Rasoamanana Wombat 10/27

slide-16
SLIDE 16

Bleichenbacher : the million-message attack

Different oracle types (1/2)

In practice, the attacker wants to find messages starting with 00 02 ← − − − − − − − − − − − − − − − − − − − − n bytes − − − − − − − − − − − − − − − − − − − − → 00 02 non zero random bytes 00 Encapsulated data ← − − − 8+ bytes − − − → However, some oracles also make additional checks ◮ the padding contains at least 8 bytes ◮ the padding ends with a null byte ◮ the message obtained has the expected length

Levillain & Rasoamanana Wombat 10/27

slide-17
SLIDE 17

Bleichenbacher : the million-message attack

Different oracle types (2/2)

If we assume an oracle returning true only for messages ◮ starting with 00 02 ◮ where the padding contains at least 8 bytes ◮ and where the padding ends The attacker thus loses good messages (starting with 00 02) which would have led to interesting equations

Levillain & Rasoamanana Wombat 11/27

slide-18
SLIDE 18

Bleichenbacher : the million-message attack

Different oracle types (2/2)

If we assume an oracle returning true only for messages ◮ starting with 00 02 ◮ where the padding contains at least 8 bytes ◮ and where the padding ends The attacker thus loses good messages (starting with 00 02) which would have led to interesting equations Bardou et al. proposed a classification where each oracle type depends on the messages an attacker can distinguish

Levillain & Rasoamanana Wombat 11/27

slide-19
SLIDE 19

Bleichenbacher : the million-message attack

Results from Bardou et al.

The article, published at CRYPTO 2012, improved the original algorithms (CRYPTO 1998) Oracle Average nb of requests type Original algo Improved algo FFF

  • 18 040 221

FFT 215 982 49 001 FTT 159 334 39 649 TFT 39 536 10 295 TTT 38 625 9 374

Levillain & Rasoamanana Wombat 12/27

slide-20
SLIDE 20

Wombat : one more Bleichenbacher toolkit

Plan

RSA and PKCS#1 v1.5 in a nutshell Bleichenbacher : the million-message attack Wombat : one more Bleichenbacher toolkit Current results and future work Conclusion

Levillain & Rasoamanana Wombat 13/27

slide-21
SLIDE 21

Wombat : one more Bleichenbacher toolkit

A modular way to implement the attack (1/2)

To test an implementation, we write a stub, which allows ◮ to get the RSA public key ◮ to get a challenge (an encrypted message) ◮ to submit messages to be decrypted

Levillain & Rasoamanana Wombat 14/27

slide-22
SLIDE 22

Wombat : one more Bleichenbacher toolkit

A modular way to implement the attack (1/2)

To test an implementation, we write a stub, which allows ◮ to get the RSA public key ◮ to get a challenge (an encrypted message) ◮ to submit messages to be decrypted The attacker can submit messages for which the plaintext is known, and assess the oracle type ◮ well formed messages ◮ messages not starting with 00 02 ◮ messages with a short padding ◮ messages with an unending padding

Levillain & Rasoamanana Wombat 14/27

slide-23
SLIDE 23

Wombat : one more Bleichenbacher toolkit

A modular way to implement the attack (2/2)

If the attacker can identify good messages by observing the implementation behaviour, an oracle has been identified The attacker can then ◮ evaluate more precisely the cost of the attack ◮ attack the implementation to recover the plaintext corresponding to the challenge ◮ use the oracle to forge a signature

Levillain & Rasoamanana Wombat 15/27

slide-24
SLIDE 24

Wombat : one more Bleichenbacher toolkit

A modular way to implement the attack (2/2)

If the attacker can identify good messages by observing the implementation behaviour, an oracle has been identified The attacker can then ◮ evaluate more precisely the cost of the attack ◮ attack the implementation to recover the plaintext corresponding to the challenge ◮ use the oracle to forge a signature wombat currently implements ◮ the original attack from Daniel Bleichenbacher ◮ improved versions of the attack (Bardou et al.) ◮ pure oracles to validate the attacks ◮ a TLS stub TLS (more on this later)

Levillain & Rasoamanana Wombat 15/27

slide-25
SLIDE 25

Wombat : one more Bleichenbacher toolkit

An open-source framework

Wombat ◮ tool developed in Python during an internship ◮ version 0.1 published in September ◮ https://gitlab.com/pictyeye/wombat

Levillain & Rasoamanana Wombat 16/27

slide-26
SLIDE 26

Wombat : one more Bleichenbacher toolkit

An open-source framework

Wombat ◮ tool developed in Python during an internship ◮ version 0.1 published in September ◮ https://gitlab.com/pictyeye/wombat Possible usages ◮ help identifying existing oracles ◮ mount attacks (with respect to the law and morality) ◮ mount hands-on sessions in classes (a simple TCP server is provided)

Levillain & Rasoamanana Wombat 16/27

slide-27
SLIDE 27

Current results and future work

Plan

RSA and PKCS#1 v1.5 in a nutshell Bleichenbacher : the million-message attack Wombat : one more Bleichenbacher toolkit Current results and future work Conclusion

Levillain & Rasoamanana Wombat 17/27

slide-28
SLIDE 28

Current results and future work

Application to TLS (1/3)

Client Server C l i e n t H e l l

  • S

e r v e r H e l l

  • C

e r t i f i c a t e S e r v e r H e l l

  • D
  • n

e C l i e n t K e y E x c h a n g e C h a n g e C i p h e r S p e c F i n i s h e d C h a n g e C i p h e r S p e c F i n i s h e d Application data

Levillain & Rasoamanana Wombat 18/27

slide-29
SLIDE 29

Current results and future work

Application to TLS (1/3)

Client Server C l i e n t H e l l

  • S

e r v e r H e l l

  • C

e r t i f i c a t e S e r v e r H e l l

  • D
  • n

e C l i e n t K e y E x c h a n g e C h a n g e C i p h e r S p e c F i n i s h e d C h a n g e C i p h e r S p e c F i n i s h e d Application data

Levillain & Rasoamanana Wombat 18/27

slide-30
SLIDE 30

Current results and future work

Application to TLS (1/3)

Client Server C l i e n t H e l l

  • S

e r v e r H e l l

  • C

e r t i f i c a t e S e r v e r H e l l

  • D
  • n

e C l i e n t K e y E x c h a n g e C h a n g e C i p h e r S p e c F i n i s h e d C h a n g e C i p h e r S p e c F i n i s h e d Application data

Levillain & Rasoamanana Wombat 18/27

slide-31
SLIDE 31

Current results and future work

Application to TLS (2/3)

We wrote a stub ◮ public key recovery from the server certificate ◮ creation of a target ciphertext (the challenge) including a pre-master-secret ◮ interface to send message to be decrypted to the TLS server

◮ first messages to force the use of RSA key exchange ◮ emission of the ClientKeyExchange including the encrypted message to test ◮ observation of the server reaction (received messages, delay before an answer)

Identification and exploitation of an oracle

Levillain & Rasoamanana Wombat 19/27

slide-32
SLIDE 32

Current results and future work

Application to TLS (3/3)

We added the vulnerability to mbedtls (the actual implementation is very robust, including against timing attacks)

+ // DON’T DO THIS AT HOME + if (ret == MBEDTLS_ERR_RSA_INVALID_PADDING) { + mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, + MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR ); + return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE); + }

Levillain & Rasoamanana Wombat 20/27

slide-33
SLIDE 33

Current results and future work

Application to TLS (3/3)

We added the vulnerability to mbedtls (the actual implementation is very robust, including against timing attacks)

+ // DON’T DO THIS AT HOME + if (ret == MBEDTLS_ERR_RSA_INVALID_PADDING) { + mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL, + MBEDTLS_SSL_ALERT_MSG_DECRYPT_ERROR ); + return (MBEDTLS_ERR_SSL_BAD_HS_CLIENT_KEY_EXCHANGE); + }

Demo time

Levillain & Rasoamanana Wombat 20/27

slide-34
SLIDE 34

Current results and future work

Real-life tests on TLS

We believed that explicit Bleichenbacher oracles in TLS stacks were something from the past...

Levillain & Rasoamanana Wombat 21/27

slide-35
SLIDE 35

Current results and future work

Real-life tests on TLS

We believed that explicit Bleichenbacher oracles in TLS stacks were something from the past...

% python example_BB_TLS_prober.py <tested-server> Explicit oracle found (type FFT) true-signal: set([(False, 21, 51), TLSHandshakeFailed()]) false-signal: set([(False, None, None), (False, 21, 20)])

Levillain & Rasoamanana Wombat 21/27

slide-36
SLIDE 36

Current results and future work

Real-life tests on TLS

We believed that explicit Bleichenbacher oracles in TLS stacks were something from the past...

% python example_BB_TLS_prober.py <tested-server> Explicit oracle found (type FFT) true-signal: set([(False, 21, 51), TLSHandshakeFailed()]) false-signal: set([(False, None, None), (False, 21, 20)])

And interestingly, <tested-server> is from Top Alexa 1M !

Levillain & Rasoamanana Wombat 21/27

slide-37
SLIDE 37

Current results and future work

Future work on TLS

Improve the TLS prober to be more reliable and more precise ◮ improve the interpretation of timing distributions ◮ handle more messages from the server behaviour (TCP errors for example) ◮ use different message sequences to trigger a reaction from the server

Levillain & Rasoamanana Wombat 22/27

slide-38
SLIDE 38

Current results and future work

Future work on TLS

Improve the TLS prober to be more reliable and more precise ◮ improve the interpretation of timing distributions ◮ handle more messages from the server behaviour (TCP errors for example) ◮ use different message sequences to trigger a reaction from the server Launch campaigns to identify potential oracles in a more systematic way ◮ regular HTTPS Top Alexa 1M scans ◮ SMTP servers (where we usually find obsolete software)

Levillain & Rasoamanana Wombat 22/27

slide-39
SLIDE 39

Current results and future work

Future work on TLS

Improve the TLS prober to be more reliable and more precise ◮ improve the interpretation of timing distributions ◮ handle more messages from the server behaviour (TCP errors for example) ◮ use different message sequences to trigger a reaction from the server Launch campaigns to identify potential oracles in a more systematic way ◮ regular HTTPS Top Alexa 1M scans ◮ SMTP servers (where we usually find obsolete software) Implement more sophisticated attacks such as DROWN or TLS 1.3/QUIC signature forgery

Levillain & Rasoamanana Wombat 22/27

slide-40
SLIDE 40

Current results and future work

Other applications

PKCS#1 is present in other standards ◮ XML Encryption ◮ SSH (RFC 4432) ◮ OpenPGP

Levillain & Rasoamanana Wombat 23/27

slide-41
SLIDE 41

Current results and future work

Other applications

PKCS#1 is present in other standards ◮ XML Encryption (proposed to students) ◮ SSH (RFC 4432) ◮ OpenPGP

Levillain & Rasoamanana Wombat 23/27

slide-42
SLIDE 42

Current results and future work

Other applications

PKCS#1 is present in other standards ◮ XML Encryption (proposed to students) ◮ SSH (RFC 4432 uses OAEP) ◮ OpenPGP

Levillain & Rasoamanana Wombat 23/27

slide-43
SLIDE 43

Current results and future work

Preliminary results on gpg

Setup ◮ an RSA key used for encryption ◮ an encrypted message ◮ altered versions of the encrypted messages

Levillain & Rasoamanana Wombat 24/27

slide-44
SLIDE 44

Current results and future work

Preliminary results on gpg

Setup ◮ an RSA key used for encryption ◮ an encrypted message ◮ altered versions of the encrypted messages Decryption time...

Levillain & Rasoamanana Wombat 24/27

slide-45
SLIDE 45

Current results and future work

Preliminary results on gpg

Setup ◮ an RSA key used for encryption ◮ an encrypted message ◮ altered versions of the encrypted messages Decryption time... ◮ correct format : Invalid cipher algorithm or decryption ◮ padding too short : Invalid cipher algorithm ◮ invalid first bytes : Wrong secret key used ◮ message is only padding : Wrong secret key used It is an FTT oracle ! Hopefully it is rare to be able to submit encrypted files to OpenPGP and observe the error messages.

Levillain & Rasoamanana Wombat 24/27

slide-46
SLIDE 46

Conclusion

Plan

RSA and PKCS#1 v1.5 in a nutshell Bleichenbacher : the million-message attack Wombat : one more Bleichenbacher toolkit Current results and future work Conclusion

Levillain & Rasoamanana Wombat 25/27

slide-47
SLIDE 47

Conclusion

Conclusion

The so-called million-message attack from Bleichenbacher ◮ an attack well known for a long time ◮ a non trivial example to teach cryptographic attacks ◮ still a reality today ? Wombat ◮ an open source tool to test the attack ◮ helpful to reproduce existing attacks ◮ extensible via stubs to analyse other standards ◮ useful for hands-on sessions with students

Levillain & Rasoamanana Wombat 26/27

slide-48
SLIDE 48

Questions ?

Thank you for your attention

https://paperstreet.picty.org/yeye https://gitlab.com/pictyeye/wombat