Crypto Attacks: It’s the implementation stupid
Thursday, August 27th, 2009Black Hat USA 2009 brought us the latest release of Moxie Marlinspike’s sslstrip tool. sslstrip is a tool for performing man-in-the-middle (MITM) attacks against TLS/SSL sessions. The previous version simply terminated the TLS connection at the MITM point and forwarded on an unencrypted connection to the client. While this attack was effective, observant users could tell what was happening. Marlinspike’s new version still terminates the TLS connection at the man in the middle point, but then uses a specially crafted X.509 certificate to create a TLS session to the client. The trick here is in the certificate itself; in order to pull this attack off the certificate must appear to be issued to the original website, not from the attacker. Marlinspike was able to circumvent this protection by exploiting a vulnerability present in many web browser. This vulnerability relies on the fact that character strings within X.509 certificates are ASN.1 encoded, but software written in the C programming language typically manipulates character strings as null terminated character arrays. ASN.1 strings are stored using a form of Type-Length-Value (TLV) encoding. C strings are simply terminated by a null byte (\x00). Here’s what this looks like in memory:
X.509 Certificate:
\x15www.bigbank.com
"C String" (char*):
www.bigbank.com\x00
Marlinspike determined that he could purchase a certificate from a major Certificate Authority (CA) with a Common Name (CN) of www.bigbank.com\x00thoughtcrime.org. Since commercial CAs only look at the root domain name and not the subdomains (i.e., thoughtcrime.org) when validating domain ownership and Marlinspike was the legitimate owner of the thoughtcrime.org domain, he was issued a signed certificate containing his specially crafted Common Name.
Things really start getting interesting when a vulnerable web browser attempts to validate a certificate that has been specially crafted in this fashion. For example, a user browses to www.bigbank.com and uses a DNS server whose cache has been poisoned such that www.bigbank.com resolved to an IP address controlled by an attacker. The attacker has a server at this IP address running sslstrip and using a specially crafted certificate with a Common Name of www.bigbank.com\x00evil.com. The user’s vulnerable web browser will perform a C string comparison (i.e., the strcmp() function from the standard <string.h> header file) between the domain being visited (www.bigbank.com) and the Common Name in the certificate presented by the attacker’s server (www.bigbank.com\x00evil.com). Since the browser is using a C string comparison it will assume it hit the end of the string when in encounters the null byte in the Common Name. Thus it will only compare the “www.bigbank.com” preface of the certificate’s Common Name against the domain being browsed to, www.bigbank.com. The end result is that the browser is tricked into thinking that it has made negotiated a valid TLS connection to www.bigbank.com.
Things gets worse. There is nothing a user can do besides inspect the X.509 certificate as it comes across the wire to detect an attack of this type. This is because vulnerable browsers use the same C string functions to display details of a certificate to the user. It’s quite an elegant attack.
Luckily, Marlinspike has been working with vendors to fix this vulnerability. Mozilla Firefox was updated within the week and a security update to Microsoft Internet Explorer should be available via Microsoft update channels soon. If you haven’t updated your browser in some time, we strongly recommend that you do so immediately to protect yourself from this attack and many others.
|
Share This Blog | |
