| 1 | BEP: 8 |
|---|
| 2 | Title: Tracker Peer Obfuscation |
|---|
| 3 | Version: $Revision$ |
|---|
| 4 | Last-Modified: $Date$ |
|---|
| 5 | Author: David Harrison <dave@bittorrent.com>, Anthony Ciani <tony@ciani.phy.uic.edu>, Arvid Norberg <arvid@bittorrent.com>, Greg Hazel <greg@bittorrent.com> |
|---|
| 6 | Status: Draft |
|---|
| 7 | Type: Standards Track |
|---|
| 8 | Created: 31-Jan-2008 |
|---|
| 9 | Post-History: |
|---|
| 10 | |
|---|
| 11 | This extends the tracker protocol to support simple obfuscation of the |
|---|
| 12 | peers it returns, using the infohash as a shared secret between the |
|---|
| 13 | peer and the tracker. The obfuscation does not provide any security |
|---|
| 14 | against eavesdroppers that know the infohash of the torrent. The goal |
|---|
| 15 | is to prevent internet service providers and other network |
|---|
| 16 | administrators from blocking or disrupting bittorrent traffic |
|---|
| 17 | connections that span between the receiver of a tracker response and |
|---|
| 18 | any peer IP-port appearing in that tracker response. |
|---|
| 19 | |
|---|
| 20 | The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", |
|---|
| 21 | "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are |
|---|
| 22 | to be interpreted as described in IETF `RFC 2119`_. |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | Announce Parameter |
|---|
| 26 | ================== |
|---|
| 27 | |
|---|
| 28 | When using this extension, instead of passing the ``info_hash`` parameter |
|---|
| 29 | to the tracker, an ``sha_ih`` is passed. |
|---|
| 30 | |
|---|
| 31 | The value of ``sha_ih`` MUST be the info-hash of the torrent, with a second |
|---|
| 32 | SHA-1 applied to it. |
|---|
| 33 | |
|---|
| 34 | For example if a torrent has infohash with hex representation |
|---|
| 35 | ``aaf4c61ddcc5e8a2dabedef3b482cd9aea9434d`` then its ``sha_ih`` is |
|---|
| 36 | ``sha1(infohash)='6b4f89a54e2d27ecd7e8da5b4ab8fd9d1d8b119'``. |
|---|
| 37 | |
|---|
| 38 | The value MUST be url encoded, just like the ``info_hash``. Thus the |
|---|
| 39 | ``sha_ih`` above when url encoded becomes |
|---|
| 40 | ``kO%89%A5N-%27%EC%D7%E8%DA%05%B4%AB%8F%D9%D1%D8%B1%19``. |
|---|
| 41 | |
|---|
| 42 | This extension does not change the semantics of any parameter passed |
|---|
| 43 | in the peer's announce. |
|---|
| 44 | |
|---|
| 45 | Announce Response |
|---|
| 46 | ================= |
|---|
| 47 | |
|---|
| 48 | If the tracker supports this extension, the response should be exactly the |
|---|
| 49 | same as if the ``info_hash`` was passed, except that any field that contains |
|---|
| 50 | peer information (such as ``peers``, ``peers6`` or any other field defined |
|---|
| 51 | by another extension) MUST be obfuscated as described in the next section. |
|---|
| 52 | |
|---|
| 53 | There are additional parameters the tracker may OPTIONALLY return. |
|---|
| 54 | These are discussed in the optimizations_ section. |
|---|
| 55 | |
|---|
| 56 | Peer List Obfuscation |
|---|
| 57 | ===================== |
|---|
| 58 | |
|---|
| 59 | We distinguish between the *tracker peer list* and the *returned peer |
|---|
| 60 | list*. The *tracker peer list* contains the ip-port pairs of all |
|---|
| 61 | known peers in a given torrent, i.e., those peers that have reported to |
|---|
| 62 | the tracker that they are downloading or seeding a given file with a |
|---|
| 63 | given infohash. The tracker may store this peer list however it |
|---|
| 64 | wishes. The *returned peer list* contains a packed array of ip-port |
|---|
| 65 | pairs conforming to the BitTorrent protocol specification. If the |
|---|
| 66 | swarm is sufficiently large then the returned ip-port pairs constitute |
|---|
| 67 | a subset of the ip-port pairs in the *tracker peer list*. |
|---|
| 68 | |
|---|
| 69 | The returned peer list is encrypted using RC4-drop768 encryption using |
|---|
| 70 | the infohash as a shared secret and optionally employing an |
|---|
| 71 | initialization vector. |
|---|
| 72 | |
|---|
| 73 | For the remainder of this document RC4 refers to RC4-drop768. In the |
|---|
| 74 | process of encryption, RC4 generates a pseudorandom string that is |
|---|
| 75 | XOR'd with the plaintext to generate the ciphertext. The receiver |
|---|
| 76 | recovers the plaintext by generating the same pseudorandom string and |
|---|
| 77 | XOR'ing it with the ciphertext. In generating the pseudorandom |
|---|
| 78 | string, the tracker and client MUST discard the first 768 bytes. The |
|---|
| 79 | next 8 bytes in the pseudorandom string are reserved for optimizations |
|---|
| 80 | discussed in the next section. |
|---|
| 81 | |
|---|
| 82 | To communicate an initialization vector, the tracker includes in the |
|---|
| 83 | bencoded response the key ``iv`` with value set to a byte string |
|---|
| 84 | containing the initialization vector. The initialization vector can |
|---|
| 85 | be of arbitrary length and is sent in plaintext. |
|---|
| 86 | |
|---|
| 87 | If the tracker sends no initialization vector then the first 64-bits |
|---|
| 88 | of the infohash are used as the RC4 key. If the tracker provides an |
|---|
| 89 | initialization vector then the RC4 key is generated by appending the |
|---|
| 90 | vector to the infohash and then hashing with SHA-1. The first 64 bits |
|---|
| 91 | of the resulting hash are then used as the RC4 key. The string from |
|---|
| 92 | which the RC4 key is derived whether it be the infohash or the SHA-1 of |
|---|
| 93 | the initialization vector appended to the infohash is called the |
|---|
| 94 | *intermediate string*. |
|---|
| 95 | |
|---|
| 96 | For example, given infohash ``aaf4c61ddcc5e8a2dabedef3b482cd9aea9434d`` |
|---|
| 97 | and initialization vector ``abcd`` both represented in hex, the RC4 key |
|---|
| 98 | is derived as follows: |
|---|
| 99 | |
|---|
| 100 | :: |
|---|
| 101 | |
|---|
| 102 | intermediate = sha1( 'aaf4c61ddcc5e8a2dabedef3b482cd9aea9434dabcd' ) |
|---|
| 103 | key = intermediate[0:64] |
|---|
| 104 | |
|---|
| 105 | where [i:j] denotes the ith through *jth* bit including the *ith* but |
|---|
| 106 | excluding the *jth*. The resulting key in hex is ``f36e9cae87cf33e0``. |
|---|
| 107 | |
|---|
| 108 | A 64-bit key is used to avoid U.S. export restrictions. |
|---|
| 109 | |
|---|
| 110 | It is RECOMMENDED that the tracker use the initialization vector, and |
|---|
| 111 | that it change the ``iv`` on roughly the same period as the rerequest |
|---|
| 112 | interval. The reasoning for this is contained in the rationale. |
|---|
| 113 | |
|---|
| 114 | |
|---|
| 115 | Optimizations |
|---|
| 116 | ============= |
|---|
| 117 | |
|---|
| 118 | The described optimizations are OPTIONAL for the tracker, but the |
|---|
| 119 | corresponding client-side MUST be implemented by clients that support |
|---|
| 120 | this extension. These optimizations hobble the strength of the RC4 |
|---|
| 121 | encryption in order to improve tracker performance. In the rationale_ |
|---|
| 122 | section we discuss why hobbling RC4 is reasonable and in many cases |
|---|
| 123 | has negligible foreseen effect on security. |
|---|
| 124 | |
|---|
| 125 | For the purpose of these optimizations we assume that the tracker |
|---|
| 126 | stores the tracker peer list for each infohash as a packed array that |
|---|
| 127 | can be copied directly into the response. We further assume that the |
|---|
| 128 | packed array is reused many times and that with each request the |
|---|
| 129 | tracker either returns the entire packed array or copies a single |
|---|
| 130 | contiguous substring from the tracker peer list into the response. |
|---|
| 131 | |
|---|
| 132 | If the peerlist is represented and used as assumed then to improve |
|---|
| 133 | randomness in the set of peers handed out by the tracker, it is |
|---|
| 134 | RECOMMENDED that the tracker periodically reshuffle the peerlist with |
|---|
| 135 | period similar to the rerequest interval. After each reshuffle the |
|---|
| 136 | tracker reperforms the operations described in this section. |
|---|
| 137 | |
|---|
| 138 | To reduce computation the tracker MAY cache the pseudorandom string |
|---|
| 139 | generated by RC4 and reuse it as peers arrive and depart. |
|---|
| 140 | |
|---|
| 141 | The tracker MAY also cache the encrypted tracker peer list. To |
|---|
| 142 | support this the tracker MUST pass two additional keys *i* and *n* |
|---|
| 143 | each with 32-bit integer values, except the tracker MAY omit *i* and |
|---|
| 144 | *n* when *i=0* and the *returned peer list* is the entire *tracker peer |
|---|
| 145 | list*. Whether the tracker returns *i* and *n*, the first 8 bytes of |
|---|
| 146 | the RC4 psuedorandom string are reserved for obscuring *i* and *n*. |
|---|
| 147 | We come back to this momentarily. Decryption starts by XORing from |
|---|
| 148 | *6i* bytes for ipv4 (or *18i* for ipv6) into the pseudorandom string |
|---|
| 149 | after the discarded and reserved bytes. Assuming that the tracker |
|---|
| 150 | encrypted the tracker peer list starting from the first byte after the |
|---|
| 151 | discarded and reserved bytes in the pseudorandom string then *i* also |
|---|
| 152 | corresponds to the *ith* ip-port pair in the tracker peer list. |
|---|
| 153 | |
|---|
| 154 | So that the client and the tracker do not have to generate an |
|---|
| 155 | arbitrarily long pseudorandom string to support large swarms, we |
|---|
| 156 | assume the tracker bounds the length of the pseudorandom string and |
|---|
| 157 | reports the length in ip-port pairs as the value to key *n*. *n* |
|---|
| 158 | excludes reserved and discarded bytes. We RECOMMEND that *n* be equal |
|---|
| 159 | to the length of the tracker peer list or random but within constant |
|---|
| 160 | factor of the longest peerlist returned by the tracker, whichever is |
|---|
| 161 | smaller. Thus the tracker encrypts the *jth* byte of the *ith* |
|---|
| 162 | ip-port pair in an ipv4 tracker peer list by XORing with the byte |
|---|
| 163 | *(6i+j)* `mod` *n* bytes into the pseudorandom string. |
|---|
| 164 | |
|---|
| 165 | Transmitting *i* and *n* as plaintext would significantly reduce the |
|---|
| 166 | cost for an attacker to recover the pseudorandom string. The tracker |
|---|
| 167 | MUST XOR the value of *i* with the first 32 bits of the pseudorandom |
|---|
| 168 | string. The tracker then XORs *n* with the next 32 bits from the |
|---|
| 169 | pseudorandom string (see Figure 1). |
|---|
| 170 | |
|---|
| 171 | .. figure:: bep_0008_pseudo.png |
|---|
| 172 | |
|---|
| 173 | **Figure 1:** The first 768 bytes of the RC4 pseudorandom |
|---|
| 174 | string are discarded. The key *i* in the tracker response has |
|---|
| 175 | value ``x xor i``. The key *n* has value ``y xor n``. |
|---|
| 176 | |
|---|
| 177 | We describe encryption in the following example for an ipv4 tracker peer |
|---|
| 178 | list consisting of 3 ip-port pairs, and using an RC4 pseudorandom string |
|---|
| 179 | of length *n=2*. *n* is small for purposes of illustration. Also, for the |
|---|
| 180 | purpose of illustration, the tracker returns only 2 peers at a time. |
|---|
| 181 | |
|---|
| 182 | :: |
|---|
| 183 | |
|---|
| 184 | Given the following peer list |
|---|
| 185 | (208.72.193.86, 6881), (209.81.173.15,14321), (128.213.6.8, 6881) |
|---|
| 186 | |
|---|
| 187 | As a packed array represented in hex it becomes |
|---|
| 188 | |
|---|
| 189 | d048c1561ae1d151ad0f37f180d506081ae1 |
|---|
| 190 | |
|---|
| 191 | which we XOR with an RC4 pseudorandom string excluding discarded and |
|---|
| 192 | reserved bytes, e.g., |
|---|
| 193 | |
|---|
| 194 | a496e5f9b83e835013d42226 |
|---|
| 195 | |
|---|
| 196 | to generate |
|---|
| 197 | |
|---|
| 198 | 74de24afa2df5201bedb15d72443e3f1a2df |
|---|
| 199 | |
|---|
| 200 | Because the RC4 pseudorandom string is shorter than the tracker |
|---|
| 201 | peer list, we wrap to the beginning of the pseudorandom string. |
|---|
| 202 | |
|---|
| 203 | A tracker returning the first two peers would return the bencoded |
|---|
| 204 | equivalent of:: |
|---|
| 205 | |
|---|
| 206 | peers=74de24afa2df5201bedb15d7, i=0, n=2 |
|---|
| 207 | |
|---|
| 208 | A tracker returning the second and third peer would return the |
|---|
| 209 | bencoded equivalent of:: |
|---|
| 210 | |
|---|
| 211 | peers=5201bedb15d72443e3f1a2df, i=1, n=2 |
|---|
| 212 | |
|---|
| 213 | In each response the tracker includes additional keys such as the |
|---|
| 214 | rerequest ``interval`` and the initialization vector ``iv``. |
|---|
| 215 | |
|---|
| 216 | The tracker response MUST remain a valid bencoded message. |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | Backwards Compatibility |
|---|
| 220 | ======================= |
|---|
| 221 | |
|---|
| 222 | Trackers that support obfuscation are identified in the .torrent file |
|---|
| 223 | by the inclusion of an ``obfuscate-announce-list`` which otherwise has the |
|---|
| 224 | same semantics as the ``announce-list`` key. Peers that do not support |
|---|
| 225 | obfuscation simply ignore the ``obfuscate-announce-list``. |
|---|
| 226 | |
|---|
| 227 | A client that is configured to use this extension should always send |
|---|
| 228 | the ``sha_ih`` to any tracker supporting obfuscation. The client |
|---|
| 229 | SHOULD only contact trackers in the ``announce-list`` once the client |
|---|
| 230 | has attempted all trackers in the ``obfuscate-announce-list`` and all failed. |
|---|
| 231 | |
|---|
| 232 | If a tracker that supports obfuscation wishes to allow legacy peers to |
|---|
| 233 | connect to the tracker then the announce URL should appear in both the |
|---|
| 234 | ``obfuscate-announce-list`` and the ``announce-list``. |
|---|
| 235 | |
|---|
| 236 | If a tracker URL appears in both lists running on the same port, and |
|---|
| 237 | the tracker failed to respond when selected from the |
|---|
| 238 | ``obfuscate-announce-list`` then the client MAY treat the tracker in |
|---|
| 239 | the ``announce-list`` as if it were temporarily unreachable and defer |
|---|
| 240 | trying it until it has tried other trackers in the ``announce-list``. |
|---|
| 241 | |
|---|
| 242 | Peers MUST never send both the ``info_hash`` and ``sha_ih`` parameters |
|---|
| 243 | in the same request, since that would defeat the purpose of the shared |
|---|
| 244 | secret. |
|---|
| 245 | |
|---|
| 246 | Any peer that requests with a ``sha_ih`` SHOULD implement Message |
|---|
| 247 | Stream Encryption (MSE) [#MSE]_. Any peer returned from the tracker |
|---|
| 248 | in response to a request with a ``sha_ih`` SHOULD be assumed to |
|---|
| 249 | support Message Stream Encryption. We include these provisions |
|---|
| 250 | because if a peer communicates with another peer without using MSE |
|---|
| 251 | then the BitTorrent protocol is trivially identified from the first |
|---|
| 252 | twenty bytes of the BitTorrent header and the ``info_hash`` appears in |
|---|
| 253 | plaintext as the next twenty bytes, hence also defeating the purpose |
|---|
| 254 | of the shared secret. |
|---|
| 255 | |
|---|
| 256 | If the tracker does not know enough peers assumed to support MSE to |
|---|
| 257 | return the desired number of peers then it MAY include peers that are |
|---|
| 258 | not assumed to support MSE. If a peer closes a connection in response |
|---|
| 259 | to an encrypted header then the initiating peer SHOULD try other peers |
|---|
| 260 | in the peer list returning to the peer that closed the connection only |
|---|
| 261 | when all other peers known or not yet known to support MSE have been |
|---|
| 262 | tried and have failed to provide "adequate performance." We |
|---|
| 263 | intentionally omit any definition of "adequate performance." |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | Rationale |
|---|
| 267 | ========= |
|---|
| 268 | |
|---|
| 269 | This extension directly addresses a known attack on the BitTorrent |
|---|
| 270 | protocol performed by some deployed network hardware. By obscuring |
|---|
| 271 | the ip-port pairs network hardware can no longer easily identify |
|---|
| 272 | ip-port pairs that are running BitTorrent by observing peer-to-tracker |
|---|
| 273 | communications. This deployed hardware under some conditions disrupts |
|---|
| 274 | BitTorrent connections by injecting forged TCP reset packets. Once a |
|---|
| 275 | BitTorrent connection has been identified, other attacks could be |
|---|
| 276 | performed such as severely rate limiting or blocking these |
|---|
| 277 | connections. |
|---|
| 278 | |
|---|
| 279 | This hardware was presumably deployed to get around BitTorrent |
|---|
| 280 | Message Stream Encryption [#MSE]_. Peers implementing BitTorrent Message Stream |
|---|
| 281 | Encryption obfuscate peer-to-peer connections by employing RC4 |
|---|
| 282 | encryption on every byte from the first byte transferred. BitTorrent |
|---|
| 283 | Message Stream Encryption thus increases the difficulty for a device |
|---|
| 284 | observing passing packets to identify BitTorrent peer-to-peer |
|---|
| 285 | connections. |
|---|
| 286 | |
|---|
| 287 | By using the SHA-1 of the infohash, the tracker is able to identify |
|---|
| 288 | torrents without sending the plaintext infohash and without requiring |
|---|
| 289 | an additional prior exchange of a shared secret. Where trackers now |
|---|
| 290 | maintain mappings from infohash to the corresponding torrent's |
|---|
| 291 | peerlist and other torrent-specific state, obfuscated trackers would need |
|---|
| 292 | one additional mapping from ``sha_ih`` to the torrent's state. |
|---|
| 293 | Tracker may also store encrypted versions of each torrent's peer list, |
|---|
| 294 | to increase computation performance at the expense of increasing |
|---|
| 295 | memory footprint by a constant factor. |
|---|
| 296 | |
|---|
| 297 | The obfuscation method meets the following criteria: |
|---|
| 298 | |
|---|
| 299 | - The entire plaintext of the peer list is not easily obtained even if |
|---|
| 300 | an eavesdropper identifies ip-port pairs from subsequent connections |
|---|
| 301 | initiated by a peer that has received a tracker response. |
|---|
| 302 | |
|---|
| 303 | - Even when a subsequent connection from a peer that has received a |
|---|
| 304 | tracker response is observed by an eavesdropper, it is difficult to |
|---|
| 305 | map the ip-port pair to specific ciphertext to verify that the |
|---|
| 306 | connection is using BitTorrent. |
|---|
| 307 | |
|---|
| 308 | When the optimizations_ are used, |
|---|
| 309 | |
|---|
| 310 | - Few computations are performed at request time. |
|---|
| 311 | |
|---|
| 312 | - Encryption may be performed at the time a peer is added. |
|---|
| 313 | The encrypted peer ip and port may be handed out hundreds of times. |
|---|
| 314 | |
|---|
| 315 | - Security is minimally impacted. |
|---|
| 316 | |
|---|
| 317 | The objective is NOT to create a cryptographically secure protocol |
|---|
| 318 | that can survive unlimited observation of passing packets and |
|---|
| 319 | substantial computational resources on network timescales. The objective |
|---|
| 320 | is to raise the bar sufficiently to deter attacks based on observing |
|---|
| 321 | ip-port numbers in peer-to-tracker communications. |
|---|
| 322 | |
|---|
| 323 | If a tracker observes a large number of tracker requests and responses |
|---|
| 324 | and subsequent connections, it is possible to attack the encryption. |
|---|
| 325 | RC4 is known to have a number of weaknesses especially in the way it |
|---|
| 326 | was used with WEP [#Borisov]_ [#Scott]_ [#Stubblefeld]_. However, |
|---|
| 327 | with tracker peer obfuscation, the number of bytes transferred between |
|---|
| 328 | the tracker and a client is likely significantly smaller than transferred |
|---|
| 329 | between a wireless computer and a basestation. An attacker faces a |
|---|
| 330 | much larger task in obtaining sufficient probable plaintext to |
|---|
| 331 | directly break the encryption. |
|---|
| 332 | |
|---|
| 333 | Hobbling the RC4 encryption by using a bounded-length RC4 pseudorandom |
|---|
| 334 | string for small swarms is likely to have negilgible impact on |
|---|
| 335 | security over any other encyption method since the pseudorandom string |
|---|
| 336 | is probably equal to or longer than the plaintext and thus no part of |
|---|
| 337 | it is repeated in the XOR except as peers arrive or leave the swarm. |
|---|
| 338 | Thus on the timescales of rerequest intervals, nearly the same |
|---|
| 339 | ciphertext is handed to every peer requesting the same infohash. |
|---|
| 340 | Intercepting the same ciphertext multiple times provides no additional |
|---|
| 341 | information to the attacker. The attacker could correlate ip-port |
|---|
| 342 | pairs in connections following tracker responses, but an attacker |
|---|
| 343 | could do this regardless of the encryption method employed. |
|---|
| 344 | Furthermore more direct methods of traffic analysis applied to |
|---|
| 345 | peer-to-peer communication is available to network operators. |
|---|
| 346 | |
|---|
| 347 | For larger swarms, hobbling RC4 may more significantly impact breaking |
|---|
| 348 | the encryption since the same pseudorandom string is used repeatedly |
|---|
| 349 | across the peer list. Some study is in order on this point taking |
|---|
| 350 | into account that the tracker can periodically change intiailization |
|---|
| 351 | vectors. |
|---|
| 352 | |
|---|
| 353 | We know from experience that periodically reshuffling peer lists on |
|---|
| 354 | the order of the rerequest interval negligibly impacts tracker |
|---|
| 355 | performance even with swarms containing millions of peers. Generating |
|---|
| 356 | a new pseudorandom string using RC4 on this same time interval is |
|---|
| 357 | likely to incur negligible performance penalty because 1) RC4 is a |
|---|
| 358 | small constant factor more expensive than a shuffle on an input string |
|---|
| 359 | of equal length, 2) the generated pseudorandom string is only *n* |
|---|
| 360 | ip-port pairs long where recommended *n* is within a small constant |
|---|
| 361 | factor larger than the largest *returned peer list* and thus much |
|---|
| 362 | smaller than the *tracker peer list* for large swarms, and 3) the cost |
|---|
| 363 | of the XOR operation is lighter weight than performing a random |
|---|
| 364 | shuffle. |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | References |
|---|
| 368 | ========== |
|---|
| 369 | |
|---|
| 370 | .. _`RFC 2119`: http://tools.ietf.org/html/rfc2119 |
|---|
| 371 | |
|---|
| 372 | .. [#MSE] BitTorrent Message Stream Encryption |
|---|
| 373 | (http://www.azureuswiki.com/index.php/Message_Stream_Encryption) |
|---|
| 374 | |
|---|
| 375 | .. [#Borisov] Nikita Borisov, Ian Goldberg, and David Wagner. Intercepting |
|---|
| 376 | mobile communications: the insecurity of 802.11. In ACM MobiCom 2001, |
|---|
| 377 | pages 180-189. ACM Press, 2001. |
|---|
| 378 | |
|---|
| 379 | .. [#Scott] Scott R. Fluhrer, Itsik Mantin, and Adi |
|---|
| 380 | Shamir. Weaknesses in the key scheduling algorithm of RC4. In Serge |
|---|
| 381 | Vaudenay and Amr M. Youssef, editors, Selected Areas in |
|---|
| 382 | Cryptography 2001, volume 2259 of Lecture Notes in Computer |
|---|
| 383 | Science, pages 1-24. Springer, 2001. |
|---|
| 384 | |
|---|
| 385 | .. [#Stubblefeld] Adam Stubblefeld, John Ioannidis, and Aviel |
|---|
| 386 | D. Rubin. A key recovery attack on the 802.11b wired equivalent |
|---|
| 387 | privacy protocol (WEP). ACM Transactions on Information and System |
|---|
| 388 | Security, 7(2):319-332, May 2004. |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | Example Python Code |
|---|
| 392 | =================== |
|---|
| 393 | |
|---|
| 394 | Request handling in a dummy tracker implementing tracker peer obfuscation:: |
|---|
| 395 | |
|---|
| 396 | from sha import sha |
|---|
| 397 | from random import randint |
|---|
| 398 | from struct import unpack |
|---|
| 399 | from rc4 import rc4 # rc4(k) generates k RC4 pseudorandom bytes. |
|---|
| 400 | |
|---|
| 401 | rand = open("/dev/random","r").read |
|---|
| 402 | rc4 = rc4() |
|---|
| 403 | |
|---|
| 404 | # tracker configuration |
|---|
| 405 | MAX_PEERS = 100 |
|---|
| 406 | |
|---|
| 407 | # per torrent state. |
|---|
| 408 | infohash = sha("dummy_info").digest() |
|---|
| 409 | pseudo = '' # pseudorandom RC4 string. |
|---|
| 410 | num_peers = 1000 # current swarm size. |
|---|
| 411 | tracker_peer_list = rand(6) * num_peers |
|---|
| 412 | obfuscated_tracker_peer_list = '' |
|---|
| 413 | |
|---|
| 414 | def xor(plaintext,pseudo): |
|---|
| 415 | isint = False |
|---|
| 416 | if type(plaintext) == int: # convert to byte string. |
|---|
| 417 | plaintext = "".join([chr(int(x,16)) for x in "%.4x" % plaintext]) |
|---|
| 418 | isint = True |
|---|
| 419 | n = len(pseudo) |
|---|
| 420 | ciphertext = "".join( |
|---|
| 421 | [chr(ord(pseudo[i%n])^ord(plaintext[i])) for i in xrange(len(plaintext))]) |
|---|
| 422 | if isint: |
|---|
| 423 | ciphertext = unpack("!I", ciphertext)[0] # convert back to unsigned int |
|---|
| 424 | return ciphertext |
|---|
| 425 | |
|---|
| 426 | def init(): # called once per rerequest interval. |
|---|
| 427 | global iv, x, n, n_xor_y, obfuscated_tracker_peer_list |
|---|
| 428 | iv = rand(20) |
|---|
| 429 | rc4.key = sha(infohash + iv).digest()[0:8] |
|---|
| 430 | rc4(768) # discard first 768 |
|---|
| 431 | x = rc4(4) |
|---|
| 432 | y = rc4(4) |
|---|
| 433 | n = min(num_peers, randint(MAX_PEERS * 2, MAX_PEERS * 4)) |
|---|
| 434 | n_xor_y = xor(n,y) |
|---|
| 435 | pseudo = rc4(n*6) |
|---|
| 436 | obfuscated_tracker_peer_list = xor(tracker_peer_list,pseudo) |
|---|
| 437 | |
|---|
| 438 | def getpeers( numwant ): |
|---|
| 439 | global iv, x, n, n_xor_y, obfuscated_tracker_peer_list |
|---|
| 440 | response = {} |
|---|
| 441 | response['iv'] = iv |
|---|
| 442 | numwant = min(numwant, MAX_PEERS) |
|---|
| 443 | if numwant > num_peers: |
|---|
| 444 | response['peers'] = obfuscated_tracker_peer_list |
|---|
| 445 | return response |
|---|
| 446 | i = randint(0,num_peers) |
|---|
| 447 | response['i'] = xor(i,x) |
|---|
| 448 | response['n'] = n_xor_y |
|---|
| 449 | response['peers'] = obfuscated_tracker_peer_list[i*6:(i+numwant)*6] |
|---|
| 450 | if len(response['peers']) < numwant * 6: |
|---|
| 451 | r = numwant - len(response['peers']) / 6 |
|---|
| 452 | response['peers'] = response['peers'] + obfuscated_tracker_peer_list[:r] |
|---|
| 453 | return response |
|---|
| 454 | |
|---|
| 455 | init() |
|---|
| 456 | print getpeers(20) |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | .. |
|---|
| 460 | Local Variables: |
|---|
| 461 | mode: indented-text |
|---|
| 462 | indent-tabs-mode: nil |
|---|
| 463 | sentence-end-double-space: t |
|---|
| 464 | fill-column: 70 |
|---|
| 465 | coding: utf-8 |
|---|
| 466 | End: |
|---|