Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security...

61
Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor BME Hálózati Rendszerek és Szolgáltatások Tanszék Lab of Cryptography and System Security (CrySyS) [email protected], [email protected]

Transcript of Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security...

Page 1: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS)

Cryptographic Protocols (EIT ICT MSc)

Dr. Levente Buttyánassociate professor

BME Hálózati Rendszerek és Szolgáltatások TanszékLab of Cryptography and System Security (CrySyS)

[email protected], [email protected]

Page 2: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 2© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Outline

- architecture and services- TLS Record Protocol- TLS Handshake Protocol- analysis and some potential attacks

Page 3: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 3© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

TLS – Transport Layer Security

� objective• to provide a secure transport connection between applications

(typically between a web server and a browser � https)• mutual authentication of parties• encryption, integrity and replay protection of all exchanged

messages

� history• SSL – Secure Socket Layer

• developed by Netscape in the mid 90’s• version 3.0 has been implemented in many web browsers and

web servers and become a de-facto standard• the IETF adopted it in 1999 under the name TLS

• TLS v1.0 ~ SSL v3.0 with some design errors corrected• further modifications due to some recent attacks � v1.1 � v1.2 • most recent specification is RFC 5746

Page 4: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 4© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

TLS architecture

TLS Record Protocol

TLSHandshake

Protocol

TLS ChangeCipher Spec

Protocol

TLSAlert

Protocol

applications(e.g., HTTP)

TCP

IP

Page 5: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 5© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

TLS components� TLS Handshake Protocol

• negotiation of security algorithms and parameters• key exchange• server authentication and optionally client authentication

� TLS Record Protocol• fragmentation• compression• message authentication and integrity protection• encryption

� TLS Alert Protocol• error messages (fatal alerts and warnings)

� TLS Change Cipher Spec Protocol• a single message that indicates the end of the TLS handshake

Page 6: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 6© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Sessions and connections

� a TLS session is a security association between a client and a server� sessions are stateful; the session state includes:

• the negotiated security algorithms and parameters • certificates (if any)• a master secret shared between the client and the server

(established during the TLS handshake)

� a session may include multiple secure connections between the same client and server• connections of the same session share the session state• in addition, each connection has its own connection keys (derived

from the master secret) and connection specific random numbers� factoring out the master secret into the session state helps to avoid

expensive negotiation of new security parameters for each and every new connection

Page 7: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 7© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

TLS Record Protocol

MAC:• computed before the encryption• input to MAC computation:

• MAC_write_key• seq_num || type || version || length || payload (compressed fragment)

• supported algorithms: HMAC with MD5, SHA1, SHA256

p.lenpadding

application data

MAC

type version length

encrypted payload (confidentiality)

Message Authentication Code(authentication, integrity, and replay protection)

IV IV, if sent explicitly

Page 8: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 8© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Encryption in the Record Protocol� stream ciphers

• no IV and padding• no re-initialization of the cipher for individual messages• supported algorithm: RC4 (128)

� block ciphers in CBC mode• IV must be a random value (in TLSv1.0, IV was the last cipher block of the

previous message)• padding:

• last byte is the length n of the padding (not including the last byte)• padding length n can range from 0 to 255 bytes, but the total length of the

encrypted text must be a multiple of the block size of the cipher• all padding bytes have value n � examples for correct padding: x00,

x01x01, x02x02x02, …• after decryption, the padding format is verified; if correct, then MAC

verification follows• supported algorithms: 3DES-EDE, AES (128, 256)

Page 9: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 9© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Auth -enc in the Record Protocol� authenticated encryption modes

• nonce is carried in the IV field, no padding• jointly encrypted and authenticated message is computed from

• client_ or server_write_key• nonce• cleartext payload• seq_num || type || version || length

• supported algorithms: AES-GCM (128, 256), AES-CCM (128, 256)

Page 10: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 10© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

TLS Alert Protocol� each alert message consists of 2 fields (bytes)� first field (byte): “warning” or “fatal”� second field (byte):

• fatal• unexpected_message• bad_record_MAC• decryption_failure (!)• handshake_failure• …

• warning• close_notify• user_canceled • no_renegotiation• …

� in case of a fatal alert• connection is terminated• session ID is invalidated � no new connection can be established within

this session

Page 11: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 11© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

TLS Handshake – overview client server

client_hello

server_hello

certificate

server_key_exchange

certificate_request

server_hello_done

certificate

client_key_exchange

certificate_verify

(change_cipher_spec)

finished

(change_cipher_spec)

finished

Phase 1: Negotiation of the session ID, key exchange algorithm, MAC algorithm, encryption algorithm, and exchange of initial random numbers

Phase 2: Server may send its certificate and keyexchange message, and it may request the clientto send a certificate. Server signals end of hellophase.

Phase 3: Client sends certificate if requested and may send an explicit certificate verification message. Client always sends its key exchange message.

Phase 4: Change cipher spec and finish handshake

Page 12: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 12© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Hello messages� version

• the highest TLS version supported by the party� random

• current time (4 bytes) + pseudo random bytes (28 bytes)� session_id

• if a new session is opened:• session_id of client_hello is empty• session_id of server_hello is the new session ID

• if a new connection is created in an existing session:• session_id of client_hello is the session ID of the existing session• session_id of server_hello is the existing session ID if the connection

can be created or empty otherwise� cipher_suites

• in client_hello: list of cipher suites supported by the client ordered by preference

• in server_hello: selected cipher suite• a cipher suite contains the specification of the key exchange method, the

encryption algorithm, and the MAC algorithm• exmaple: TLS_RSA_with_AES_128_CBC_SHA

Page 13: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 13© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Supported key exchange methods� RSA based (TLS_RSA_with...)

• the secret key (pre-master secret) is encrypted with the server’s public RSA key

• the server’s public key is made available to the client during the exchange � fixed Diffie-Hellman (TLS_DH_RSA_with… or TLS_DH_DSS_with…)

• the server has fix DH parameters contained in a certificate signed by a CA• the client may have fix DH parameters certified by a CA or it may send an

unauthenticated one-time DH public value in the client_key_exchange message

� ephemeral Diffie-Hellman (TLS_DHE_RSA_with… or TLS_DHE_DSS_with…)• both the server and the client generate one-time DH parameters • the server signs its DH parameters with its private RSA or DSS key• the client sends an unauthenticated one-time DH public value in the

client_key_exchange message • the client may authenticate itself (if requested by the server) by signing the

hash of the handshake messages with its private RSA or DSS key� anonymous Diffie-Hellman (TLS_DH_anon_with…)

• both the server and the client generate one-time DH parameters• they send their parameters to the peer without authentication

Page 14: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 14© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Server certificate and key exchange� certificate

• required for every key exchange method except for anonymous DH• contains one or a chain of X.509 certificates (up to a known root CA)• may contain

• public RSA key suitable for encryption, or• public RSA or DSS key suitable for signing only, or• fix DH parameters

� server_key_exchange• sent only if the certificate does not contain enough information to

complete the key exchange (e.g., the certificate contains an RSA signing key only)

• may contain• public RSA key (exponent and modulus), or• DH parameters (p, g, public DH value)

• digitally signed

Page 15: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 15© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Cert request and server hello done

� certificate_request• sent if the client needs to authenticate itself• specifies which type of certificate is requested

� server_hello_done• sent to indicate that the server is finished its part of the key

exchange• after sending this message the server waits for client response• the client should verify that the server provided a valid certificate

and the server parameters are acceptable

Page 16: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 16© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Client auth and key exchange

� certificate• sent only if requested by the server

� client_key_exchange• always sent• may contain

• RSA encrypted pre-master secret, or• client one-time public DH value

� certificate_verify• sent only if the client sent a certificate• provides client authentication• contains signed hash of all the previous handshake messages from

client_hello up to this message

Page 17: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 17© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Finished messages

� finished• sent immediately after the change_cipher_spec message• used to authenticate all previous handshake messages• first message that uses the newly negotiated algorithms and

keys• computed with a pseudo-random function (see definition later)

from the master secret and the hash of all handshake messages

PRF( master_secret, “client finished”, hash(handshake_messages) ) � 12 bytes

PRF( master_secret, “server finished”, hash(handshake_messages) ) � 12 bytes

Page 18: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 18© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

The pseudo -random function PRF

� PRF(secret, label, seed) = P_hash(secret, label || seed)

� P_hash(secret, seed) = HMAC_hash( secret, A(1) || seed ) ||HMAC_hash( secret, A(2) || seed ) ||HMAC_hash( secret, A(3) || seed ) ||…

where A(0) = seedA(i) = HMAC_hash(secret, A(i-1))

Page 19: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 19© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

P_hash illustrated

HMACsecret

|| seed

HMACsecret

A(1)

seed

HMACsecret

|| seed

HMACsecret

A(2)

HMACsecret

|| seed

HMACsecret

A(3) …

Page 20: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 20© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Key generation

� master secret: PRF( pre_master_secret,

“master secret”, client_random || server_random ) � 48 bytes

� connection keys:• key block:

PRF( master_secret, “key expansion”, server_random || client_random ) � as many bytes as needed

• key block is then partitioned:client_write_MAC_key || server_write_MAC_key || client_write_key || server_write_key || client_write_IV || server_write_IV

Page 21: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 21© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Key exchange alternatives

� RSA / no client authentication• server sends its encryption capable RSA public key in

server_certificate• server_key_exchange is not sent• client sends encrypted pre-master secret in client_key_exchange• client_certificate and certificate_verify are not sentor• server sends its RSA or DSS public signature key in

server_certificate• server sends a temporary RSA public key in server_key_exchange• client sends encrypted pre-master secret in client_key_exchange• client_certificate and certificate_verify are not sent

Page 22: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 22© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Key exchange alternatives (cont’d)

� RSA / client is authenticated• server sends its encryption capable RSA public key in

server_certificate• server_key_exchange is not sent• client sends its RSA or DSS public signature key in client_certificate• client sends encrypted pre-master secret in client_key_exchange• client sends signature on all previous handshake messages in

certificate_verifyor• server sends its RSA or DSS public signature key in

server_certificate• server sends a one-time RSA public key in server_key_exchange• client sends its RSA or DSS public signature key in client_certificate• client sends encrypted pre-master secret in client_key_exchange• client sends signature on all previous handshake messages in

certificate_verify

Page 23: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 23© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Key exchange alternatives (cont’d)

� fix DH / no client authentication• server sends its fix DH parameters in server_certificate• server_key_exchange is not sent• client sends its one-time DH public value in client_key_exchange• client_ certificate and certificate_verify are not sent

� fix DH / client is authenticated• server sends its fix DH parameters in server_certificate• server_key_exchange is not sent• client sends its fix DH parameters in client_certificate• client_key_exchange is sent but empty• certificate_verify is not sent

Page 24: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 24© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Key exchange alternatives (cont’d)� ephemeral DH / no client authentication

• server sends its RSA or DSS public signature key in server_certificate

• server sends signed one-time DH parameters in server_key_exchange

• client sends one-time DH public value in client_key_exchange• client_certificate and certificate_verify are not sent

� ephemeral DH / client is authenticated• server sends its RSA or DSS public signature key in

server_certificate• server sends signed one-time DH parameters in

server_key_exchange • client sends its RSA or DSS public signature key in client_certificate• client sends one-time DH public value in client_key_exchange• client sends signature on all previous handshake messages in

certificate_verify

Page 25: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 25© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Key exchange alternatives (cont’d)

� anonymous DH / no client authentication• server_certificate is not sent• server sends (unsigned) one-time DH parameters in

server_key_exchange• client sends one-time DH public value in client_key_exchange• client_certificate and certificate_verify are not sent

� anonymous DH / client is authenticated• not allowed

Page 26: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Analysis and attacks

Transport Layer Security (TLS) 26© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 27: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

SSL/TLS Handshake protocol

� Cipher suite rollback attack� Dropping the Change_Cipher_Spec message� Key exchange algorithm rollback� Version rollback

Reference:D. Wagner, B. Schneier. Analysis of the SSL 3.0 protocol, November 1996.

Transport Layer Security (TLS) 27© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 28: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 28© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Cipher suite rollback attack

� in SSL 2.0, an attacker could force the use of an export-weakened encryption algorithm by modifying the list of supported cipher suites in the hello messages

� this is prevented in TLS (and SSL 3.0) by authenticating all handshake messages with the master secret (in the finished messages)

� the master secret itself is authenticated by other means• for the client:

• implicit authentication via the server certificate– only the server could decrypt the RSA encrypted pre-master secret– only the server could compute the pre-master secret from the client’s public DH value

• explicit authentication via the server_key_exchange message (if sent)– ephemeral parameters are explicitly signed by the server

• for the server:• explicit authentication via the certificate_verify message (if sent)

– certificate_verify contains a signed hash of all previous handshake messages including those that contain the key exchange parameters used to compute the master secret

Page 29: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 29© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Dropping change_cipher_spec� authentication in the finished message does not protect the

change_cipher_spec message (it is not part of the handshake protocol !)� this may allow the following attack:

• assume that the negotiated cipher suite includes only message authentication (no encryption)

change_cipher_spec

finishedC, mack1(finishedC)finishedC

change_cipher_spec

finishedS, mack2(finishedS)finishedS

data, mack1(data)modified data

man-in-the-middle

sending stateis updated

serverclient first 3 phases of the handshake:setup of MAC secrets k1 and k2

sending stateis updated

receiving stateis not updated:

finishS isaccepted

receiving stateis not yet updated:finishC is accepted

Page 30: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 30© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Dropping the change_cipher_spec

� if the negotiated cipher suite includes encryption, then the attackdoesn’t work• client sends encrypted finished message• server expects clear finished message• the attacker cannot decrypt the encrypted finished message

� the attack is prevented in TLS by requiring reception of change_cipher_spec before processing the finished message• this seems to be obvious, but…• even Netscape’s reference SSL implementation SSLRef 3.0b1

allowed for processing finished messages without checking if a change_cipher_spec has been received

� another possible fix: include the change_cipher_spec message in the computation of the finished message• for some reason, this approach has not been adopted

Page 31: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 31© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Key-exchange algorithm rollbackserverclient man-in-the-middle

client_hello: SSL_RSA_...

client_hello: SSL_DHE_...

server_hello: SSL_DHE_...

server_hello: SSL_RSA_...

server_key_exchange: p, g, gy mod p, signature

server_key_exchange: p, g, gy mod p, signature

certificate: server signing key certificate: server signing key

RSA modulus = pRSA exponent = g client_key_exchange:

secg mod p client_key_exchange: gx mod p

sec’ = (gx)y mod p

recover sec by computing g-th root

(this is easy since p is prime)

compute sec’ as (gy)x mod p

finished: { hash(msgs’, sec), macsec(…) }sec

finished: { hash(msgs, sec’), macsec’(…) }sec’

Page 32: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 32© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Key-exchange algorithm rollback

� TLS/SSL authenticates only the server’s (RSA or DH) parameters in the server_key_exchange message

� it doesn’t authenticate the context (key exchange algorithm in use) in which those parameters should be interpreted

� a fix: • hash all messages exchanged before the

server_key_exchange message and include the hash in the signature in the server_key_exchange message

Page 33: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 33© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Version rollback attacks� on some servers, SSL 2.0 may still be supported� an attacker may change the client_hello message so that it looks like an SSL

2.0 client_hello� as a result the client and the server will run SSL 2.0� SSL 2.0 has serious security flaws

• among other things, there are no finished messages to authenticate the handshake

• the version rollback attack will go undetected

� fortunately, TLS and SSL 3.0 can detect version rollback• pre-master secret generated on SSL 3.0 enabled clients:

struct{

ProtocolVersion client_version; // latest version supported by the client

opaque random[46]; // random bytes

} PreMasterSecret;

• an SSL 3.0 enabled server detects the version rollback attack, when it runs an SSL 2.0 handshake but receives a pre-master secret that includes version 3.0 as the latest version supported by the client

Page 34: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

SSL/TLS Record protocol

� A distingushing attack� Padding oracle attack� Lucky 13 attack� BEAST attack

References:S. Vaudenay. Security Flaws Induced by CBC Padding – Applicationsto SSL, IPSEC, WTLS ... EUROCRYPT 2002.B. Canvel, A. P. Hiltgen, S. Vaudenay, and M. Vuagnoux. Password Interception in a SSL/TLS Channel. CRYPTO 2003.N. J. AlFardan, K. G. Paterson. Lucky 13: Breaking the TLS and DTLS Record Protocols. February 27, 2013.T. Duong and J. Rizzo. Here come the XOR Ninjas. Unpublishedmanuscript, 2011.

Transport Layer Security (TLS) 34© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 35: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 35© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Reminder on HMACHMACk(x) = H( (k+ ⊕opad) | H( (k+ ⊕ ipad) | x ) )

where• h is a hash function with input block size b and output size n• k+ is k padded with 0s to obtain a length of b bits• ipad is 00110110 repeated b/8 times• opad is 01011100 repeated b/8 times

k+ ⊕ ipad

CV0

f

x1

f

xL|padding1

fCV1

inner

k+ ⊕ opad

CV0

f

M|padding2

fCV1

outerHMACk(x)

H

H

Page 36: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Hash functions used by HMAC in TLS

� MD5, SHA1, SHA256

� block size for all of these is 512 bits = 64 bytes� padding for hashing

• 8-byte message length field (Merkle-Damgard strengthening)• followed by at least 1 byte of padding

� key observation:• if message length < 56 bytes

• then message + 8 byte length + padding fits in a single 64-byte block

• hashing needs 4 invocations of the compression function f• if message length > 55 bytes

• then padded message needs at least two 64-byte blocks• hashing needs at least 5 invocations of f

• this is a timing channel!

Transport Layer Security (TLS) 36© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 37: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

A distinguishing attack

� abstract description• the attacker chooses a pair of messages (M0, M1) of equal length• one of these is encrypted and given back to the attacker• the attacker must tell which message was encrypted (can use a

decryption oracle)

� particular parameters in case of TLS• encryption is AES in CBC mode (enc block size is 16 bytes)• MAC and padding (in this order) before encryption

• let the MAC be HMAC with SHA1 (20 bytes)• TLS Record header (5 bytes)

� let • M0 be 32 arbitrary bytes followed by 256 xFF (max length padding)• M1 be 287 arbitrary bytes followed by a single x00 (min pad)

� note that both messages are 288 bytes long (= 18x16 bytes)

Transport Layer Security (TLS) 37© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 38: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

A distinguishing attack

� after encryption:

� now the attacker removes the part containing the MAC and the padding, and submits the remaining message to a decryption oracle (length field in header is set accordingly)

Transport Layer Security (TLS) 38© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

p.lenpadding

Mi

MAC

type version length

IV

18x16 bytes

Page 39: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

A distinguishing attack� after decryption:

� in case of M0:• xFF xFF ... valid padding � removed• remaining 32 bytes are interpreted as 12-byte message + 20-byte

MAC• MAC is verified on 8-byte sequence number + 5-byte header + 12 byte

message = 25 bytes < 56 bytes � 4 calls to function f

� in case of M1:• x00 valid padding � removed• remaning 287 bytes are interpreted as 267-byte message + 20-byte

MAC• MAC is verified on 8-byte sequence number + 5-byte header + 267-

byte message = 280 bytes � 8 calls to function f

Transport Layer Security (TLS) 39© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

xFF xFF xFF .....

x00

Page 40: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Experimental results

Transport Layer Security (TLS) 40© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 41: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 41© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Padding oracle attack (2002)

� send a random message to a TLS server� the server will drop the message with overwhelming

probability• either the padding is incorrect (the server responds with a

DECRYPTION_FAILED alert)• or the MAC is incorrect with very high probability (the server

responds with BAD_RECORD_MAC alert)

� if the response is BAD_RECORD_MAC, then the padding was correct � we get 1 bit of information !

� such an oracle can be used to decrypt any encrypted message

Page 42: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 42© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Recovering the last byte(s)� assume we have an encrypted block y1y2…y8 = EK(x1x2…x8)� we want to compute x8 (the last byte of x)� idea:

1. choose a random block r1r2…r8; let i = 02. send r1r2…r7(r8⊕i)y1y2…y8 to the server (oracle)3. if there’s a padding error, then increment i and go back to step 24. if there’s no padding error, then r⊕x ends with 0 or 11 or 222 …

• the most likely is that (r8⊕i)⊕x8 = 0, and hence x8 = r8⊕i

DK

r1r2…r7(r8⊕i)

garbage

K

+

DK

y1y2…y8

K

+IVx1x2…x8

(r1⊕x1)(r2⊕x2)…(r8⊕i⊕x8)

Page 43: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 43© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Recovering the last byte(s)� assume we get that x⊕r has a correct padding, but we don’t know if it is 0 or 11

or 222 … � algorithm:

1. let j = 12. change rj and send r1r2…r8y1y2…y8 to the server again3. if the padding is still correct then the j-th byte was not a padding byte;

increment j and go back to step 24. if the padding becomes incorrect then the j-th byte was the first padding

byte; xj ⊕ rj|xj+1 ⊕ rj+1 | … | x8 ⊕ r8 = (8-j) |…| (8-j) and hence xj xj+1 … x8 = rj⊕(8-j) rj+1⊕(8-j) … r8⊕(8-j)

x = DE AD BE EF DE AD BE EFr = 01 23 45 67 DD AE BD EC

r ⊕x = DF 8E FB 88 03 03 03 03

j r r⊕x padding1 00 23 45 67 DD AE BD EC DE 8E FB 88 03 03 03 03 OK2 00 22 45 67 DD AE BD EC DE 8F FB 88 03 03 03 03 OK3 00 22 44 67 DD AE BD EC DE 8F FA 88 03 03 03 03 OK4 00 22 44 66 DD AE BD EC DE 8F FA 89 03 03 03 03 OK5 00 22 44 66 DC AE BD EC DE 8F FA 89 02 03 03 03 ERROR

x5 x6 x7 x8 = DD⊕03 AE ⊕03 BD ⊕03 EC ⊕03 = DE AD BE EF

Page 44: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 44© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Decrypting an entire block� assume we have an encrypted block y1y2…y8 = EK(x1x2…x8) and we know the

value of xjxj+1…x8 (using the method for recovering the last byte(s))� we want to compute xj-1� algorithm:

1. choose a random block r1r2…r8 such that rj = xj⊕(9-j); rj+1 = xj+1⊕(9-j); … r8 = x8⊕(9-j);

2. let i = 03. send r1r2…rj-2(rj-1⊕i)rj…r8y1y2…y8 to the server (oracle)4. if there’s a padding error then increment i and go back to step 35. if there’s no padding error then xj-1⊕rj-1⊕i = 9-j and hence

xj-1 = rj-1⊕i⊕(9-j)

x = DE AD BE EF DE AD BE EFr = 01 23 45 67 DA A9 BA EB

r ⊕x = DF 8E FB 88 04 04 04 04

i r r⊕x padding0 01 23 45 67 DA A9 BA EB DF 8E FB 88 04 04 04 04 ERROR1 01 23 45 66 DA A9 BA EB DF 8E FB 89 04 04 04 04 ERROR… … … …140 01 23 45 EB DA A9 BA EB DF 8E FB 04 04 04 04 04 OK

x4 = EB ⊕04 = EF

Page 45: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 45© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Decrypting an entire message

� assume we have a CBC encrypted message (Y1, Y2, …, YN) where • Y1 = EK(X1⊕IV)• Yi = EK(Xi⊕Yi-1) (for 1 < i < N)• YN = EK([XN|pad|plen]⊕YN-1)

� we want to compute X1, X2, … XN

� algorithm: • decrypt YN using the block decryption method and XOR the result to YN-1;

you get XN|pad|plen• decrypt Yi using the block decryption method and XOR the result to Yi-1; you

get Xi

• decrypt Y1 using the block decryption method and XOR the result to IV; you get X1 (if the IV is secret you cannot get X1)

complexity of the whole attack:on average we need only ½*256*8*N = 1024*N oracle calls !

Page 46: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Problems in practice

� alert messages are encrypted � BAD_RECORD_MAC and DECRYPTION_FAILED cannot be distinguished• measure timing between oracle call and oracle response• BAD_RECORD_MAC takes more time than

DECRYPTION_FAILED

� BAD_RECORD_MAC and DECRYPTION_FAILED are fatal errors � connection is closed after one oracle call• a password can still be broken if it is sent periodically to a server

using TLS (a different session (and key) is used each time the password is sent, but the password is always the same)

Transport Layer Security (TLS) 46© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 47: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 47© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Example: IMAP over TLS (2003)� Outlook Express checks for new mail on the server periodically (every 5

minutes)� each time the same password is sent for every folder

XXXX LOGIN “username” “password”<x0D><x0A>� it is possible to uncover the password using the attack as follows:

client man-in-the-middle server

X X X X L O GI N b u t t ya n k i s k ac s a

DECRYPTION_FAILEDDECRYPTION_FAILED

∆t

r 1 r 2 r 3 r 4 r 5 r 6 r 7 r 8

a n k i s k a

Page 48: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Eliminating the timing channel

� when badly formatted padding is encountered during decryption, a MAC check must still be performed on somedata to prevent known timing attacks

� which data?� TLS 1.1 and 1.2 recommend checking the MAC as if there

was a zero-length pad„This leaves a small timing channel, since MAC performancedepends to some extent on the size of the data fragment, but it is not believed to be large enough to be exploitable, due to the large block size of existing MACs and the small size of the timing signal.”

Transport Layer Security (TLS) 48© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 49: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Lucky 13 attack (2013)

� similar to the padding oracle attack, but uses a different timing channel

� let C* be an encrypted block (16 bytes); C* = EK(P*)� the attacker wants to find P*� The attacker sends C1 | C2 | R | C* (64 bytes) with proper

TLS record header to a decryption oracle (e.g. TLS server)� the oracle decrypts this into P1 | P2 | P3 | P4, where P4 =

DK(C*) + R = P* + R� MAC verification fails, but ...

Transport Layer Security (TLS) 49© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 50: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Lucky 13 attack (2013)� there are 3 cases:

1. P1 | P2 | P3 | P4 ends with invalid padding:• last 20 bytes are interpreted as MAC• remaining 44 bytes are interpreted as message• 44 +13 bytes (sqn and header) = 57 bytes go into MAC verification• >55 bytes � >4 calls to to function f

2. P4 ends with x00:• x00 removed as valid padding• next 20 bytes interpreted as MAC• remaining 64-21 = 43 bytes interpreted as message• 43 + 13 bytes = 56 bytes go into MAC computation• > 55 bytes � >4 calls to function f

3. P4 ends with a valid padding of length at least 2:• at least 2 bytes are removed as valid padding• message length is at most 42• 42 + 13 bytes (sqn and header) = 55 bytes go into MAC

computation• < 56 bytes � 4 calls to function f

Transport Layer Security (TLS) 50© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 51: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Lucky 13 attack (2013)

� if response time is „short”, then there is a valid padding of length at least 2 at the end of P1 | P2 | P3 | P4

� the case x01|x01 has the highest probability � this means that the last two bytes of P* = x01|x01 XOR the

last two bytes of R� the rest can be figured out in the same way as in the

Vaudenay attack

� if response time is „long”, than change last two bytes of R� after at most 216 trials, we get a short response time

Transport Layer Security (TLS) 51© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 52: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Lucky 13 attack (2013)

� practical considerations• the TLS session is destroyed as soon as the attacker submits

his very first attack ciphertext• mount a multi-session attack, where the same plaintext is

repeated in the same position over many sessions (similar to the attck on the IMAP password)

• the timing difference between the cases is very small, and so likely to be hidden by network jitter and other sources oftiming difference

• iterate the attack many times for each R value (similar to the distinguishing attack)

• then perform statistical processing of the recorded times to estimate which value of R is most likely to correspond to case 3 („short” response time)

Transport Layer Security (TLS) 52© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 53: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

The problem of predictable IVs in CBC

� let Ci = EK(Ci-1 + Pi) for some i (part of a CBC encrypted message), and let us assume that the attacker suspects that Pi = P*

� the attacker predicts the IV of the next message, andsubmits a message with IV + Ci-1 + P* as the first block to the oracle

� the oracle outputs a ciphertext with EK(IV + IV + Ci-1 + P*) = EK(Ci-1 + P*) as the first block

� if the attacker’s guess was correct (i.e., Pi = P*), then the above first block is equal to Ci

� thus, the attacker can confirm his guess

Transport Layer Security (TLS) 53© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 54: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

BEAST attack (2011)

� in SSL v3.0 and TLS v1.0, the IV of the next message is the last ciphertext block of the previous message � IV is predictable (known)

� Can we take advantage of the known weakness of predictable IVs in practice?

� basic idea:• if all bytes of Pi are known except one byte, then that missing

byte can be figured out by guessing and confirming the guess, and repeating this until it succeeds (at most 256 trials only)

Transport Layer Security (TLS) 54© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 55: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

BEAST attack (2011)

� algorithm to figure out the last byte:• let Ci = EK(Ci-1 + Pi) for some i (part of a CBC encrypted

message), and let us assume that the attacker knows all but the last byte of Pi (Pi = P|p*, where p* is the last byte)

• let p = 0, and repeat the following:• predict the next IV, and submit a message with IV + Ci-1 +

P|p as the first block to the oracle• (the oracle outputs a ciphertext with EK(IV + IV + Ci-1 +

P|p) = EK(Ci-1 + P|p) as the first block)• check if the first block of the oracle output is equal to Ci

• if so, then p is the unknown byte (p = p*), and stop• otherwise increment p

� this algorithm finds p* in at most 256 stepsTransport Layer Security (TLS) 55© Buttyán Levente, HIT

Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 56: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

BEAST attack (2011)

GET /document123.html HTTP/1.1

Host: www.example.orgCookie: secretvalue

[blank line here]

G E T / d o c u m e n t 1 2 3

. h t m l H T T P / 1 . 1 \r \n

H o s t : w w w . e x a m p l

e . o r g \r \n C o o k i e : s

e c r e t v a l u e \r \n \r \n

G E T / d o c u m e n t 1 2 .

h t m l H T T P / 1 . 1 \r \n H

o s t : w w w . e x a m p l e

. o r g \r \n C o o k i e : s e

c r e t v a l u e \r \n \r \n

Transport Layer Security (TLS) 56© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

attacker may be able to control the length of this string

Page 57: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

BEAST attack (2011)

� Step 1:• Mallory forces Alice’s browser to send an HTTPS POST (or

GET) request to http://bob.com/AAAAAA. • Alice’s browser uses SSL/TLS to derive a shared secret key k

with Bob’s web server, then it utilizes a block cipher in CBC mode to compute the encrypted request

• AAA... is chosen in such a way that the first byte x of the unknown cookie header falls in the last position of one of the plaintext blocks, which then looks like P|x, where P is known to the attacker.

• The encrypted request is sent to Bob’s server by Alice’s browser.

Transport Layer Security (TLS) 57© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 58: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

BEAST attack (2011)

� Step 2:• Mallory captures the encrypted request. • Let the encrypted block containing the first unknown byte x of

the cookie header be C, and let the preceding block be C’. • Mallory’s goal is to obtain x.• Let W[1..L] be the set of allowed bytes in HTTP header and

let i = 1.

Transport Layer Security (TLS) 58© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 59: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

BEAST attack (2011)

� Step 3:• Let IV be the last ciphertext block that Mallory captures, e.g.,

IV is the last block of the request captured in Step 2. • Mallory computes IV + C’ + P|W[i], and arranges that this is

encrypted and sent by Alice’s browser (e.g., appends it to the existing request)

• Alice’s browser would compute and send C* = EK(IV+IV+C’+P|W[i]) = EK(C’+P|W[i])

� Step 4:• Mallory captures C*. • If C* = C, then she knows that x is equal to W[i]. • Otherwise she increases i and goes back to step 3.

Transport Layer Security (TLS) 59© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 60: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

BEAST attack (2011)� summary of assumptions:

• Mallory can capture encrypted HTTPS requests sent by Alice• Mallory can force Alice’s browser to make arbitrary cookie-bearing

requests to Bob’s web server over HTTPS. Moreover, Mallory can also control the path value in these requests.

• HTML5 WebSocket API• Java URLConnection API• Silverlight WebClient API

• After making Alice’s browser open some HTTPS requests to the server, Mallory can append arbitrary plaintext blocks to each ongoing request.

� a browser exploit that leverages browser features or plugins to help Mallory gain his desired privileges and run an agent inside the browser• BEAST = Browser Exploit Against SSL/TLS

� a network sniffer that intercepts SSL traffic, and sends ciphertext blocks to the agent• the agent can communicate with the network sniffer via basic socket

programming

Transport Layer Security (TLS) 60© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Page 61: Transport Layer Security (TLS)buttyan/courses/EIT-SEC/2013/10_tls.pdf · Transport Layer Security (TLS) Cryptographic Protocols (EIT ICT MSc) Dr. Levente Buttyán associate professor

Transport Layer Security (TLS) 61© Buttyán Levente, HIT Budapesti M űszaki és Gazdaságtudományi Egyetem

Summary on TLS� overall:

• TLS is a well designed protocol providing strong security• current version evolved by considering many known problems of previous

versions• extremely important for securing web transactions, and for other

applications

� TLS Record Protocol• uses strong algorithms (HMAC, AES)• good protection against passive eavesdropping• some protection against traffic analysis (random length padding)• possibly vulnerable to some padding oracle attacks• may be vulnerable to the BEAST attack (needs a browser exploit)

� TLS Handshake Protocol• uses strong algorithms (RSA, DH, DSS, well designed PRF based on

HMAC)• protection against passive and active attacks• protection against some rollback attacks (cipher suite rollback, version

rollback) and against dropping change_cipher_spec messages