如何使用Python计算消息完整性代码(MIC)?

2024-10-03 17:21:52 发布

您现在位置:Python中文网/ 问答频道 /正文

最近,我尝试用Python手动计算MIC,以验证四向握手消息2中的MIC值,因为当我尝试连接时,路由器和WIFI模块之间的过程每次都会在消息2中停止

因为我正在使用WPA2

mic = hmac.new(ptk[0:16].encode("ascii"), payload, hashlib.sha1).hexdigest()[:32]

有效负载是802.1X身份验证的全部部分,麦克风由0x00替换。 enter image description here

为了计算ptk,我使用PRF-384

ptk = customPRF384(pmk, pke, key_data)

def customPRF384(key, A, B):
    blen = 48
    i = 0
    R = ''
    while i <= ((blen * 8 + 159) / 160):
        hmacsha1 = hmac.new(key, (str(A) + chr(0x00) + str(B) + chr(i)).encode("ascii"), hashlib.sha1)
        i += 1
        R = R + hmacsha1.hexdigest()
    return R[:blen]

pke = "Pairwise key expansion"
key_data = min(mac_ap, mac_cl) + max(mac_ap, mac_cl) + min(anonce,snonce) + max(anonce,snonce)

pmk = PBKDF2(psk, ssid, 4096).read(32)

(我对迭代有点困惑,这是固定的吗?)

然而,使用这种方法,我无法计算正确的麦克风。 如果你们中有人能发现一些错误,我将不胜感激


Tags: key消息newmacasciihmacsha1encode