2013-02-28 52 views
3

我試圖計算WPA握手數據包的MIC,但不幸的是它失敗了。更確切地說,我使用了802.1x數據包(如規範所述)。用Python創建WPA消息完整性代碼(MIC)

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

這是相關代碼:

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

凡hmac.new從HMAC LIB採取:

import hmac,hashlib,binascii 

爲加密的密鑰顯然是由前16個字節的Pairwise Transcient Key(所謂的密鑰確認密鑰)。 PTK由一個名爲cowPatty的程序確認。 所以我可以排除這兩個因素是錯誤的。這是我的802.1x的數據,這是由十六進制值0103介紹:

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

Wireshark的計算MIC是:

e8b4b90bfc3fd97b657afeb66262ae94 

,我計算爲MIC:

5492624bb538b52d6aa6261c692bd595 

不幸的是,我所做的並不重要,我永遠無法計算出相同的MIC。 也許一些專家有寶貴意見,真的很感謝!

此致敬禮!

+1

http://stackoverflow.com/questions/12018920/wpa-handshake-with-python-hashing-difficulties 這可能會有所幫助。 通知endianess-issues – 2014-04-17 12:20:07

回答

3

這裏是一個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使用HMAC與MD5哈希函數,WPA2使用HMAC與SHA1哈希值,你可以在了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。