How can you protect yourself from CRIME, BEAST’s successor?

2012-09-10 by . 19 comments

Post to Twitter

For those who haven’t been following Juliano Rizzo and Thai Duong, two researchers who developed the BEAST attack against TLS 1.0/SSL 3.0 in September 2011, they have developed another attack they plan to publish at the Ekoparty conference in Argentina later this month – this time giving them the ability to hijack HTTPS sessions – and this has started people worrying again.

Security Stack Exchange member Kyle Rozendo asked this question:

With the advent of CRIME, BEASTs successor, what is possible protection is available for an individual and / or system owner in order to protect themselves and their users against this new attack on TLS?

And the community expectation was that we wouldn’t get an answer until Rizzo and Duong presented their attack.

However, our highest reputation member, Thomas Pornin delivered this awesome hypothesis, which I will quote here verbatim:


This attack is supposed to be presented in 10 days from now, but my guess is that they use compression.

SSL/TLS optionally supports data compression. In the ClientHello message, the client states the list of compression algorithms that it knows of, and the server responds, in the ServerHello, with the compression algorithm that will be used. Compression algorithms are specified by one-byte identifiers, and TLS 1.2 (RFC 5246) defines only the null compression method (i.e. no compression at all). Other documents specify compression methods, in particular RFC 3749 which defines compression method 1, based on DEFLATE, the LZ77-derivative which is at the core of the GZip format and also modern Zip archives. When compression is used, it is applied on all the transferred data, as a long stream. In particular, when used with HTTPS, compression is applied on all the successive HTTP requests in the stream, header included. DEFLATE works by locating repeated subsequences of bytes.

Suppose that the attacker is some Javascript code which can send arbitrary requests to a target site (e.g. a bank) and runs on the attacked machine; the browser will send these requests with the user’s cookie for that bank — the cookie value that the attacker is after. Also, let’s suppose that the attacker can observe the traffic between the user’s machine and the bank (plausibly, the attacker has access to the same LAN of WiFi hotspot than the victim; or he has hijacked a router somewhere on the path, possibly close to the bank server).

For this example, we suppose that the cookie in each HTTP request looks like this:

> Cookie: secret=7xc89f+94/wa

The attacker knows the “Cookie: secret=” part and wishes to obtain the secret value. So he instructs his Javascript code to issue a request containing in the body the sequence “Cookie: secret=0″. The HTTP request will look like this:

POST / HTTP/1.1 Host: thebankserver.com (…) Cookie: secret=7xc89f+94/wa (…)

Cookie: secret=0

When DEFLATE sees that, it will recognize the repeated “Cookie: secret=” sequence and represent the second instance with a very short token (one which states “previous sequence has length 15 and was located n bytes in the past); DEFLATE will have to emit an extra token for the ’0′.

The request goes to the server. From the outside, the eavesdropping part of the attacker sees an opaque blob (SSL encrypts the data) but he can see the blob length (with byte granularity when the connection uses RC4; with block ciphers there is a bit of padding, but the attacker can adjust the contents of his requests so that he may phase with block boundaries, so, in practice, the attacker can know the length of the compressed request).

Now, the attacker tries again, with “Cookie: secret=1″ in the request body. Then, “Cookie: secret=2″, and so on. All these requests will compress to the same size (almost — there are subtleties with Huffman codes as used in DEFLATE), except the one which contains “Cookie: secret=7″, which compresses better (16 bytes of repeated subsequence instead of 15), and thus will be shorter. The attacker sees that. Therefore, in a few dozen requests, the attacker has guessed the first byte of the secret value.

He then just has to repeat the process (“Cookie: secret=70″, “Cookie: secret=71″, and so on) and obtain, byte by byte, the complete secret.


What I describe above is what I thought of when I read the article, which talks about “information leak” from an “optional feature”. I cannot know for sure that what will be published as the CRIME attack is really based upon compression. However, I do not see how the attack on compression cannot work. Therefore, regardless of whether CRIME turns out to abuse compression or be something completely different, you should turn off compression support from your client (or your server).

Note that I am talking about compression at the SSL level. HTTP also includes optional compression, but this one applies only to the body of the requests and responses, not the header, and thus does not cover the Cookie: header line. HTTP-level compression is fine.

(It is a shame to have to remove SSL compression, because it is very useful to lower bandwidth requirements, especially when a site contains many small pictures or is Ajax-heavy with many small requests, all beginning with extremely similar versions of a mammoth HTTP header. It would be better if the security model of Javascript was fixed to prevent malicious code from sending arbitrary requests to a bank server; I am not sure it is easy, though.)


As bobince commented:

I hope CRIME is this and we don’t have two vulns of this size in play! However, I wouldn’t say that being limited to entity bodies makes HTTP-level compression safe in general… whilst a cookie header is an obvious first choice of attack, there is potentially sensitive material in the body too. eg Imagine sniffing an anti-XSRF token from response body by causing the browser to send fields that get reflected in that response.

It is reassuring that there is a fix, and my recommendation would be for everyone to assess the risk to them of having sessions hijacked and seriously consider disabling SSL compression support.

Filed under Attack Crypto Hijack News

19 Comments

Subscribe to comments with RSS.

  • John Verg says:

    The POST request as explained can’t be done in real life. If the attack is so easy why it was not done before? Anyone tried?

  • xorninja says:

    Hmm I tried this idea, but it didn’t work very well. Some code for those who want to play: http://pastebin.com/qZdNYgfr

    Still a nice idea, though!

  • roryalsop says:

    It looks like this assumption is correct – Chromium disabled TLS compression on August 3rd: https://chromiumcodereview.appspot.com/10825183

    Also Firefox, Chrome and Safari send ClientHello without advertising compression support – they silently removed it one month ago

    Looks like Thomas is spot on with this one!

  • @xorninja – I improved the algorithm and now it sort of works. Results vary, but usually at least the first 8 characters are detected.

    https://gist.github.com/3696912

  • CodesInChaos says:

    The annoying thing about this attack is that it’s not limited to TLS. It applies in many situations where content from mixed sources is compressed together. So pretty much any protocol that allows chosen plaintext attacks with compression needs to be reviewed.

    • HTTP compression with XSRF tokens, as bobince already noticed
    • Possibly SPDY header compression
    • SSH probably has similar issues
  • Caleb says:

    Way to roll Security.SE folks! Great info both on the specifics of current issues but clearly explained in a way that is useful to keep in mind for other scenarios as well.

  • David-Sarah Hopwood says:

    I’m not certain, but I think that SPDY over TLS (http://en.wikipedia.org/wiki/SPDY) may be vulnerable to this attack, even if TLS compression is disabled. SPDY does header compression, and I don’t think it’s necessary to the attack that the compression be at the TLS level. I have not studied the details of how SPDY uses compression contexts, though.

  • David-Sarah Hopwood says:

    Oh, right, CodesInChaos already pointed that out ;-)

  • [...] discuté sur IT Security Stack Exchange, la supposition que l’attaque CRIME (qui doit être présentée prochainement à la EkoParty) [...]

  • [...] opis możliwego przebiegu ataku znaleźliśmy w serwisie StackExchange. Według jego autora atak CRIME, umożliwiający odgadnięcie zawartości zaszyfrowanego ciasteczka [...]

  • Thrawn says:

    There’s a 10-year-old Firefox RFE that could go a long way toward fixing the JavaScript security model:

    https://bugzilla.mozilla.org/show_bug.cgi?id=38933

    The gist of it is: any time a cross-site request is going to be sent to a site where you have cookies and/or HTTP AUTH, you get a warning dialog, and can choose to strip the cookies/auth from the request, or block it altogether, and remember your decision for next time.

  • [...] attack » is a reference to an exploit described in this blog post, where the well-known cryptographer by that name correctly guessed how CRIME worked based on [...]

  • Nagilum says:

    Can this attack mitigated by inserting random data into the headers sent by the server?

    i.e. RequestHeader set Unique-Id %{UNIQUE_ID}e

  • Nagilum says:

    Actually this should be a Cookie so more like: RequestHeader add Set-Cookie: Unique-Id=%{UNIQUE_ID}e; Max-Age=0; Path=/; Version=”1″ That way the (changing) value will be included in all the requests the client sends.

  • Leave a comment

    Log in
    with Stack Exchange
    or