Home
Writeups Misc About
Oh SNAP

Oh SNAP

The given link shows us an instance of ARC4, or the stream cipher version of the encryption scheme RC4. I do know beforehand that RC4 is deprecated because of some vulnerabilities, and there are no other apparent weakness to the way that the plaintext is generated from the ciphertext and iv. Also note that, as this is a symmetric stream cipher, encryption and decryption is the same xor operation on the keystream generated.

Searching on Google for SNAP RC4 takes us to the Fluhrer, Mantin and Shamir attack, which is taking advantage of the invariance in the Key Scheduling Algorithm to reconstruct the key from the eavesdropping encrypted messages. This enables attacks on the WEP, the security algorithm for 802.11 wireless networks. The SNAP refers to the fact that the first byte of the WEP SNAP header is known, an attacker can derive the first byte of the keystream. The paper which covers the mathematical details can be found at this link.

Again, same as other solution on Cryptohack, I borrow the script from FMS-Attack on Github. As the full output of the decrypted plaintext (or effectively ciphertext), we can specify the plaintext as the null byte to get the key stream without the xor operation. The form of the IV is A + 3, 255, X, where A is the number of bytes in the secret key that we know (initially A = 0), and X is some random value in the range from 0 to 255.

To somewhat understand the script, I don't think there is any way other than reading the paper and pondering for a bit on how it works. There are some terms that may confuse you (word in the paper is byte in my script). Also the script is not using encoded strings, so I have to modify it a bit. Other than this, there are a few things that needs to be tweaked as well, but should be easy if you understand the idea of the attack. I would suggest testing the RC4 code with pycryptodome ARC4 before trying to implement the FMS attack - in case there is some implementation difference.

Python Implementation:

There are also ways to improve the performance of the script. Credit to ciphr on Cryptohack for this multithreaded solution.