#!/usr/bin/env python3 import struct, binascii from .wifi import * #from binascii import a2b_hex #from struct import unpack,pack from Crypto.Cipher import AES, ARC4 from scapy.layers.dot11 import Dot11, Dot11CCMP, Dot11QoS import zlib def pn2bytes(pn): pn_bytes = [0] * 6 for i in range(6): pn_bytes[i] = pn & 0xFF pn >>= 8 return pn_bytes def pn2bin(pn): return struct.pack(">Q", pn)[2:] def dot11ccmp_get_pn(p): pn = p.PN5 pn = (pn << 8) | p.PN4 pn = (pn << 8) | p.PN3 pn = (pn << 8) | p.PN2 pn = (pn << 8) | p.PN1 pn = (pn << 8) | p.PN0 return pn def ccmp_get_nonce(priority, addr, pn): return struct.pack("B", priority) + addr2bin(addr) + pn2bin(pn) def ccmp_get_aad(p, amsdu_spp=False): # FC field with masked values fc = raw(p)[:2] fc = struct.pack("I", pn)[1:] cipher = ARC4.new(iv + key) ciphertext = cipher.encrypt(payload) # Construct packet ourselves to avoid scapy bugs newp = p/iv/struct.pack("