python - 使用 Python 创建 WPA 消息完整性代码 (MIC)

标签 python encryption wireless wireshark wpa

我试图计算 WPA 握手数据包的 MIC,但不幸的是它失败了。更准确地说,我采用了 802.1x 数据包(如规范所述)。

MIC = HMAC_MD5(MIC Key, 16, 802.1x data)

这是相关代码:

mic = hmac.new(ptk[0:16],data)
print "mic: " + mic.hexdigest()  + "\n"

hmac.new 取自 hmac 库:

import hmac,hashlib,binascii

加密 key 显然由成对 transient key (所谓的 key 确认 key )的前 16 个字节组成。 PTK 由名为 cowPatty 的程序确认。 所以我可以排除这两个因素是错误的。这是我的 802.1x 数据,由十六进制值 0103 引入:

01030077fe010a001000000000000000
01ae11df37f5fb100665ce0c849f5950
c0e7901da3224ddfc9e9434babad5512
73000000000000000000000000000000
00000000000000000000000000000000
00e8b4b90bfc3fd97b657afeb66262ae
940018dd160050f20101000050f20201
000050f20401000050f202

Wireshark计算的MIC是:

e8b4b90bfc3fd97b657afeb66262ae94

我计算的MIC是:

5492624bb538b52d6aa6261c692bd595

不幸的是,不管我做什么,我永远无法计算出相同的 MIC。 也许一些专家提供了宝贵的意见,我们将不胜感激!

最好的问候!

最佳答案

这是来自 4 次握手中的第二条消息的 EAPOL 数据(在逻辑链路控制之后立即开始):

unsigned char eapol[] =
{
    '\x01',        // Version
    '\x03',        // Type
    '\x00','\x77', // Length
    '\xfe',        // Key Descriptor Type
    '\x01','\x0a', // Key information
    '\x00','\x10', // Key length
    // Replay counter
    '\x00','\x00','\x00','\x00','\x00','\x00','\x00','\x01',
    // WPA Key Nounce
    '\x77','\xd6','\x54','\xad','\x0c','\x1f','\xea','\x2f',
    '\x20','\x99','\xf1','\xdd','\x1c','\xae','\xdb','\xd8',
    '\xf7','\xe8','\x86','\xb0','\x81','\x60','\xed','\x7f',
    '\x70','\xdd','\xbb','\x33','\xb6','\xf1','\xd9','\x98',
    // Key IV
    '\x00','\x00','\x00','\x00','\x00','\x00','\x00','\x00',
    '\x00','\x00','\x00','\x00','\x00','\x00','\x00','\x00',
    // Key RSC
    '\x00','\x00','\x00','\x00','\x00','\x00','\x00','\x00',
    // Key ID
    '\x00','\x00','\x00','\x00','\x00','\x00','\x00','\x00',
    // MIC **************** CHANGE HERE ********************
//  '\x0a','\x62','\x24','\x07','\x11','\x36','\xd5','\x67',
//  '\x87','\xc0','\x7b','\x82','\x6b','\x06','\xf7','\xff',
    '\x00','\x00','\x00','\x00','\x00','\x00','\x00','\x00',
    '\x00','\x00','\x00','\x00','\x00','\x00','\x00','\x00',
    // Key Data Length
    '\x00','\x18',
    // Key Data
    '\xdd','\x16','\x00','\x50','\xf2','\x01','\x01','\x00',
    '\x00','\x50','\xf2','\x04','\x01','\x00','\x00','\x50',
    '\xf2','\x04','\x01','\x00','\x00','\x50','\xf2','\x02'
};

确保将 16 字节的 MIC 字段替换为“\x00”,这样您就可以准备好有效的 EAPOL 数据,以便根据 Michael 算法进行计算。

此外,请确保您使用的是基于 WPA 版本的正确算法。 WPA1 使用具有 MD5 哈希函数的 HMAC,WPA2 使用具有 SHA1 哈希函数的 HMAC,如您在 aircrack-ng 源代码中所见:

if (ap->wpa.keyver == 1)
    HMAC(EVP_md5(), ptk[j], 16, ap->wpa.eapol, ap->wpa.eapol_size, mic[j], NULL);
else
    HMAC(EVP_sha1(), ptk[j], 16, ap->wpa.eapol, ap->wpa.eapol_size, mic[j], NULL);

我认为 python 在 HMAC 对象中默认使用 MD5。

关于python - 使用 Python 创建 WPA 消息完整性代码 (MIC),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133797/

相关文章:

Arduino 的 iOS 虚拟按钮

linux - USB无线桌面组合不断重置 "reset full speed USB device"

python - 如何将 openCV 转换图像转换为原始格式

python - Django 按时间从特定小时开始排序查询集,最后发送其他结果

encryption - 当我有 IV、纯文本和加密文本时获取 AES CBC key

ios - 加密/解密 .plist 文件 ios

python - 将分块的 dask xarray 乘以掩码

python - 如何将 SimpleGUI 与 Python 2.7 和 3.0 shell 集成

ssl - CFNetwork SSLHandshake 间歇性失败 (-9806)

java - 了解机器何时连接到互联网