I am trying to encrypt and decrypt Wi-Fi data, I captured Wi-Fi packets between AP and my iPhone to test own encryption and decryption are correct or not? I have referenced IEEE 802.11i documentation, but the encrypted data isn't same as captured data. Can someone tell me which part is wrong?
I referenced IEEE 802.11i documentation and pycryptodome to implement my encryption.
MAC address is replaced by 'x' character.
from scapy.all import *
from Crypto.Cipher import AES
AAD = bytes.fromhex("2082") + bytes.fromhex("7403bdxxxxxx") + bytes.fromhex("7c04d0xxxxxx") + bytes.fromhex("7403bdxxxxxx") + bytes.fromhex("0005") + bytes.fromhex("0006")
nonce = bytes.fromhex("00") + bytes.fromhex("7c04d0xxxxxx") + bytes.fromhex("000000000002")
key = bytes.fromhex("354a770813c0b4f57b7d65397fe8ec95")
plaintext = bytes.fromhex("aaaa03000000080600010800060400017c04d0c8fc4ac0a8016e000000000000c0a80101")
cipher = AES.new(key, AES.MODE_CCM, nonce, mac_len=8)
cipher.update(AAD)
msg = nonce, AAD, cipher.encrypt(plaintext), cipher.digest()
hexdump(msg[2])
hexdump(msg[3])
My results:
Ciphertext
0000 E5 91 E4 72 1B 9D 54 AD 70 CB 88 43 27 29 9C B1 ...r..T.p..C')..
0010 41 EA 35 BE F6 97 AF 36 C5 97 50 E8 23 DE FB AD A.5....6..P.#...
0020 83 AC DF E9 ....
MAC/MIC
0000 B3 0C BF C8 4D 28 3D F3 ....M(=.
Expected results:
0000 34 39 09 e7 7f 97 35 37 bd 72 bb 33 ca 5f 4c 2d 49....57.r.3._L-
0010 02 62 95 11 d5 41 2e 9c 7e d1 41 3b 64 12 37 92 .b...A..~.A;d.7.
0020 74 fd 92 f7 d0 03 0e 0e 34 bb 3d b9 t.......4.=.
Wireshark captured data between my iPhone and AP's images(MAC address is redacted)
- Img 1
- Img 2
- Img 3
After few days, I found out which part is wrong.
Modified last 2 bytes from 0006 to 0600.
AAD = ... + bytes.fromhex("0600")
Modified first bytes from 00 to 06.
nonce = bytes.fromhex("06") + ...