wifihandshakewpa

How to count the number of valid WPA handshakes in a cap file


I want to know how many valid WPA handshakes are in a cap file.

I did try using this approach:

  tshark -r file.cap -R "(wlan.fc.type_subtype == 0x08 || wlan.fc.type_subtype == 0x05 || eapol)" -2 


   1   0.064507 D-LinkIn_89:9f:44 → Broadcast    802.11 325 Beacon frame, SN=2485, FN=0, Flags=........, BI=100, SSID=AAAAA
   2  15.639995 LgElectr_94:af:ba → D-LinkIn_89:9f:44 EAPOL 155 Key (Message 2 of 4)
   3  15.643065 D-LinkIn_89:9f:44 → LgElectr_94:af:ba EAPOL 213 Key (Message 3 of 4)
   4  27.695798 LgElectr_94:af:ba → D-LinkIn_89:9f:44 EAPOL 155 Key (Message 2 of 4)
   5  27.703480 LgElectr_94:af:ba → D-LinkIn_89:9f:44 EAPOL 133 Key (Message 4 of 4)
   6  54.926712 D-LinkIn_89:9f:44 → LgElectr_94:af:ba EAPOL 133 Key (Message 1 of 4)
   7  54.975420 D-LinkIn_89:9f:44 → LgElectr_94:af:ba EAPOL 213 Key (Message 3 of 4)
   8  81.340985 D-LinkIn_89:9f:44 → LgElectr_94:af:ba EAPOL 133 Key (Message 1 of 4)
   9  81.351228 LgElectr_94:af:ba → D-LinkIn_89:9f:44 EAPOL 155 Key (Message 2 of 4)
  10  81.353779 D-LinkIn_89:9f:44 → LgElectr_94:af:ba EAPOL 213 Key (Message 3 of 4)
  11  81.358911 LgElectr_94:af:ba → D-LinkIn_89:9f:44 EAPOL 133 Key (Message 4 of 4)
  12 119.080377 LgElectr_94:af:ba → D-LinkIn_89:9f:44 EAPOL 133 Key (Message 4 of 4)

I want the following output:

count.sh file.cap

3 (3 valid handshake).

What I don't know is to identify when a set of messages is a valid Handshake to crack it (let's say something like aircrack-ng).

Help.


Solution

  • Well, after some more digging I realize the answer was right in front of my eyes.

    I found LazyScript (github repo) that has a feature to check/validate WPA/WPA2 handshakes. Diving into the source code I figured it out that it uses Pyrit and Cowpatty

    So, in summary, there's a very easy/simple way to count for handshakes in a cap file (also check the quality):

    pyrit -r fileWithHandShakes.cap analyze
    

    It will give this output:

    Pyrit 0.4.0 (C) 2008-2011 Lukas Lueg http://pyrit.googlecode.com
    This code is distributed under the GNU General Public License v3+
    
    Parsing file '/folder/fileWithHandShakes.cap' (1/1)...
    Parsed 112 packets (112 802.11-packets), got 1 AP(s)
    
    #1: AccessPoint fd:94:e3:43:bc:b6 ('MyWifi'):
      #1: Station 30:fd:38:c1:2b:bb, 3 handshake(s):
        #1: HMAC_SHA1_AES, good, spread 1
        #2: HMAC_SHA1_AES, bad, spread 17
        #3: HMAC_SHA1_AES, bad, spread 22
      #2: Station 44:00:10:06:bc:bc, 2 handshake(s):
        #1: HMAC_SHA1_AES, good, spread 1
        #2: HMAC_SHA1_AES, bad, spread 3
    

    That's the way to count for handshakes and also to check for the quality of those handshakes.