# All Your Biases Belong To Us Breaking RC4 in WPA TKIP and TLS pdf pdf

Gratis

All Your Biases Belong To Us:

Breaking RC4 in WPA-TKIP and TLS

Mathy Vanhoef *KU Leuven* *Mathy.Vanhoef@cs.kuleuven.be* Frank Piessens

*KU Leuven* *Frank.Piessens@cs.kuleuven.be* Abstract

We present new biases in RC4, break the Wi-Fi Protected Access Temporal Key Integrity Protocol (WPA-TKIP), and design a practical plaintext recovery attack against the Transport Layer Security (TLS) protocol. To empir- ically find new biases in the RC4 keystream we use sta- tistical hypothesis tests. This reveals many new biases in the initial keystream bytes, as well as several new long- term biases. Our fixed-plaintext recovery algorithms are capable of using multiple types of biases, and return a list of plaintext candidates in decreasing likelihood.

To break WPA-TKIP we introduce a method to gen- erate a large number of identical packets. This packet is decrypted by generating its plaintext candidate list, and using redundant packet structure to prune bad candidates. From the decrypted packet we derive the TKIP MIC key, which can be used to inject and decrypt packets. In prac- tice the attack can be executed within an hour. We also attack TLS as used by HTTPS, where we show how to decrypt a secure cookie with a success rate of 94% using 9 · 2

27

ciphertexts. This is done by injecting known data around the cookie, abusing this using Mantin’s *AB* S*AB* bias, and brute-forcing the cookie by traversing the plain- text candidates. Using our traffic generation technique, we are able to execute the attack in merely 75 hours.

Arguably its most well known usage is in SSL and WEP, and in their successors TLS In particular it was heavily used after attacks against CBC- mode encryption schemes in TLS were published, such as BEAST As a mitigation RC4 was recommended. Hence, at one point around 50% of all TLS connections were us- ing RC4 This motivated the search for new attacks, relevant ex- amples being Of special interest is the attack proposed by AlFardan et al., where roughly 13 · 2

30

ciphertexts are required to decrypt a cookie sent over HTTPS This corresponds to about 2000 hours of data in their setup, hence the attack is considered close to being practical. Our goal is to see how far these attacks can be pushed by exploring three areas. First, we search for new biases in the keystream. Second, we improve fixed-plaintext recovery algorithms. Third, we demon- strate techniques to perform our attacks in practice.

First we empirically search for biases in the keystream. This is done by generating a large amount of keystream, and storing statistics about them in several datasets. The resulting datasets are then analysed using statistical hy- pothesis tests. Our null hypothesis is that a keystream byte is uniformly distributed, or that two bytes are in- dependent. Rejecting the null hypothesis is equivalent to detecting a bias. Compared to manually inspecting graphs, this allows for a more large-scale analysis. With this approach we found many new biases in the initial keystream bytes, as well as several new long-term biases.

We break WPA-TKIP by decrypting a complete packet using RC4 biases and deriving the TKIP MIC key. This key can be used to inject and decrypt packets In par- ticular we modify the plaintext recovery attack of Pater- son et al. to return a list of candidates in decreas- ing likelihood. Bad candidates are detected and pruned based on the (decrypted) CRC of the packet. This in- creases the success rate of simultaneously decrypting all unknown bytes. We achieve practicality using a novel method to rapidly inject identical packets into a network. In practice the attack can be executed within an hour.

### 1 Introduction RC4 is (still) one of the most widely used stream ciphers.

We also attack RC4 as used in TLS and HTTPS, where we decrypt a secure cookie in realistic conditions. This is done by combining the *AB*

S*AB *and Fluhrer-McGrew bi- ases using variants of the of Isobe et al. and AlFardan et al. attack Our technique can easily be extended to include other biases as well. To abuse Mantin’s *AB*

S*AB* bias we inject known plaintext around the cookie, and ex- ploit this to calculate Bayesian plaintext likelihoods over

- We use statistical tests to empirically detect biases in the keystream, revealing large sets of new biases.
- We design plaintext recovery algorithms capable of using multiple types of biases, which return a list of plaintext candidates in decreasing likelihood.
- We demonstrate practical exploitation techniques to break RC4 in both WPA-TKIP and TLS.

1

1

= *Z*

2

] = 2

−8

(1 − 2

−8

) was found by Paul and Preneel Isobe et al. refined this result for the value zero to Pr

[*Z*

= *Z*

has a pos- itive bias towards 256 − ℓ AlFardan et al. showed that all initial 256 keystream bytes are biased by empiri- cally estimating their probabilities when 16-byte keys are used While doing this they found additional strong biases, an example being the bias towards value *r *for all positions 1 ≤ *r *≤ 256. This bias was also independently discovered by Isobe et al.

2

= 0] ≈ 3 · 2

−16

In the authors searched for biases of similar strength between initial bytes, but did not find additional ones. However, we did manage to find new ones (see Sect.

2.1.2 Long-Term Biases In contrast to short-term biases, which occur only in the initial keystream bytes, there are also biases that keep occurring throughout the whole keystream. We call these long-term biases. For example, Fluhrer and Mc- Grew (FM) found that the probability of certain digraphs, i.e., consecutive keystream bytes

(*Z*

*r*

, *Z*

*r*

uniform throughout the whole keystream These bi- ases depend on the public counter *i *of the PRGA, and are listed in Table (ignoring the condition on *r *for now). In their analysis, Fluhrer and McGrew assumed that the in- ternal state of the RC4 algorithm was uniformly random.

The bias Pr [*Z*

ℓ

Figure 1: Implementation of RC4 in Python-like pseudo- code. All additions are performed modulo 256. random choice of the key. Because zero occurs more of- ten than expected, we call this a positive bias. Similarly, a value occurring less often than expected is called a neg- ative bias. This result was extended by Maitra et al. and further refined by Sen Gupta et al. to show that there is a bias towards zero for most initial keystream bytes. Sen Gupta et al. also found key-length dependent biases: if ℓ is the key length, keystream byte *Z*

Practical attacks on TKIP and TLS are presented in Sect.

swap(S[i], S[j]) _{5 return S} Listing (2) RC4 Keystream Generation (PRGA). _{1 S, i, j = KSA(key), 0, 0} _{2 while True:} _{3 i += 1} _{4 j += S[i]} 5 swap(S[i], S[j]) _{6 yield S[S[i] + S[j]]}

the unknown cookie. We then generate a list of (cookie) candidates in decreasing likelihood, and use this to brute- force the cookie in negligible time. The algorithm to gen- erate candidates differs from the WPA-TKIP one due to the reliance on double-byte instead of single-byte likeli- hoods. All combined, we need 9 · 2

27

encryptions of a cookie to decrypt it with a success rate of 94%. Finally we show how to make a victim generate this amount within only 75 hours, and execute the attack in practice.

To summarize, our main contributions are:

The remainder of this paper is organized as follows. Section gives a background on RC4, TKIP, and TLS. In Sect.

### 2 Background We introduce RC4 and its usage in TLS and WPA-TKIP.

### 2.1 The RC4 Algorithm

= *P*

*r*

, where the probability is over the Listing (1) RC4 Key Scheduling (KSA). _{1 j, S = 0, range(256)} _{2 for i in range(256):} _{3 j += S[i] + key[i % len(key)]}

_{4}

2 = 0] ≈ 2 · 2 −8

[*Z*

2.1.1 Short-Term Biases Several biases have been found in the initial RC4 key- stream bytes. We call these short-term biases. The most significant one was found by Mantin and Shamir. They showed that the second keystream byte is twice as likely to be zero compared to uniform Or more formally that Pr

*r* .

⊕ *Z*

The RC4 algorithm is intriguingly short and known to be very fast in software. It consists of a Key Scheduling Algorithm (KSA) and a Pseudo Random Generation Al- gorithm (PRGA), which are both shown in Fig. The state consists of a permutation S of the set {0, . . . , 255}, a public counter *i*, and a private index *j*. The KSA takes as input a variable-length key and initializes S. At each round *r* = 1, 2, . . . of the PRGA, the yield statement out- puts a keystream byte *Z*

*r*

*r*

. All additions are performed modulo 256. A plaintext byte *P*

*r*

is encrypted to cipher- text byte *C*

using *C*

*r*

- 1 ), deviate from

*i*= 1

2

−16

(1 + 2

−7

) (0,0) *i* 6= 1, 255

header TSC SNAP

## IP TCP MIC

(1 + 2

, *Z*

Pr [(*Z*

Hence the bigger the gap, the weaker the bias. Finally, Sen Gupta et al. found the long-term bias

) (1)

−4−8*g* _{256}

e

−8

(1+2

−16

)] = 2

*r* +*g*+3

*r* +*g*+2

, *Z*

) = (*Z*

*r* +1

, *Z*

*r*

S a short sequence of bytes called the gap. With the length of the gap S de- noted by *g*, the bias can be written as: Pr [(*Z*

Another long-term bias was found by Mantin He discovered a bias towards the pattern *AB* S*AB*, where *A* and *B *represent byte values, and

) Table 1: Generalized Fluhrer-McGrew (FM) biases. Here *i *is the public counter in the PRGA and *r *the posi- tion of the first byte of the digraph. Probabilities for long- term biases are shown (for short-term biases see Fig. This assumption is only true after a few rounds of the PRGA . Consequently these biases were gen- erally not expected to be present in the initial keystream bytes. However, in Sect. we show that most of these biases do occur in the initial keystream bytes, albeit with different probabilities than their long-term variants.

−8

(1 − 2

−16

*w* 256

*w* 256 +2

6= 254 ∧ *r *6= 5

1 K

We focus on the TLS record protocol when RC4 is se- lected as the symmetric cipher In particular we as- sume the handshake phase is completed, and a 48-byte TLS master secret has been negotiated.

2.3 The TLS Record Protocol

are the two least significant bytes of the TSC. Since the TSC is public, so are the first three bytes of K. Both formally and using simulations, it has been shown this actually weakens security

1

= TSC Here, TSC and TSC

2

| 0x20) & 0x7f K

1

= (TSC

1

K = TSC

) = (0, 0)] = 2

When the client wants to transmit a payload, it first calculates a MIC value using the appropriate MIC key and the Micheal algorithm (see Fig. Figure Unfortu- nately Micheal is straightforward to invert: given plain- text data and its MIC value, we can efficiently derive the MIC key After appending the MIC value, a CRC checksum called the Integrity Check Value (ICV) is also appended. The resulting packet, including MAC header and example TCP payload, is shown in Figure The payload, MIC, and ICV are encrypted using RC4 with a per-packet key. This key is calculated by a mixing function that takes as input the TK, the TKIP sequence counter (TSC), and the transmitter MAC address (TA). We write this as K = KM(TA, TK, TSC). The TSC is a 6-byte counter that is incremented after transmitting a packet, and is included unencrypted in the MAC header. In practice the output of KM can be modelled as uni- formly random In an attempt to avoid weak-key attacks that broke WEP §11.4.2.1.1]:

Pairwise Transient Key (PTK) has already been nego- tiated between the Access Point (AP) and client. From this PTK a 128-bit temporal encryption key (TK) and two 64-bit Message Integrity Check (MIC) keys are de- rived. The first MIC key is used for AP-to-client commu- nication, and the second for the reverse direction. Some works claim that the PTK, and its derived keys, are re- newed after a user-defined interval, commonly set to 1 hour However, we found that generally only the Groupwise Transient Key (GTK) is periodically re- newed. Interestingly, our attack can be executed within an hour, so even networks which renew the PTK every hour can be attacked.

ICV encrypted payload Figure 2: Simplified TKIP frame with a TCP payload.

2

Our attack on TKIP relies on two elements of the pro- tocol: its weak Message Integrity Check (MIC) and its faulty per-packet key construction We briefly introduce both aspects, assuming a 512-bit

The design goal of WPA-TKIP was for it to be a tem- porary replacement of WEP §11.4.2]. While it is being phased out by the WiFi Alliance, a recent study shows its usage is still widespread Out of 6803 net- works, they found that 71% of protected networks still allow TKIP, with 19% exclusively supporting TKIP.

) where *w* ≥ 1. We discovered that a bias towards (128, 0) is also present at these positions (see Sect.

−8

(1 + 2

−16

2

*i*

−8

−8

−8

(1 + 2

−16

2

) (129,129) *i* = 2, *r *6= 2

−8

(1 + 2

−16

2

) (*i *+ 1,255) *i* 6= 254 ∧ *r *6= 1

(1 − 2

2

−16

2

6= 0, 255

*i*

) (0,*i *+ 1)

−8

(1 + 2

−16

2

) (0,1) *i* 6= 0, 1

) (255,*i *+ 1) *i* 6= 1, 254

−16

) (255,255)

−8

−8

−16

−16

2

) (255,2) *i* = 0, 1

−8

(1 + 2

−16

2

) (255,1) *i* = 255

(1 + 2

(1 + 2

−16

2

) (255,0) *i* = 254

−8

(1 + 2

−16

2

∈ [1, 252] ∧ *r *6= 2

*i*

) (255,*i *+ 2)

−8

(1 + 2

### 2.2 TKIP Cryptographic Encapsulation

type version length payload HMAC header RC4 encrypted

Figure 3: TLS Record structure when using RC4. To send an encrypted payload, a TLS record of type application data is created. It contains the protocol ver- sion, length of the encrypted content, the payload itself, and finally an HMAC. The resulting layout is shown in Fig. The HMAC is computed over the header, a se- quence number incremented for each transmitted record, and the plaintext payload. Both the payload and HMAC are encrypted. At the start of a connection, RC4 is ini- tialized with a key derived from the TLS master secret. This key can be modelled as being uniformly random None of the initial keystream bytes are discarded.

In the context of HTTPS, one TLS connection can be used to handle multiple HTTP requests. This is called a persistent connection. Slightly simplified, a server indi- cates support for this by setting the HTTP Connection header to keep-alive. This implies RC4 is initialized only once to send all HTTP requests, allowing the usage of long-term biases in attacks. Finally, cookies can be marked as being secure, assuring they are transmitted only over a TLS connection.

### 3 Empirically Finding New Biases

In this section we explain how to empirically yet soundly detect biases. While we discovered many biases, we will not use them in our attacks. This simplifies the descrip- tion of the attacks. And, while using the new biases may improve our attacks, using existing ones already sufficed to significantly improve upon existing attacks. Hence our focus will mainly be on the most intriguing new biases.

To test whether values are uniformly distributed, we use a chi-squared goodness-of-fit test. A naive approach to test whether two bytes are independent, is using a chi- squared independence test. Although this would work, it is not ideal when only a few biases (outliers) are present. Moreover, based on previous work we expect that only a few values between keystream bytes show a clear de- pendency on each other Taking the Fluhrer-McGrew biases as an example, at any position at most 8 out of a total 65536 value pairs show a clear bias When expecting only a few outliers, the M-test of Fuchs and Kenett can be asymptotically more pow- erful than the chi-squared test Hence we use the M-test to detect dependencies between keystream bytes. To determine which values are biased between dependent bytes, we perform proportion tests over all value pairs.

We reject the null hypothesis only if the p-value is lower than 10

−4

. Holm’s method is used to control the family-wise error rate when performing multiple hypoth- esis tests. This controls the probability of even a single false positive over all hypothesis tests. We always use the two-sided variant of an hypothesis test, since a bias can be either positive or negative.

Simply giving or plotting the probability of two depen- dent bytes is not ideal. After all, this probability includes the single-byte biases, while we only want to report the strength of the dependency between both bytes. To solve this, we report the absolute relative bias compared to the expected single-byte based probability. More precisely, say that by multiplying the two single-byte probabilities of a pair, we would expect it to occur with probability *p*. Given that this pair actually occurs with probability *s*, we then plot the value |*q*| from the formula *s *= *p *· (1 + *q*). In a sense the relative bias indicates how much information is gained by not just considering the single-byte biases, but using the real byte-pair probability.

### 3.1 Soundly Detecting Biases

3.2 Generating Datasets

Our main results are based on two datasets, called first16 and consec512. The first16 dataset esti- mates Pr

[*Z*

*a*

= *x *∧ *Z*

*b*

= *y*] for 1 ≤ *a *≤ 16, 1 ≤ *b *≤ 256, and 0 ≤ *x*, *y *< 256 using 2

44

keys. Its generation took

In order to empirically detect new biases, we rely on hy- pothesis tests. That is, we generate keystream statistics over random RC4 keys, and use statistical tests to un- cover deviations from uniform. This allows for a large- scale and automated analysis. To detect single-byte bi- ases, our null hypothesis is that the keystream byte values are uniformly distributed. To detect biases between two bytes, one may be tempted to use as null hypothesis that the pair is uniformly distributed. However, this falls short if there are already single-byte biases present. In this case single-byte biases imply that the pair is also biased, while both bytes may in fact be independent. Hence, to detect double-byte biases, our null hypothesis is that they are independent. With this test, we even detected pairs that are actually more uniform than expected. Rejecting the null hypothesis is now the same as detecting a bias.

In order to generate detailed statistics of keystream bytes, we created a distributed setup. We used roughly 80 stan- dard desktop computers and three powerful servers as workers. The generation of the statistics is done in C. Python was used to manage the generated datasets and control all workers. On start-up each worker generates a cryptographically random AES key. Random 128-bit RC4 keys are derived from this key using AES in counter mode. Finally, we used R for all statistical analysis Digraph position Absolute relativ e bias

2 − ^{8.5}

= 63

15

= 159 *Z*

32

= 224

2

−15.96574

(1 + 2

−9.493

)

*Z*

16

= 240 *Z*

31

2

)

−15.95021

(1 + 2

−8.996

)

*Z*

16

= 240 *Z*

32

= 16

2

−15.94976

(1 + 2

−9.261

*Z*

−10.904

*Z*

17

*Z*

14

= 0 *Z*

16

= 14

2

−15.99349

(1 + 2

−9.941

)

*Z*

15

= 47 *Z*

= 16

(1 − 2

2

−16.00191

(1 + 2

−11.279

)

*Z*

15

= 112

*Z*

32

= 224

2

−15.96637

)

16

−8.208

(1 − 2

2

−15.92619

(1 − 2

−10.965

)

*Z*

16

= 240

*Z*

64

= 192

2

−15.93357

−11.229

48

) Table 2: Biases between (non-consecutive) bytes. ble (note the extra conditions on the position *r*). This is surprising, as the Fluhrer-McGrew biases were gener- ally not expected to be present in the initial keystream bytes However, these biases are present, albeit with different probabilities. Figure shows the absolute rela- tive bias of most Fluhrer-McGrew digraphs, compared to their expected single-byte based probability (recall Sect. We observe that the relative biases converge to their long- term values, especially after position 257. The vertical lines around position 1 and 256 are caused by digraphs which do not hold (or hold more strongly) around these positions.

A second set of strong biases have the form: Pr [*Z*

*w* 16 −1

= *Z*

*w*

16

= 256 − *w*16] (2) with 1 ≤ *w *≤ 7. In Table we list their probabilities. Since 16 equals our key length, these are likely key- length dependent biases.

Another set of biases have the form Pr [*Z*

*r*

= *Z*

*r* +1 = *x*].

Depending on the value *x*, these biases are either nega- tive or positive. Hence summing over all *x *and calcu- lating Pr

[*Z r* = *Z r* +1 ] would lose some statistical informa-

= 208

= 240 *Z*

= 240

2

*Z*

33

= 16

2

−15.94960

(1 + 2

−10.516

)

*Z*

16

= 240 *Z*

40

= 32

−15.94976

16

(1 + 2

−10.933

)

*Z*

16

= 240 *Z*

48

= 16

2

−15.94989

(1 + 2

−10.832

)

*Z*

)

(1 + 2

2 − ^{8}

*Z* 48 = 208

−4.894

)

*Z*

31

= 224 *Z*

32

= 224

2

−15.96486

(1 − 2

−5.427

)

*Z* 47 = 208

2

−15.94786

−15.97595

(1 − 2

−5.963

)

*Z*

63

= 192

*Z*

64

= 192

2

−15.98363

(1 − 2

(1 − 2

2

)

45

2 − ^{7.5}

2 − ^{7}

2 − ^{6.5}

1

32

64 96 128 160 192 224 256 288 (0, 0) (0, 1) (0,i+1)

( i+1,255) (255, i+1) (255, i+2) (255,255)

Figure 4: Absolute relative bias of several Fluhrer- McGrew digraphs in the initial keystream bytes, com- pared to their expected single-byte based probability. roughly 9 CPU years. This allows detecting biases be- tween the first 16 bytes and the other initial 256 bytes.

The consec512 dataset estimates Pr [*Z*

*r*

= *x *∧ *Z*

*r* +1

= *y*] for 1 ≤ *r *≤ 512 and 0 ≤ *x*, *y *< 256 using 2

keys, which took 16 CPU years to generate. It allows a detailed study of consecutive keystream bytes up to position 512.

= 240

We optimized the generation of both datasets. The first optimization is that one run of a worker generates at most 2

30

keystreams. This allows usage of 16-bit inte- gers for all counters collecting the statistics, even in the presence of significant biases. Only when combining the results of workers are larger integers required. This low- ers memory usage, reducing cache misses. To further re- duce cache misses we generate several keystreams before updating the counters. In independent work, Paterson et al. used similar optimizations For the first16 dataset we used an additional optimization. Here we first generate several keystreams, and then update the coun- ters in a sorted manner based on the value of *Z*

*a*

. This optimization caused the most significant speed-up for the first16 dataset.

By analysing the generated datasets we discovered many new short-term biases. We classify them into several sets.

3.3.1 Biases in (Non-)Consecutive Bytes By analysing the consec512 dataset we discovered nu- merous biases between consecutive keystream bytes.

Our first observation is that the Fluhrer-McGrew biases are also present in the initial keystream bytes. Excep- tions occur at positions 1, 2 and 5, and are listed in Ta-

First byte Second byte Probability

*Consecutive biases:* *Z*

15

= 240 *Z*

16

−6.469

*Z*

−15.99918

3

−7.912

)

*Z*

3

= 131 *Z*

131

= 3

2

−15.99543

(1 + 2

−8.700

)

*Z*

= 131

−16.00243

*Z* 131

= 131

2

−15.99347

(1 − 2

−9.511

)

*Z*

4

= 5 *Z*

6

= 255

2

(1 + 2

2

79

2

= 176 *Z*

80

= 176

2

−15.99020

(1 − 2

−7.150

)

*Z*

95

= 160 *Z*

96

= 160

−15.99405

= 4

(1 − 2

−7.740

)

*Z* 111 = 144

*Z* 112 = 144

2

−15.99668

(1 − 2

−8.331

)

*Non-consecutive biases:* *Z*

3

= 4 *Z*

5

### 3.3 New Short-Term Biases

= *y*] (6) We ended up with 2

2 .

4

] = 2

−8

(1 − 2

−9.622

) (5) Note that all either involve an equality with *Z*

1

or *Z*

3.3.3 Single-Byte Biases We analysed single-byte biases by aggregating the consec512 dataset, and by generating additional statis- tics specifically for single-byte probabilities. The aggre- gation corresponds to calculating

2

Pr [*Z*

*r*

= *k*] =

255 ∑ *y* =0

Pr [*Z*

*r*

= *k *∧ *Z*

*r* +1

= *Z*

Pr [*Z*

47

(1 − 2

1

[*Z*

= 0] found by Isobe et al. Bias B and D are positive. We also discovered the following three biases: Pr [*Z*

1

= *Z*

3

] = 2

−8

−9.617

) (4)

) (3) Pr

[*Z*

1

= *Z*

4

] = 2

−8

(1 + 2

−8.590

### 2 Arguably our most intriguing finding is the amount of

keys used to estimate single-byte probabilities. For all initial 513 bytes we could reject the hypothesis that they are uniformly distributed. In other words, all initial 513 bytes are biased. Figure shows the probability distribution for some positions. Manual inspection of the distributions revealed a significant bias towards *Z*

2

Bias 2 Bias 4 Bias 6

= 240 generally have a position, or value, that is a multiple of 16. This is an indication that these are likely key-length dependent biases.

16

We also detected biases between non-consecutive bytes that do not fall in any obvious categories. An overview of these is given in Table We remark that the biases induced by *Z*

*r* +1 ], was detected up to position 512.

= *Z*

*r*

[*Z*

Figure 5: Biases induced by the first two bytes. The num- ber of the biases correspond to those in Sect. tion. In principle, these biases also include the Fluhrer- McGrew pairs (0, 0) and (255, 255). However, as the bias for both these pairs is much higher than for other values, we don’t include them here. Our new bias, in the form of Pr

64 96 128 160 192 224 256 Bias 1 Bias 3 Bias 5

1

32

1

2 − ^{7}

2 − ^{8}

2 − ^{9}

2 − ^{10}

2 − ^{11}

Position other keystream byte (variable i) Absolute relativ e bias

3.3.2 Influence of *Z*

and *Z*

= 0 3) *Z*

*i*

*i*

= 0 ∧ *Z*

2

= *i* 5) *Z*

*i*

= 257 − *i *∧ *Z*

1

= 1 2) *Z*

= *i *− 1 ∧ *Z*

information the first two keystream bytes leak. In partic- ular, *Z*

1

= 0 4) *Z*

*i*

= 257 − *i *∧ *Z*

1

We detected the following six sets of biases: 1) *Z*

2 influence all initial 256 keystream bytes.

and *Z*

1

= *Z*

*k*·16 =*k*· 32 for 1 ≤*k*≤ 7. These are likely

6= 0, and both ap- pear to be mainly caused by the strong positive bias ^{Keystream byte value} ^{0.00390577} ^{0.00390589} ^{0.00390601} ^{0.00390613} ^{0.00390625} ^{0.00390637} ^{0.00390649} ^{32} ^{Probability} ^{64} ^{96 128 160 192 224 256} ^{Position 272} ^{Position 304} ^{Position 336} ^{Position 368} Figure 6: Single-byte biases beyond position 256. Pr

1

1

Pairs involving *Z*

2 , are generally negative.

= *i* Their absolute relative bias, compared to the single-byte biases, is shown in Fig. The relative bias of pairs 5 and 6, i.e., those involving *Z*

*i*

= 0 ∧ *Z*

2

*Z*

= 257 − *i* 6)

*i*

= 257 − *i *∧ *Z*

256

1

key-length dependent biases. Following we conjec- ture there are single-byte biases even beyond these posi- tions, albeit less strong.

3.4 New Long-Term Biases

To search for new long-term biases we created a variant of the first16 dataset. It estimates Pr

[*Z*

256*w*

(7) for 0 ≤ *a *≤ 16, 0 ≤ *b *< 256, 0 ≤ *x*, *y *< 256, and *w *≥ 4. It is generated using 2

12 RC4 keys, where each key was

used to generate 2

40

keystream bytes. This took roughly

8 CPU years. The condition on *w *means we always

are generally positive, except pair 3, which always has a negative relative bias. We also de- tected dependencies between *Z*

and *Z*

*a*=*x*∧*Z*256*w**b*=*y*]

= 1 Bias A and C are negative for all *x*

2

= *x *∧ *Z*

1

D) *Z*

= 258 − *x*

2

= *x *∧ *Z*

1

B) *Z*

= 0

2

1

2

C) *Z*

= *x*

2

= 0 ∧ *Z*

1

] bias of Paul and Preneel That is, the following pairs are strongly biased: A) *Z*

2

= *Z*

1

[*Z*

other than the Pr

= *x *∧ *Z*

*a*=*Z*256*w**b*] ≈ 2 −8

*k* _{1} ,*k* _{2}

*k* ^{1} ,*k* _{2}

(*p*

∏ *k* _{1} ,*k* _{2} ∈ ^{I} ^{c}

·

*M* µ1,µ2

= (*u*)

, µ _{2}

λ µ _{1}

= *u* (14) where *u *represents the probability of an unbiased double- byte keystream value. Then we rewrite formula to:

*k* _{2}

· *p*

*k* _{1}

= *p*

) ∈ I : *p*

*N* µ1,µ2 *k*1,*k*2

2

, *k*

1

∀(*k*

are independent and uni- form. More precisely, let us assume that all keystream value pairs in the set I are independent and uniform:

2

and *k*

1

(13) We found this formula can be optimized if most key- stream byte values *k*

*N* µ1,µ2 *k*1,*k*2

)

*k* _{1} ,*k* _{2}

(*p*

)

(15) where

∏ *k* ^{1}

For example, when applied to the long-term keystream setting over Fluhrer-McGrew biases, roughly 2

, respectively. To accomplish this we abuse surrounding known plaintext. Our main idea is to first calculate the

2

and µ

1

that the plain- text bytes at fixed positions *r *and *r*

, µ _{2}

λ µ _{1}

We now show how to compute a double-byte plaintext likelihood using Mantin’s *AB* S*AB *bias. More formally, we want to compute the likelihood

4.2 Likelihoods From Mantin’s Bias

. A similar (though less drastic) optimization can also be made when single-byte biases are present.

32

opera- tions are required to calculate all likelihood estimates, in- stead of 2

19

*c* is small, this results in a lower time-complexity.

*M* µ _{1} , µ _{2}

I

the set of dependent keystream values. If the set

*c*

I

(16) and with

,*k* _{2}

µ _{1} , µ _{2} *k* ^{1}

∈ ^{I} ^{c} *N*

∑ *k* ^{1 ,k} ^{2}

= |C| −

,*k* _{2}

∈ ^{I} *N* µ _{1} , µ _{2} *k* ^{1}

∑ *k* ^{1 ,k} ^{2}

=

,*k* _{2} ∈{0,...,255}

=

*k*

Pr [*Z*

These can be obtained by following the steps in Sect. All biases in *p*

*r* = *k*].

= Pr[*Z*

*k*

Our goal is to convert a sequence of ciphertexts C into predictions about the plaintext. This is done by exploit- ing biases in the keystream distributions *p*

We will design plaintext recovery techniques for usage in two areas: decrypting TKIP packets and HTTPS cookies. In other scenarios, variants of our methods can be used.

, these are difficult to reliably detect. That is, the pattern where these biases occur, and when their relative bias is positive or nega- tive, is not yet clear. We consider it an interesting future research direction to (precisely and reliably) detect all keystream bytes which are dependent in this manner.

−16

Due to the small relative bias of 2

) (9)

−16

(2 ± 2

256*w*

] by aggregating our dataset. This revealed that many bytes are dependent on each other. That is, we detected several long-term biases of the form

are used to calculate the likelihood that a plaintext byte equals a certain value µ. To accom- plish this, we rely on the likelihood calculations of Al- Fardan et al. Their idea is to calculate, for each plaintext value µ, the (induced) keystream distributions required to witness the captured ciphertexts. The closer this matches the real keystream distributions *p*

*r* ′

= *Z*

*r*

) (8) for *w* ≥ 1. Surprisingly this was not discovered earlier, since a bias towards (0, 0) at these positions was already known We also specifically searched for biases of the form Pr [*Z*

−8

(1 + 2

−16

) = (128, 0)] = 2

*w* 256 +2

, *Z*

*w* 256

Pr [(*Z*

dropped the initial 1023 keystream bytes. Using this dataset we can detect biases whose periodicity is a proper divisor of 256 (e.g., it detected all Fluhrer-McGrew bi- ases). Our new short-term biases were not present in this dataset, indicating they indeed only occur in the initial keystream bytes, at least with the probabilities we listed. We did find the new long-term bias

### 4 Plaintext Recovery

### 4.1 Calculating Likelihood Estimates

*k*

µ _{1} , µ _{2}

= Pr[*P *= µ | C] ∼ Pr[C | *P *= µ] (12) For our purposes we can treat this as an equality The most likely plaintext byte

*N* µ _{k}

)

*k*

(*p*

∏ *k* ∈{0,...,255}

Pr [C | *P *= µ] =

we calculate the likelihood that this induced distribution would occur in practice. This is modelled using a multi- nomial distribution with the number of trails equal to |C|, and the categories being the 256 possible keystream byte values. Since we want the probability of this *sequence *of keystream bytes we get

that the plaintext byte is µ: λ

, the more likely we have the correct plaintext byte. Assuming a fixed position *r *for simplicity, the induced keystream dis- tributions are defined by the vector *N*

µ

µ is the one that maximises λ µ . This was extended to a pair of dependent keystream bytes in the obvious way:

µ

λ

= |{*C *∈ C | *C *= *k *⊕ µ}| (10)

*N* µ *k*

represents the number of times the keystream byte was equal to *k*, assuming the plaintext byte was µ:

µ *k*

). Each *N*

µ 255

, . . . , *N*

µ

= (*N*

µ

(11) Using Bayes’ theorem we can convert this into the like- lihood λ

- 1 are µ

*k*

µ ′

and *N*

µ

Note that the vectors *N*

are permutations of each other. Based on the real keystream probabilities *p*

- 2+
*g* - 1 ⊕
*Z* - 3+
*g*) (17)

b µ ⊕(µ ′ _{1}

2 ^{31}

2 ^{29}

2 ^{27}

0% 20% 40% 60% 80% 100%

Number of ciphertexts A ver age reco ver y r ate

S*AB *bias up to gap sizes of at least 135 bytes. The theoretical estimate in formula slightly underestimates the true empirical bias. In our attacks we use a maximum gap size of 128.

*AB*

blocks of 512 keystream bytes. Based on this we empirically confirmed Mantin’s

48

S*AB *bias is still detectable, we generated 2

(24) To estimate at which gap size the *AB*

)

, µ ′ _{2}

= λ

2 ^{35}

µ ^{1 , µ} ^{2}

Finally we apply our knowledge of the known plaintext bytes to get our desired likelihood estimate: λ

= b µ o (23)

*C*

∈ b C | b

*C*

| b µ | = n b

(22) where we slightly abuse notation by defining | b µ | as

| b µ |

· α(*g*)

| ^{C} |−|b *u* |

= (1 − α(*g*))

b µ

2 ^{33}

2 ^{37}

- 2 +
*g*and*r*+ 3 +*g*, respectively. Similar to our previous likelihood estimates, we calcu- late the probability of witnessing the ciphertext differen- tials b

be likelihoods derived from *AB* S*AB *biases of gap *g*. Then their combination is straightforward: λ µ _{1 ,}

S*AB *biases and the Fluhrer-McGrew biases, where we use the method from Sect. to derive likelihoods from *AB*

*AB*

S*AB *bias. Then we combine 2 · 129

To verify the effectiveness of this approach, we per- formed simulations where we attempt to decrypt two bytes using one double-byte likelihood estimate. First this is done using only the Fluhrer-McGrew biases, and using only one *AB*

(25) While this method may not be optimal when combining likelihoods of dependent bytes, it does appear to be a general and powerful method. An open problem is de- termining which biases can be combined under a single likelihood calculation, while keeping computational re- quirements acceptable. Likelihoods based on other bi- ases, e.g., Sen Gupta’s and our new long-term biases, can be added as another factor (though some care is needed so positions properly overlap).

*g*, µ _{1 ,} µ _{2}

′

λ

∏ *g*

·

′ µ _{1 ,} µ _{2}

= λ

µ _{2}

*g*, µ _{1} , µ _{2}

2 ^{39} Combined FM only ABSAB only

′

based on the Fluhrer-McGrew biases. Similarly, let λ

2

and µ

1

be the likelihood of plaintext bytes µ

′ µ _{1} , µ _{2}

λ

). To overcome this problem, we perform and combine multiple separate likelihood estimates. We will combine multiple types of biases by multi- plying their individual likelihood estimates. For exam- ple, let

2 ·8·*n*

O(2

Our goal is to combine multiple types of biases in a likeli- hood calculation. Unfortunately, if the biases cover over- lapping positions, it quickly becomes infeasible to per- form a single likelihood estimation over all bytes. In the worst case, the calculation cannot be optimized by rely- ing on independent biases. Hence, a likelihood estimate over *n *keystream positions would have a time complex- ity of

4.3 Combining Likelihood Estimates

Figure 7: Average success rate of decrypting two bytes using: (1) one *AB* S*AB *bias; (2) Fluhrer-McGrew (FM) biases; and (3) combination of FM biases with 258 *AB* S*AB *biases. Results based on 2048 simulations each.

λ

b µ

= Pr[ b C | b *P* = b µ ]. Since only one differential pair is biased, we can apply and simplify formula

*g* *r*

*g* *r*

= (0, 0) with b *P*

*g* *r*

) = α(*g*) (18) When XORing both sides of b *Z*

−4−8*g* _{256}

e

−8

(1 + 2

−16

= (0, 0)] = 2

*g* *r*

Pr [b *Z*

to denote the differential over ciphertext and plaintext bytes, respectively. The *AB* S*AB* bias can then be written as:

and b *P*

[ b

*g* *r*

Similarly we use b *C*

*r*

*r*

, *Z*

*r*

⊕ *Z*

*r*

= (*Z*

*Z* *g* *r*

as: b

*g* *r*

likelihood of the *differential *between the known and un- known plaintext. We define the differential b *Z*

we get Pr

*C* *g* *r*

(21) Using this notation we see that this is indeed identical to an ordinary likelihood estimation. Using Bayes’ theorem we get λ

*P*

b µ o

*C* ∈ b C | b *C* = b *k* ⊕

= n b

*N* b µ b*k*

(20) where

*N* b µ b*k*

]

*k*

= b

*Z*

[b

∏ b*k*∈{0,...,255} ^{2} Pr

= b µ ] =

[ b C | b

= b

C assuming the plaintext differential is b µ: Pr

the known plaintext bytes at positions *r*

2

′

and µ

1

′

phertext differentials, and µ

*AB* S*AB *gap of *g*. Let b C be the sequence of captured ci-

of a differential b µ. For ease of notation we assume a fixed position *r *and a fixed

b µ

Hence Mantin’s bias implies that the ciphertext differen- tial is biased towards the plaintext differential. We use this to calculate the likelihood λ

] = α(*g*) (19)

*P* *g* *r*

S*AB *biases. We assume the unknown bytes are surrounded at both sides by known plaintext, and use a

### 4.4 List of Plaintext Candidates

*pr*

*P* *r*

[*i*] ← *P*

*r* −1 [*pos*(µ)] k µ

*E* *r*

[*i*] ← *E*

*r* −1 [*pos*(µ)] + log(λ *r*,

µ ) *pos* (µ) ← *pos*(µ) + 1 *pr* (µ) ← *E* *r* −1

[*pos*(µ)] + log(λ

*r*, µ

) if *pos* (µ) > min(*N*, 256

*r* −1

) then

(µ) ← −∞ return *P*

′

*N*

order time-inhomogeneous HMM. The state space *S *of the HMM is defined by the set of possible plaintext val- ues {0, . . . , 255}. The byte positions are modelled using the time-dependent (i.e., inhomogeneous) state transition probabilities. Intuitively, the “current time” in the HMM corresponds to the current plaintext position. This means the transition probabilities for moving from one state to another, which normally depend on the current time, will now depend on the position of the byte. More formally:

Pr [*S*

*t*

2

| *S*

*t*

= µ

1

] ∼ λ

*t*, µ _{1 ,} µ _{2}

(26) where *t *represents the time. For our purposes we can treat this as an equality. In an HMM it is assumed that its current state is not observable. This corresponds to the fact that we do not know the value of any plaintext bytes. In an HMM there is also some form of output which depends on the current state. In our setting a par- ticular plaintext value leaks no observable (side-channel) information. This is modelled by always letting every state produce the same null output with probability one.

Using the above HMM model, finding the most likely plaintext reduces to finding the most likely state se- quence. This is solved using the well-known Viterbi al- gorithm. Indeed, the algorithm presented by AlFardan et al. closely resembles the Viterbi algorithm Similarly, finding the *N *most likely plaintexts is the same as find- ing the *N *most likely state sequences. Hence any *N*-best variant of the Viterbi algorithm (also called list Viterbi

)

which maximizes *pr* (µ

maximum *AB* S*AB *gap of 128 bytes. Figure shows the results of this experiment. Notice that a single *AB* S*AB* bias is weaker than using all Fluhrer-McGrew biases at a specific position. However, combining several *AB* S*AB* biases clearly results in a major improvement. We con- clude that our approach to combine biases significantly reduces the required number of ciphertexts.

We model the plaintext likelihood estimates as a first- Algorithm 1: Generate plaintext candidates in de- creasing likelihood using single-byte estimates.

In practice it is useful to have a list of plaintext candi- dates in decreasing likelihood. For example, by travers- ing this list we could attempt to brute-force keys, pass- words, cookies, etc. (see Sect. In other situations the plaintext may have a rigid structure allowing the removal of candidates (see Sect. We will generate a list of plaintext candidates in decreasing likelihood, when given either single-byte or double-byte likelihood estimates.

First we show how to construct a candidate list when given single-byte plaintext likelihoods. While it is trivial to generate the two most likely candidates, beyond this point the computation becomes more tedious. Our solu- tion is to incrementally compute the *N *most likely can- didates based on their length. That is, we first compute the *N *most likely candidates of length 1, then of length 2, and so on. Algorithm gives a high-level implemen- tation of this idea. Variable *P*

*r*

[*i*] denotes the *i*-th most likely plaintext of length *r*, having a likelihood of *E*

*r* [*i*].

The two min operations are needed because in the initial loops we are not yet be able to generate *N *candidates, i.e., there only exist 256

*r*

plaintexts of length *r*. Picking the µ

′

which maximizes *pr* (µ

′

) can be done efficiently using a priority queue. In practice, only the latest two versions of lists *E *and *P *need to be stored. To better maintain numeric stability, and to make the computation more efficient, we perform calculations using the loga- rithm of the likelihoods. We implemented Algorithm and report on its performance in Sect. where we use it to attack a wireless network protected by WPA-TKIP.

To generate a list of candidates from double-byte like- lihoods, we first show how to model the likelihoods as a hidden Markov model (HMM). This allows us to present a more intuitive version of our algorithm, and refer to the extensive research in this area if more efficient im- plementations are needed. The algorithm we present can be seen as a combination of the classical Viterbi algo- rithm, and Algorithm Even though it is not the most optimal one, it still proved sufficient to significantly im- prove plaintext recovery (see Sect. For an introduc- tion to HMMs we refer the reader to Essentially an HMM models a system where the internal states are not observable, and after each state transition, output is (probabilistically) produced dependent on its new state.

Input: *L *: Length of the unknown plaintext λ

′

1 ≤*r*≤*L*, 0≤µ≤255

: single-byte likelihoods

*N* : Number of candidates to generate

Returns: List of candidates in decreasing likelihood

*P* [1] ← ε *E* [1] ← 0

for *r* = 1 to *L *do for

µ = 0 to 255 do

*pos* (µ) ← 1 *pr* (µ) ← *E* *r* −1

[1] + log(λ

*r*, µ

) for *i* = 1 to min(*N*, 256

*r*

) do µ ← µ

- 1 = µ

Input: *L *: Length of the unknown plaintext plus two

### 2 E

*r* −1

) then

*r* −2

) > min(*N*, 256

1

) if *pos* (µ

*r*, µ ^{1 , µ} ^{2}

)] + log(λ

1

, *pos* (µ

1

[µ

1

) ← *E*

(µ

*pr* (µ

) + 1

1

) ← *pos*(µ

1

*pos* (µ

)

*r*, µ _{1 ,} µ _{2}

)] + log(λ

1

, *pos* (µ

*pr*

) ← −∞ return *P*

1

We use our plaintext recovery techniques to decrypt a full packet. From this decrypted packet the MIC key can be derived, allowing an attacker to inject and decrypt pack- ets. The attack takes only an hour to execute in practice.

IP of the victim is know, and incoming connections to- wards it are not blocked, we can simply send identical packets to the victim. Otherwise we induce the victim into opening a TCP connection to an attacker-controlled server. This connection is then used to transmit identical packets to the victim. A straightforward way to accom- plish this is by social engineering the victim into visit- ing a website hosted by the attacker. The browser will open a TCP connection with the server in order to load the website. However, we can also employ more sophis- ticated methods that have a broader target range. One

We show how to fulfil the first requirement of a success- ful attack: the generation of identical packets. If the

5.2 Injecting Identical Packets

With our per-TSC keystream distributions we obtained similar results to that of Paterson et al. By run- ning simulations we confirmed that the odd byte posi- tions can be recov- ered with a higher probability than others. Similarly, the bytes at positions 49-51 and 63-67 are generally recov- ered with higher probability as well. Both observations will be used to optimize the attack in practice.

keys per TSC value to estimate the keystream distribu- tion for the first 128 bytes. Using our distributed setup the generation of these statistics took 10 CPU years.

32

The downside of this attack is that it requires detailed per-TSC keystream statistics. Paterson at al. generated statistics for the first 512 bytes, which took 30 CPU years However, in our attack we only need these statistics for the first few keystream bytes. We used 2

*r*, µ for every unknown byte at a given position *r*.

likelihoods, for one plaintext byte, are combined by multiplying them over all TSC pairs. In a sense this is similar to combining multiple types of biases as done in Sect. though here the different types of bi- ases are known to be independent. We use the single-byte variant of the attack §4.1] to obtain likelihoods λ

2

We rely on the attack of Paterson et al. to compute plain- text likelihood estimates They noticed that the first three bytes of the per-packet RC4 key are public. As explained in Sect. the first three bytes are fully determined by the TKIP Sequence Counter (TSC). It was observed that this dependency causes strong TSC- dependent biases in the keystream which can be used to improve the plaintext likelihood estimates. For each TSC value they calculated plaintext likelihoods based on empirical, per-TSC, keystream distributions. The resulting 256

5.1 Calculating Plaintext Likelihoods

. In Sect. we use this algorithm to generate a list of cookies. Algorithm This is because it has to store the *N *most likely candidates for each possible ending value µ. We remind the reader that our goal is not to present the most optimal algorithm. Instead, by showing how to model the problem as an HMM, we can rely on related work in this area for more efficient algorithms Since an HMM can be modelled as a graph, all *k*-shortest path algorithms are also applicable Finally, we remark that even our simple variant sufficed to significantly im- prove plaintext recovery rates (see Sect.

*r* −1 [µ

*L*

has to be executed only for the value *m*

2

of the plaintext are known. During the last round of the outer for-loop, the loop over µ

*L*

and last byte *m*

1

The simplest form of such an algorithm keeps track of the *N *best candidates ending in a particular value µ, and is shown in Algorithm we assume the first byte *m*

, : ] algorithm) can be used, examples being

*L*

[*m*

*N*

1

, *i* ] ← *E*

*m*

2

for *r* = 3 to *L *do for µ

2

k µ

1

, 1 ] ← *m*

2

[µ

2

*P*

)

1,*m* ^{1 , µ} ^{2}

, 1 ] ← log(λ

[µ

= 0 to 255 do for µ

2

*E*

= 0 to 255 do

2

Returns: List of candidates in decreasing likelihood for µ

*N* : Number of candidates to generate

: double-byte likelihoods

1 ≤*r*<*L*, 0≤µ _{1 ,} µ _{2} ≤255

: known first and last byte λ

*L*

and *m*

1

2

1

2

1

[µ

*r*

)] k µ

1

, *pos* (µ

1

*r* −1 [µ

, *i* ] ← *P*

2

[µ

*P* *r*

← µ which maximizes *pr*(µ)

) do µ

= 0 to 255 do

*r* −1

) for *i* = 1 to min(*N*, 256

*r*, µ _{1} , µ _{2}

, 1 ] + log(λ

1

[µ

*r* −1

) ← *E*

1

*pr* (µ

) ← 1

1

*pos* (µ

### 5 Attacking WPA-TKIP

such method is abusing the inclusion of (insecure) third- party resources on popular websites For example, an attacker can register a mistyped domain, accidentally used in a resource address (e.g., an image URL) on a popular website. Whenever the victim visits this website and loads the resource, a TCP connection is made to the server of the attacker. In these types of vulnerabil- ities were found to be present on several popular web- sites. Additionally, any type of web vulnerability that can be abused to make a victim execute JavaScript can be utilised. In this sense, our requirements are more relaxed than those of the recent attacks on SSL and TLS, which

11

2 ^{22}

2 ^{26}

1

3

5

7

9

13

2 ^{14}

15 Figure 9: Median position of a candidate with a correct

ICV with nearly 2

30

candidates. Results are based on 256 simulations each. that the TKIP ICV is a simple CRC checksum which we can easily verify ourselves. Hence we can detect bad candidates by inspecting their CRC checksum. We now generate a plaintext candidate list, and traverse it until we find a packet having a correct CRC. This drastically im- proves the probability of simultaneously decrypting all bytes. From the decrypted packet we can derive the TKIP MIC key

Figure shows the success rate of finding a packet with a good ICV and deriving the correct MIC key. For comparison, it also includes the success rates had we only used the two most likely candidates. Figure shows the median position of the first candidate with a correct

ICV. We plot the median instead of average to lower in- fluence of outliers, i.e., at times the correct candidate was unexpectedly far (or early) in the candidate list.

The question that remains how to determine the con- tents of the unknown fields in the IP and TCP packet. More precisely, the unknown fields are the internal IP and port of the client, and the IP time-to-live (TTL) field. One observation makes this clear: both the IP and TCP header contain checksums. Therefore, we can apply ex- actly the same technique (i.e., candidate generation and pruning) to derive the values of these fields with high

2 ^{18}

2 ^{10}

*require* the ability to run JavaScript code in the victim’s

5

browser Another method is to hijack an exist- ing TCP connection of the victim, which under certain conditions is possible without a man-in-the-middle posi- tion We conclude that, while there is no universal method to accomplish this, we can assume control over a TCP connection with the victim. Using this connection we inject identical packets by repeatedly retransmitting identical TCP packets. Since retransmissions are valid TCP behaviour, this will work even if the victim is be- hind a firewall.

We now determine the optimal structure of the injected packet. A naive approach would be to use the shortest possible packet, meaning no TCP payload is included. Since the total size of the LLC/SNAP, IP, and TCP header is 48 bytes, the MIC and ICV would be located at posi- tion 49 up to and including 60 (see Fig. At these locations 7 bytes are strongly biased. In contrast, if we use a TCP payload of 7 bytes, the MIC and ICV are lo- cated at position 56 up to and including 60. In this range 8 bytes are strongly biased, resulting in better plaintext likelihood estimates. Through simulations we confirmed that using a 7 byte payload increases the probability of successfully decrypting the MIC and ICV. In practice, adding 7 bytes of payload also makes the length of our injected packet unique. As a result we can easily identify and capture such packets. Given both these advantages, we use a TCP data packet containing 7 bytes of payload.

Our goal is to decrypt the injected TCP packet, including its MIC and ICV fields. Note that all these TCP packets will be encrypted with a different RC4 key. For now we assume all fields in the IP and TCP packet are known, and we will later show why we can safely make this as- sumption. Hence, only the 8-byte MIC and 4-byte ICV of the packet remain unknown. We use the per-TSC key- stream statistics to compute single-byte plaintext likeli- hoods for all 12 bytes. However, this alone would give a very low success probability of simultaneously (cor- rectly) decrypting all bytes. We solve this by realising

Ciphertext copies times 2 ^{20} Probability MIC k e y reco ver y

0% 20% 40% 60% 80% 100%

1

3

7

Ciphertext copies times 2 ^{20} Median position correct ICV

9

11

13

15

2 ^{30} candidates 2 candidates

Figure 8: Success rate of obtaining the TKIP MIC key using nearly 2

30

candidates, and using only the two best candidates. Results are based on 256 simulations each.

### 5.3 Decrypting a Complete Packet

success rates. This can be done independently of each other, and independently of decrypting the MIC and ICV.

Another method to obtain the internal IP is to rely on HTML5 features. If the initial TCP connection is created by a browser, we can first send JavaScript code to obtain the internal IP of the victim using WebRTC We also noticed that our NAT gateway generally did not modify the source port used by the victim. Consequently we can simply read this value at the server. The TTL field can also be determined without relying on the IP checksum. Using a traceroute command we count the number of hops between the server and the client, allowing us to derive the TTL value at the victim.

To test the plaintext recovery phase of our attack we cre- ated a tool that parses a raw pcap file containing the cap- tured Wi-Fi packets. It searches for the injected packets, extracts the ciphertext statistics, calculates plaintext like- lihoods, and searches for a candidate with a correct ICV. From this candidate, i.e., decrypted injected packet, we derive the MIC key.

For the ciphertext generation phase we used an OpenVZ VPS as malicious server. The incoming TCP connection from the victim is handled using a custom tool written in Scapy. It relies on a patched version of Tcpreplay to rapidly inject the identical TCP packets.

The victim machine is a Latitude E6500 and is connected to an Asus RT-N10 router running Tomato 1.28. The victim opens a TCP connection to the malicious server by visiting a website hosted on it. For the attacker we used a Compaq 8510p with an AWUS036nha to capture the wireless traffic. Under this setup we were able to generate roughly 2500 packets per second. This number was reached even when the victim was actively brows- ing YouTube videos. Thanks to the 7-byte payload, we uniquely detected the injected packet in all experiments without any false positives.

We ran several test where we generated and captured traffic for (slightly more) than one hour. This amounted to, on average, capturing 9.5 · 2

20

different encryptions of the packet being injected. Retransmissions were filtered based on the TSC of the packet. In nearly all cases we successfully decrypted the packet and derived the MIC key. Recall from Sect. that this MIC key is valid as long as the victim does not renew its PTK, and that it can be used to inject and decrypt packets from the AP to the victim. For one capture our tool found a packet with a correct ICV, but this candidate did not correspond to the actual plaintext. While our current evaluation is limited in the number of captures performed, it shows the attack is practically feasible, with overall success probabilities appearing to agree with the simulated results of Fig.

Listing 3: Manipulated HTTP request, with known plain- text surrounding the cookie at both sides. _{1 GET / HTTP/1.1} _{2 Host: site.com} _{3 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:32.0)}

Gecko/20100101 Firefox/32.0 _{4 Accept: text/html,application/xhtml+xml,application/} xml;q=0.9,*/*;q=0.8 _{5 Accept-Language: en-US,en;q=0.5} _{6 Accept-Encoding: gzip, deflate}

_{7}

6 Decrypting HTTPS Cookies

### 5.4 Empirical Evaluation

We inject known data around a cookie, enabling use of the *AB* S*AB *biases. We then show that a HTTPS cookie can be brute-forced using only 75 hours of ciphertext.

6.1 Injecting Known Plaintext

We want to be able to predict the position of the targeted cookie in the encrypted HTTP requests, and surround it with known plaintext. To fix ideas, we do this for the se- cure auth cookie sent to https://site.com. Similar to previous attacks on SSL and TLS, we assume the at- tacker is able to execute JavaScript code in the victim’s browser In our case, this means an active man- in-the-middle (MiTM) position is used, where plaintext HTTP channels can be manipulated. Our first realisa- tion is that an attacker can predict the length and con- tent of HTTP headers preceding the Cookie field. By monitoring plaintext HTTP requests, these headers can be sniffed. If the targeted auth cookie is the first value in the Cookie header, this implies we know its position in the HTTP request. Hence, our goal is to have a layout as shown in Listing Here the targeted cookie is the first value in the Cookie header, preceded by known headers, and followed by attacker injected cookies.

To obtain the layout in Listing we use our MiTM po- sition to redirect the victim to http://site.com, i.e., to the target website over an insecure HTTP channel. If the target website uses HTTP Strict Transport Secu- rity (HSTS), but does not use the includeSubDomains attribute, this is still possible by redirecting the victim to a (fake) subdomain Since few websites use HSTS, and even fewer use it properly this redirection will likely succeed. Against old browsers HSTS can even be bypassed completely Since secure cookies guarantee only confidentiality but not integrity, the in- secure HTTP channel can be used to overwrite, remove, or inject secure cookies 4.1.2.5]. This allows us to remove all cookies except the auth cookie, pushing it to the front of the list. After this we can inject cookies that will be included after the auth cookie. An example of a HTTP(S) request manipulated in this manner is shown in Listing Here the secure auth cookie is surrounded by known plaintext at both sides. This allows us to use Mantin’s *AB* S*AB *bias when calculating plaintext likeli- hoods.

6.2 Brute-Forcing The Cookie

0% 20% 40% 60% 80% 100%

To test our attack in practice we implemented a tool in C which monitors network traffic and collects the nec- essary ciphertext statistics. This requires reassembling the TCP and TLS streams, and then detecting the 512- byte (encrypted) HTTP requests. Similar to optimizing the generation of datasets as in Sect. we cache sev- eral requests before updating the counters. We also cre- ated a tool to brute-force the cookie based on the gen- erated candidate list. It uses persistent connections and HTTP pipelining §6.3.2]. That is, it uses one con- nection to send multiple requests without waiting for each response.

XMLHttpRequest objects to issue Cross-Origin Requests to the targeted website. The browser will auto- matically add the secure cookie to these (encrypted) re- quests. Due to the same-origin policy we cannot read the replies, but this poses no problem, we only require that the cookie is included in the request. The requests are sent inside HTML5 WebWorkers. Essentially this means our JavaScript code will run in the background of the browser, and any open page(s) stay responsive. We use GET requests, and carefully craft the values of our in- jected cookies so the targeted auth cookie is always at a fixed position in the keystream (modulo 256). Recall that this alignment is required to make optimal use of the Fluhrer-McGrew biases. An attacker can learn the re- quired amount of padding by first letting the client make a request without padding. Since RC4 is a stream cipher, and no padding is added by the TLS protocol, an attacker can easily observe the length of this request. Based on this information it is trivial to derive the required amount of padding.

candidates, and only the most likely candidate, dependent on the number of collected ciphertexts. Results based on 256 simulations each. when performing a man-in-the-middle attack, we can in- ject JavaScript into any plaintext HTTP connection. We then use

23

Figure 10: Success rate of brute-forcing a 16-character cookie using roughly 2

2 ^{23} candidates 1 candidate

15

13

11

9

7

5

3

1

Ciphertext copies times 2 ^{27} Probability successful br ute−f orce

In contrast to passwords, many websites do not protect against brute-forcing cookies. One reason for this is that the password of an average user has a much lower en- tropy than a random cookie. Hence it makes sense to brute-force a password, but not a cookie: the chance of successfully brute-forcing a (properly generated) cookie is close to zero. However, if RC4 can be used to con- nect to the web server, our candidate generation algo- rithm voids this assumption. We can traverse the plain- text candidate list in an attempt to brute-force the cookie.

The main requirement of our attack is being able to col- lect sufficiently many encryptions of the cookie, i.e., hav- ing many ciphertexts. We fulfil this requirement by forc- ing the victim to generate a large number of HTTPS re- quests. As in previous attacks on TLS we ac- complish this by assuming the attacker is able to execute JavaScript in the browser of the victim. For example,

6.3 Empirical Evaluation

encryptions of the cookie have been captured. We conjecture that generating more candidates will further increase success rates.

27

brute-force at- tempts, success rates of more than 94% are obtained once 9 · 2

23

attempts. For compar- ison, we also include the probability of decrypting the cookie if only the most likely plaintext was used. This also allows for an easier comparison with the work of AlFardan et al. Note that they only use the Fluhrer- McGrew biases, whereas we combine serveral *AB* S*AB* biases together with the Fluhrer-McGrew biases. We conclude that our brute-force approach, as well as the inclusion of the *AB* S*AB *biases, significantly improves success rates. Even when using only 2

23

Figure shows the success rate of brute-forcing a 16- character cookie using at most 2

2 only loop over allowed characters.

and µ

1

µ

Since we are targeting a cookie, we can exclude cer- tain plaintext values. As RFC 6265 states, a cookie value can consists of at most 90 unique characters §4.1.1]. A similar though less general observation was already made by AlFardan et al. Our observation allows us to give a tighter bound on the required number of cipher- texts to decrypt a cookie, even in the general case. In practice, executing the attack with a reduced character set is done by modifying Algorithm so the for-loops over

In our experiments the victim uses a 3.1 GHz Intel Core i5-2400 CPU with 8 GB RAM running Windows 7. Internet Explorer 11 is used as the browser. For the server a 3.4 GHz Intel Core i7-3770 CPU with 8 GB RAM is

[*Z*

The first practical attack on WPA-TKIP was found by Beck and Tews Recently several works stud- ied the per-packet key construction both analytically For our attack we replicated part of the results of Paterson et al. and are the first to demonstrate this type of attack in prac- tice. In AlFardan et al. ran experiments where the two most likely plaintext candidates were generated us- ing single-byte likelihoods However, they did not present an algorithm to return arbitrarily many candi- dates, nor extended this to double-byte likelihoods.

*r*

= *Z*

*r*

sume the internal state S is a random permutation, which is true only after a few rounds of the PRGA. Isobe et al. searched for dependencies between initial keystream bytes by empirically estimating Pr [*Z*

*r*

= *y *∧ *Z*

*r* −*a*

= *x*] for ≤ *x*, *y *≤ 255, 2 ≤ *r *≤ 256, and 1 ≤ *a *≤ 8 They did not discover any new biases using their approach.

Mironov modelled RC4 as a Markov chain and recom- mended to skip the initial 12 · 256 keystream bytes Paterson et al. generated keystream statistics over con- secutive keystream bytes when using the TKIP key struc- ture However, they did not report which (new) bi- ases were present. Through empirical analysis, we show that biases between consecutive bytes are present even when using RC4 with random 128 bit keys.

The SSL and TLS protocols have undergone wide scrutiny Our work is based on the attack of AlFardan et al., who estimated that 13 · 2

) was dis- covered by Basu et al. While this resembles our new short-term bias Pr

30

ci- phertexts are needed to recover a 16-byte cookie with high success rates We reduce this number to 9 · 2

27

using several techniques, the most prominent being us- age of likelihoods based on Mantin’s *AB* S*AB *bias Isobe et al. used Mantin’s *AB* S*AB *bias, in combination with previously decrypted bytes, to decrypt bytes after position 257 a guess- and-determine algorithm combines *AB* S*AB *and Fluhrer- McGrew biases, requiring roughly 2

34

ciphertexts to de- crypt an individual byte with high success rates.

### 7 Related Work

8 Conclusion

While previous attacks against RC4 in TLS and WPA- TKIP were on the verge of practicality, our work pushes them towards being practical and feasible. After cap- turing 9 · 2

27

encryptions of a cookie sent over HTTPS, we can brute-force it with high success rates in negligi- ble time. By running JavaScript code in the browser of the victim, we were able to execute the attack in practice within merely 52 hours. Additionally, by abusing RC4 biases, we successfully attacked a WPA-TKIP network within an hour. We consider it surprising this is possi- ble using only known biases, and expect these types of attacks to further improve in the future. Based on these results, we strongly urge people to stop using RC4.

−15

Due to its popularity, RC4 has undergone wide crypt- analysis. Particularly well known are the key recovery attacks that broke WEP Several other key-related biases and improvements of the orig- inal WEP attack have also been studied

27 ciphertexts.

−8

used. We use nginx as the web server, and configured RC4-SHA1 with RSA as the only allowable cipher suite. This assures that RC4 is used in all tests. Both the server and client use an Intel 82579LM network card, with the link speed set to 100 Mbps. With an idle browser this setup resulted in an average of 4450 requests per second. When the victim was actively browsing YouTube videos this decreased to roughly 4100. To achieve such num- bers, we found it’s essential that the browser uses persis- tent connections to transmit the HTTP requests. Other- wise a new TCP and TLS handshake must be performed for every request, whose round-trip times would signif- icantly slow down traffic generation. In practice this means the website must allow a keep-alive connec- tion. While generating requests the browser remained re- sponsive at all times. Finally, our custom tool was able to test more than 20000 cookies per second. To execute the attack with a success rate of 94% we need roughly 9

· 2

27

ciphertexts. With 4450 requests per seconds, this means we require 75 hours of data. Compared to the (more than) 2000 hours required by AlFardan et al.

§5.3.3] this is a significant improvement. We remark that, similar to the attack of AlFardan et al. our attack also tolerates changes of the encryption keys. Hence, since cookies can have a long lifetime, the generation of this traffic can even be spread out over time. With 20000 brute-force at- tempts per second, all 2

= *Z*

23

[*Z*

We refer to Sect. In addition to these, the long-term bias Pr

candidates for the cookie can be tested in less than 7 minutes. We have executed the attack in practice, and success- fully decrypted a 16-character cookie. In our instance, capturing traffic for 52 hours already proved to be suf- ficient. At this point we collected 6.2 · 2

estimate. These results push the attack from being on the verge of practicality, to feasible, though admittedly somewhat time-consuming.

27

After processing the ciphertexts, the cookie was found at position 46229 in the candidate list. This serves as a good example that, if the attacker has some luck, less cipher- texts are needed than our 9 · 2

- 1 | 2 ·
*Z*

(1 + 2

*r*

*r*

*r*

= *i*

*r*

] = 2

- 1 ], in their analysis they as-

### 9 Acknowledgements

[19] IEEE Std 802.11-2012. *Wireless LAN Medium*

Mjølsnes. An improved attack on TKIP. In *14th*

*Nordic Conference on Secure IT Systems* , NordSec ’09, 2009.

[17] B. Harris and R. Hunt. Review: TCP/IP security threats and attack methods. *Computer Communi-*

*cations* , 22(10):885–897, 1999.

[18] ICSI. The ICSI certificate notary. Retrieved 22 Feb.

2015, from

*Access Control (MAC) and Physical Layer (PHY)* *Specifications* , 2012.

[15] S. S. Gupta, S. Maitra, W. Meier, G. Paul, and S. Sarkar. Dependence in IV-related bytes of RC4 key enhances vulnerabilities in WPA. Cryptology ePrint Archive, Report 2013/476, 2013.

[20] T. Isobe, T. Ohigashi, Y. Watanabe, and M. Morii.

Full plaintext recovery attack on broadcast RC4. In *FSE* , 2013. [21] A. Klein. Attacks on the RC4 stream cipher. *De-*

*signs, Codes and Cryptography* , 48(3):269–286, 2008.

[22] S. Maitra and G. Paul. New form of permutation bias and secret key leakage in keystream bytes of RC4. In *Fast Software Encryption*, pages 253–269. Springer, 2008. [23] S. Maitra, G. Paul, and S. S. Gupta. Attack on broadcast RC4 revisited. In *Fast Software Encryp-*

*tion* , 2011.

[24] I. Mantin. Predicting and distinguishing attacks on RC4 keystream generator. In *EUROCRYPT*, 2005. [25] I. Mantin and A. Shamir. A practical attack on broadcast RC4. In *FSE*, 2001.

[16] F. M. Halvorsen, O. Haugen, M. Eian, and S. F.

We thank Kenny Paterson for providing valuable feed- back during the preparation of the camera-ready paper, and Tom Van Goethem for helping with the JavaScript traffic generation code.

This research is partially funded by the Research Fund KU Leuven. Mathy Vanhoef holds a Ph. D. fellowship of the Research Foundation - Flanders (FWO).

RFC 6265, 2011. [4] R. Basu, S. Ganguly, S. Maitra, and G. Paul. A complete characterization of the evolution of RC4 pseudo random generation algorithm. *J. Mathemat-* *ical Cryptology* , 2(3):257–289, 2008.

References

[1] N. J. Al Fardan and K. G. Paterson. Lucky thirteen: Breaking the TLS and DTLS record protocols. In *IEEE Symposium on Security and Privacy* , 2013.

[2] N. J. AlFardan, D. J. Bernstein, K. G. Paterson,

B. Poettering, and J. C. N. Schuldt. On the secu- rity of RC4 in TLS and WPA. In *USENIX Security*

*Symposium* , 2013.

[3] A. Barth. HTTP state management mechanism.

[5] D. Berbecaru and A. Lioy. On the robustness of ap- plications based on the SSL and TLS security pro- tocols. In *Public Key Infrastructure*, pages 248– 264. Springer, 2007.

*areas in cryptography* . Springer, 2001.

[6] K. Bhargavan, A. D. Lavaud, C. Fournet, A. Pironti, and P. Y. Strub. Triple handshakes and cookie cut- ters: Breaking and fixing authentication over TLS. In *Security and Privacy (SP), 2014 IEEE Sympo-* *sium on* , pages 98–113. IEEE, 2014.

[7] B. Canvel, A. P. Hiltgen, S. Vaudenay, and M. Vuagnoux. Password interception in a SSL/TLS channel. In *Advances in Cryptology (CRYPTO)*, 2003.

[8] T. Dierks and E. Rescorla. The transport layer secu- rity (TLS) protocol version 1.2. RFC 5246, 2008. [9] T. Duong and J. Rizzo. Here come the xor ninjas.

In *Ekoparty Security Conference*, 2011. [10] D. Eppstein. k-best enumeration. *arXiv preprint* *arXiv:1412.5075* , 2014.

[11] R. Fielding and J. Reschke. Hypertext transfer protocol (HTTP/1.1): Message syntax and routing.

RFC 7230, 2014.

[12] S. Fluhrer, I. Mantin, and A. Shamir. Weaknesses in the key scheduling algorithm of RC4. In *Selected*

[13] S. R. Fluhrer and D. A. McGrew. Statistical analy- sis of the alleged RC4 keystream generator. In *FSE*, 2000. [14] C. Fuchs and R. Kenett. A test for detecting outlying cells in the multinomial distribution and two-way contingency tables. *J. Am. Stat. Assoc.*, 75:395–398, 1980.

[26] I. Mironov. (Not so) random shuffles of RC4. In *CRYPTO* , 2002. [27] N. Nikiforakis, L. Invernizzi, A. Kapravelos,

*Secur.* , 7(2), 2004.

[40] N. Seshadri and C.-E. W. Sundberg. List Viterbi decoding algorithms with applications.

*IEEE* *Transactions on Communications* , 42(234):313–

323, 1994. [41] B. Smyth and A. Pironti. Truncating TLS con- nections to violate beliefs in web applications. In

*WOOT’13: 7th USENIX Workshop on Offensive* *Technologies* , 2013.

[42] F. K. Soong and E.-F. Huang. A tree-trellis based fast search for finding the n-best sentence hypothe- ses in continuous speech recognition. In *Acoustics,*

*Speech, and Signal Processing, 1991. ICASSP-91.,* *1991 International Conference on* , pages 705–708.

IEEE, 1991. [43] A. Stubblefield, J. Ioannidis, and A. D. Rubin. A key recovery attack on the 802.11b wired equiva- lent privacy protocol (WEP). *ACM Trans. Inf. Syst.*

[44] E. Tews and M. Beck. Practical attacks against WEP and WPA. In *Proceedings of the second ACM*

[39] P. Sepehrdad, S. Vaudenay, and M. Vuagnoux. Dis- covery and exploitation of new biases in RC4.

*conference on Wireless network security* , WiSec ’09, 2009.

[45] E. Tews, R.-P. Weinmann, and A. Pyshkin. Break- ing 104 bit WEP in less than 60 seconds. In *In-*

*formation Security Applications* , pages 188–202.

Springer, 2007. [46] Y. Todo, Y. Ozawa, T. Ohigashi, and M. Morii. Fal- sification attacks against WPA-TKIP in a realistic environment. *IEICE Transactions*, 95-D(2), 2012. [47] T. Van Goethem, P. Chen, N. Nikiforakis,

L. Desmet, and W. Joosen. Large-scale security analysis of the web: Challenges and findings. In

*TRUST* , 2014.

[48] M. Vanhoef and F. Piessens. Practical verification of WPA-TKIP vulnerabilities. In *ASIACCS*, 2013. [49] M. Vanhoef and F. Piessens. Advanced Wi-Fi at- tacks using commodity hardware. In *ACSAC*, 2014. [50] S. Vaudenay and M. Vuagnoux. Passive–only key recovery attacks on RC4. In *Selected Areas in*

In *Selected Areas in Cryptography*, pages 74–91. Springer, 2011.

*of Cryptology* , 27(1):67–108, 2014.

S. Van Acker, W. Joosen, C. Kruegel, F. Piessens, and G. Vigna. You are what you include: Large- scale evaluation of remote JavaScript inclusions. In

Big bias hunting in amazonia: Large-scale compu- tation and exploitation of RC4 biases. In *Advances*

*Proceedings of the 2012 ACM conference on Com-* *puter and communications security* , 2012.

[28] D. Nilsson and J. Goldberger. Sequentially finding the n-best list in hidden Markov models. In *Interna-*

*tional Joint Conferences on Artificial Intelligence* , 2001.

[29] T. Ohigashi, T. Isobe, Y. Watanabe, and M. Morii.

Full plaintext recovery attacks on RC4 using multi- ple biases. *IEICE TRANSACTIONS on Fundamen-*

*tals of Electronics, Communications and Computer* *Sciences* , 98(1):81–91, 2015.

[30] K. G. Paterson, B. Poettering, and J. C. Schuldt.

*in Cryptology — ASIACRYPT* , 2014.

(Non-)random sequences from (non-)random per- mutations - analysis of RC4 stream cipher. *Journal*

[31] K. G. Paterson, J. C. N. Schuldt, and B. Poettering.

Plaintext recovery attacks against WPA/TKIP. In *FSE* , 2014. [32] G. Paul, S. Rathi, and S. Maitra. On non-negligible bias of the first output byte of RC4 towards the first three bytes of the secret key. *Designs, Codes and* *Cryptography* , 49(1-3):123–134, 2008. [33] S. Paul and B. Preneel. A new weakness in the

RC4 keystream generator and an approach to im- prove the security of the cipher. In *FSE*, 2004. [34] R Core Team. *R: A Language and Environment for*

*Statistical Computing* . R Foundation for Statistical Computing, 2014.

[35] L. Rabiner. A tutorial on hidden Markov mod- els and selected applications in speech recognition.

*Proceedings of the IEEE* , 1989.

[36] M. Roder and R. Hamzaoui. Fast tree-trellis list Viterbi decoding. *Communications, IEEE Transac-* *tions on* , 54(3):453–461, 2006.

[37] D. Roesler. STUN IP address requests for We- bRTC. Retrieved 17 June 2015, from [38] S. Sen Gupta, S. Maitra, G. Paul, and S. Sarkar.

*Cryptography* , pages 344–359. Springer, 2007.