26.07.2018 Views

hacking-the-art-of-exploitation

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Plaintext message P (M with 32-bit CS)<br />

XOR<br />

Keystream generated by RC4(seed)<br />

equals<br />

24-bit IV<br />

Ciphertext C<br />

When <strong>the</strong> recipient receives a WEP-encrypted packet, <strong>the</strong> process is simply<br />

reversed. The recipient pulls <strong>the</strong> IV from <strong>the</strong> message and <strong>the</strong>n concatenates<br />

<strong>the</strong> IV with his own WEP key to produce a seed value <strong>of</strong> S. If <strong>the</strong> sender and<br />

receiver both have <strong>the</strong> same WEP key, <strong>the</strong> seed values will be <strong>the</strong> same. This<br />

seed is fed into RC4 again to produce <strong>the</strong> same keystream, which is XORed<br />

with <strong>the</strong> rest <strong>of</strong> <strong>the</strong> encrypted message. This will produce <strong>the</strong> original plaintext<br />

message, consisting <strong>of</strong> <strong>the</strong> packet message M concatenated with <strong>the</strong> integrity<br />

checksum CS. The recipient <strong>the</strong>n uses <strong>the</strong> same CRC32 function to recalculate<br />

<strong>the</strong> checksum for M and checks that <strong>the</strong> calculated value matches <strong>the</strong> received<br />

value <strong>of</strong> CS. If <strong>the</strong> checksums match, <strong>the</strong> packet is passed on. O<strong>the</strong>rwise, <strong>the</strong>re<br />

were too many transmission errors or <strong>the</strong> WEP keys didn’t match, and <strong>the</strong><br />

packet is dropped.<br />

That’s basically WEP in a nutshell.<br />

0x772<br />

RC4 Stream Cipher<br />

RC4 is a surprisingly simple algorithm. It consists <strong>of</strong> two algorithms: <strong>the</strong> Key<br />

Scheduling Algorithm (KSA) and <strong>the</strong> Pseudo-Random Generation Algorithm<br />

(PRGA). Both <strong>of</strong> <strong>the</strong>se algorithms use an 8-by-8 S-box, which is just an array <strong>of</strong><br />

256 numbers that are both unique and range in value from 0 to 255. Stated<br />

simply, all <strong>the</strong> numbers from 0 to 255 exist in <strong>the</strong> array, but <strong>the</strong>y’re all just<br />

mixed up in different ways. The KSA does <strong>the</strong> initial scrambling <strong>of</strong> <strong>the</strong> S-box,<br />

based on <strong>the</strong> seed value fed into it, and <strong>the</strong> seed can be up to 256 bits long.<br />

First, <strong>the</strong> S-box array is filled with sequential values from 0 to 255. This<br />

array will be aptly named S. Then, ano<strong>the</strong>r 256-byte array is filled with <strong>the</strong> seed<br />

value, repeating as necessary until <strong>the</strong> entire array is filled. This array will be<br />

named K. Then <strong>the</strong> S array is scrambled using <strong>the</strong> following pseudo-code.<br />

j = 0;<br />

for i = 0 to 255<br />

{<br />

j = (j + S[i] + K[i]) mod 256;<br />

swap S[i] and S[j];<br />

}<br />

Once that is done, <strong>the</strong> S-box is all mixed up based on <strong>the</strong> seed value.<br />

That’s <strong>the</strong> key scheduling algorithm. Pretty simple.<br />

Cryptology 435

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!