Really Understanding the SSL/TLS Vulnerability (Part 1)
This is a two part blog post. In the first part I will try to explain the vulnerability so we can get a better handle on it, and in the second part we'll examine possible countermeasures and mitigation strategies. There was some big news in the security world on November 4, 2009 when Marsh Ray released details about a newly published SSL/TLS vulnerability. Of course, selling security is all about creating Fear, Uncertainty and Doubt (FUD) and as such a number of websites and blogs also picked up the story. Most notably: The real question is whether you should be worried or not. I think that in order to answer this question we need to really dig into the details of how the attack works and then analyze the risk and potential mitigation factors from there. This particular attack is called a chosen plaintext attack. A successful attack will allow the attacker to do two things: (1) Execute a chosen HTTP transaction on the server. This could be any HTTP request that eventually does something important on the server side. For instance, a bank account transfer comes to mind as well as single message transactions such data insertion, but it could be any server-side action triggered by a specifically chosen HTTP request. (2) Gain information regarding the shared symmetric key used in an SSL session. (for a limited time). If the attacker knows a specific HTTP transaction produces a given plaintext, or plaintext sequence, he or she might be able to choose which plaintext blocks to encrypt and obtain the matching results. This may yield some information about the key. In this case, the attacker might accumulate many examples of the plaintext and matching cipher-text. As we will see, a sophisticated In order to understand how this man in the middle attack (MITM) works, we have to first understand what happens inside an SSL handshake. SSL works in two broad phases: First, the handshake phase, and second, the application data phase. The handshake phase is where the shared, symmetric key is computed which is subsequently used in the application data phase of the protocol to encrypt application data traffic. The goal of SSL is to provide secure socket communication between two endpoints. In this respect, SSL is really a layer 4 protocol as it is communicating over standard sockets. I think we take SSL for granted due to its ubiquity, but the handshake is actually performing a cryptographic feat: a shared symmetric key is securely generated between two parties that have never met before. The protocol itself requires no initial shared secret information, only a set of trusted certificate-authority (CA) certificates on the client side (at a minimum). We also take these for granted because the certificate-authority vendors have placed "trusted" CA certificates in our browsers. As an exercise you can check your browser to see who you implicitly trust. In Firexfox 3.5.x this is under Tools > Options > Advanced > Encryption tab > View Certificates. In the latest Firefox I count 70 CA certificates (roughly). Moreover, the protocol supports client authentication as well, which requires CA certificates be provisioned on the server similar to what we see in the browser. Certificates are important in two respects for SSL. First and foremost they contain the public key used by the client to encrypt the pre-master secret during the handshake, and second, they are used to validate one or both sides of the communication using X.509 certificate path validation. Certificate path validation is the process of validating the trust on a certificate by checking that you trust the issuer of the certificate. This is done by looking at the issuer's issuer and so on, up the chain until you reach an implicitly trust CA certificate, called a root CA. The limitation that Marsh Ray uncovered has to do with renegotiation of the shared secret, which I will call the renegotiation gap. SSL allows for either side to renegotiate the master secret at any time by sending an appropriate message, either from the client or server. Renegotiation can be done for any number of reasons – to refresh the shared secret, to change the cipher, or to change the mode of the protocol to a different form. It can also be done for no good specific reason, simply by having the client send a new client hello. Usually, however, renegotiation is a move from one-way SSL (server authentication) to two-way SSL (client authentication).The first thing we will do in order to understand the renegotiation gap is dig into the handshake. To see the problem, you have to put yourself in the mind of the attacker and treat the handshake like an information game with state changes along the way. The goal of the game depends on the mode of the protocol, and for SSL this will either be a shared secret with server-side authentication, or a shared secret with both client and server authentication. In the case of server side authentication, the end goal is to generate a shared secret key where the client knows the identity of the server based on the limitations of PKI technology (certificate validation). In the case of client authentication, the goal of the game is to generate a shared secret where both sides know the identity of each other, again based on the limitations of PKI technology. Once you understand the additional information state at each stage of the handshake, it becomes trivial to see how a man-in-the-middle attack can work, and further, how the renegotiation gap changes the rules of the game. First, let's lay out the handshake in 13 possible steps as follows. The table below is meant to be read from left to right and the ">" arrow denotes a message flowing from the client to the server. Similarly, the "<" indicator denotes a message from the server to the client. Once the handshake is finished, the game is over with one of two "normal" outcomes: (1) A shared secret was generated and the server was authenticated or (2) The shared secret was generated and both sides were authenticated. A critical point here is that a man in the middle of the SSL handshake changes the rules of the game and the information state. In the table below note that "*" is used to denote optional messages in the SSL handshake, used in the case of client authentication. This implies that the shortest possible handshake (for server side authentication) is an exchange of 8 messages and the full handshake is 12 messages. It should be noted for completeness that the Server Key Exchange is only used when the certificate doesn't contain a public key, such as in the case of DSA. Also, for completeness, there is a mode for SSL called "anonymous Diffie-Hellman" which requires neither side authenticate, but we won't cover it since it is infrequently used. Handshake Phase Step Client Message Server Message Information State 1 Client Hello > The first handshake message that contains the protocol version, random bytes, a session ID (or null), supported cipher-suites, and optional supported compression methods 2 < Server Hello The second message contains a selected cipher-suite, the highest mode of SSL supported by the server, session ID and compression methods 3 < Server Certificate ASN.1 encoded certificate or certificate chain goes back to the client. 4 < Server Key Exchange* (Skipped for this discussion but included for completeness) 5 < Certificate Request* Contains acceptable certificate types and list of acceptable CAs 6 < Server Hello Done Indicates the server is finished with its side of the handshake 7 Client Certificate* > The client sends its certificate or certificate chain 8 Client Key Exchange > The pre-master secret is encrypted for the server using the public key in the server's certificate 9 Certificate Verify* > Client-generated signature over the master previous handshake messages 10 Change Cipher Spec > Signal message with version and a single byte 11 Finished > Two hashes of the handshake messages, master secret, identifier and padding 12 < Change Cipher Spec Signal message with a version and a single byte 13 < Finished Two hashes of the handshake messages, master secret, identifier and padding With this background, we can now insert the attacker into the flow to see how the attack works. It is easy to think of SSL as an "encrypted" channel safe from an intruder, but if there is a man in the middle actively intercepting packets from the inception of the protocol, he or she can exploit the renegotiation gap. The Man-in-the Middle is actively waiting between the client and server under the following preconditions: Handshake Phase with Man-In-The-Middle (MITM) Step Client Message Man in the Middle Server Message Information State 1 Client Hello > Client Hello > The server receives a client hello as normal; the MITM caches the initial client hello and starts a new session with the server, sending a new client hello 2 MITM caches the server hello without passing it on. < Server Hello The server responds with a server hello. The client is still waiting for this message 3 MITM caches the server certificate. < Server Certificate The client is still waiting for a server certificate 4 < Server Key Exchange * (Skipped) – Does not affect this case 5 < Certificate Request * (Skipped) – The MITM must start with a handshake that does not trigger a certificate request 6 < Server Hello Done Server sends the server hello done. 7 Client Certificate* > (Skipped) – The MITM has chosen a handshake with no client certificate request 8 Client Key Exchange > The pre-master secret is encrypted for the server using the public key in the server's certificate 9 Certificate Verify* > (Skipped) – The MITM has chosen a handshake with no client certificate request 10 Change Cipher Spec > Signal message with version and a single byte 11 Finished > Two hashes of the handshake messages, master secret, identifier and padding (MITM) 12 < Change Cipher Spec Signal message with version and a single byte 13 < Finished Two hashes of the handshake messages, master secret, identifier and padding (Server) 14 Renegotiation Trigger Message (RTM) > (This can be as simple as a new client hello) 15 < Hello Request The server sends a hello request based on the trigger message (RTM), which starts a new handshake 17 Replayed Client Hello from Step 1 > 18 < Server Hello < Server Hello The server responds with a certificate. This matches the response the client expects after Step 1. 19 < Server Certificate < Server Certificate The server responds with its certificate which is passed on by the MITM 20 < Certificate Request < Certificate Request The server requests the client certificate – the RTM in this case triggers a stronger form of SSL 21 < Server Hello Done < Server Hello Done Server sends the server hello done which is passed through to the client 23 Client Certificate > Client Certificate > The client sends its certificate 24 Client Key Exchange > Client Key Exchange > MITM passes along the client key exchange containing encrypted the shared secret 25 Certificate Verify > Certificate Verify > MITM passes along the client's proof of possession message 26 Change Cipher Spec > Change Cipher Spec > Signal message with version and a single byte 27 Finished > Finished > MITM passes along the finished message from the client 28 < Change Cipher Spec < Change Cipher Spec Signal message with version and a single byte 29 < Finished < Finished MITM passes along the finished message from the server 30 < HTTP Response < HTTP Response The server retroactively applies the authentication to the message sent in step 14, allowing the transaction through The Man-in-the-Middle (MITM) is present from the inception of the first client hello and acts in such a way as to make both the client and server believe the handshake is legitimate, while at the same time executing a chosen plaintext attack. I have highlighted the important parts of the attack in the previous table. Another way of seeing how the attack can work is consider the behavior from the client As you can see, there is very little to indicate a compromise on either the client or server side. The key weakness is the SSL renegotiation, which can be triggered by the client or server. Worse, renegotiation is valid at any point during the protocol communication and may be done simply for the purposes of refreshing the key. In principle the weakness can be exploited anywhere the renegotiation occurs assuming the MITM is watching for this state from the inception of the handshake. In the next blog post we will look at the current and proposed mitigation strategies for this attack.
attacker acting as a man-in-the-middle (MITM) will be able to inject plaintext and then have access to the corresponding ciphertext, and if he or she knows any information about the generated response, there may be a stretch of time (before the next renegotiation) where a chosen-plaintext attack is feasible.
The SSL Handshake
Let's look at how the man in the middle can intercept messages during the handshake. In the following table I've highlighted certain portions of the handshake important to making the attack to work.
The MITM – Handshake Explanation
Conclusion