forked from rootorben/multicapconverter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulticapconverter.py
2321 lines (2253 loc) · 94.7 KB
/
multicapconverter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = "Abdelhafidh Belalia (s77rt)"
__credits__ = ['Jens Steube <[email protected]>', 'Philipp "philsmd" Schmidt <[email protected]>', 'ZerBea (https://github.com/ZerBea)', 'RealEnder (https://github.com/RealEnder)']
__license__ = "MIT"
__maintainer__ = "Abdelhafidh Belalia (s77rt)"
__email__ = "[email protected]"
__version__ = "1.1.1"
__github__ = "https://github.com/s77rt/multicapconverter/"
import os
import sys
import argparse
import errno
import re
import gzip
import requests
import time
from operator import itemgetter
from itertools import groupby
from multiprocessing import Process, Manager
###### User Configurations #####
""" The api key below is temporarily
Get your api key from https://hashc.co.uk/
Or contact [email protected]
IMPORTANT: DO NOT change the api key below, instead use the environment variable: hashC_APIKEY
"""
hashC_APIKEY = os.environ.get('hashC_APIKEY', 'TESTxQfS8hIKcALYZIfYz14IYGxbWQbJ0mKLFE7e0hIbIIt4J3K7Ce5Xcdshqngr')
################################
### Endianness ###
if sys.byteorder == "big":
BIG_ENDIAN_HOST = True
xprint("WARNING! Endianness is not well tested on BIG_ENDIAN_HOST.")
else:
BIG_ENDIAN_HOST = False
###
### Constants ###
OUI_DB_FILE = os.path.join(os.path.expanduser('~'), "oui.csv")
OUI_DB_URL = "http://standards-oui.ieee.org/oui/oui.csv"
HCCAPX_VERSION = 4
HCCAPX_SIGNATURE = 0x58504348 # HCPX
HCWPAX_SIGNATURE = "WPA"
TCPDUMP_MAGIC = 0xa1b2c3d4
TCPDUMP_CIGAM = 0xd4c3b2a1
PCAPNG_MAGIC = 0x1A2B3C4D
PCAPNG_CIGAM = 0xD4C3B2A1
TCPDUMP_DECODE_LEN = 65535
DLT_IEEE802_11 = 105 # IEEE 802.11 wireless
DLT_IEEE802_11_PRISM = 119
DLT_IEEE802_11_RADIO = 127
DLT_IEEE802_11_PPI_HDR = 192
IEEE80211_FCTL_FTYPE = 0x000c
IEEE80211_FCTL_STYPE = 0x00f0
IEEE80211_FCTL_TODS = 0x0100
IEEE80211_FCTL_FROMDS = 0x0200
IEEE80211_FTYPE_MGMT = 0x0000
IEEE80211_FTYPE_DATA = 0x0008
IEEE80211_STYPE_ASSOC_REQ = 0x0000
IEEE80211_STYPE_REASSOC_REQ = 0x0020
IEEE80211_STYPE_PROBE_REQ = 0x0040
IEEE80211_STYPE_PROBE_RESP = 0x0050
IEEE80211_STYPE_BEACON = 0x0080
IEEE80211_STYPE_QOS_DATA = 0x0080
IEEE80211_LLC_DSAP = 0xAA
IEEE80211_LLC_SSAP = 0xAA
IEEE80211_LLC_CTRL = 0x03
IEEE80211_DOT1X_AUTHENTICATION = 0x8E88
MFIE_TYPE_SSID = 0
MFIE_TYPE_RATES = 1
SIZE_OF_pcap_pkthdr_t = 16
SIZE_OF_pcap_file_header_t = 24
SIZE_OF_prism_header_t = 144
SIZE_OF_ieee80211_radiotap_header_t = 8
SIZE_OF_ppi_packet_header_t = 8
SIZE_OF_ieee80211_hdr_3addr_t = 24
SIZE_OF_ieee80211_qos_hdr_t = 26
SIZE_OF_beacon_t = 12
SIZE_OF_assocreq_t = 4
SIZE_OF_reassocreq_t = 10
SIZE_OF_ieee80211_llc_snap_header_t = 8
SIZE_OF_EAPOL = 256
AUTH_EAP = 0
AUTH_EAPOL = 3
AUTH_EAP_MD5 = 4
AUTH_EAP_LEAP = 17
BROADCAST_MAC = (255, 255, 255, 255, 255, 255)
MAX_ESSID_LEN = 32
EAPOL_TTL = 1
ZERO = b'\x00'
WPA_KEY_INFO_TYPE_MASK = 7
WPA_KEY_INFO_INSTALL = 64
WPA_KEY_INFO_ACK = 128
WPA_KEY_INFO_SECURE = 512
ESSID_SOURCE_REASSOC = 20
ESSID_SOURCE_ASSOC = 30
ESSID_SOURCE_PROBE = 40
ESSID_SOURCE_BEACON = 60
EXC_PKT_NUM_1 = 1
EXC_PKT_NUM_2 = 2
EXC_PKT_NUM_3 = 3
EXC_PKT_NUM_4 = 4
MESSAGE_PAIR_M12E2 = 0
MESSAGE_PAIR_M14E4 = 1
MESSAGE_PAIR_M32E2 = 2
MESSAGE_PAIR_M32E3 = 3
MESSAGE_PAIR_M34E3 = 4
MESSAGE_PAIR_M34E4 = 5
MESSAGE_PAIR_APLESS = 0b00010000
MESSAGE_PAIR_LE = 0b00100000
MESSAGE_PAIR_BE = 0b01000000
MESSAGE_PAIR_NC = 0b10000000
Enhanced_Packet_Block = 0x00000006
Section_Header_Block = 0x0A0D0D0A
Custom_Block = 0x0000000bad
Custom_Option_Codes = [2988, 2989, 19372, 19373]
if_tsresol_code = 9
opt_endofopt = 0
HCXDUMPTOOL_PEN = bytes([0x2a, 0xce, 0x46, 0xa1])
HCXDUMPTOOL_MAGIC_NUMBER = bytes([0x2a, 0xce, 0x46, 0xa1, 0x79, 0xa0, 0x72, 0x33, 0x83, 0x37, 0x27, 0xab, 0x59, 0x33, 0xb3, 0x62, 0x45, 0x37, 0x11, 0x47, 0xa7, 0xcf, 0x32, 0x7f, 0x8d, 0x69, 0x80, 0xc0, 0x89, 0x5e, 0x5e, 0x98])
HCXDUMPTOOL_OPTIONCODE_RC = 0xf29c
HCXDUMPTOOL_OPTIONCODE_ANONCE = 0xf29d
SUITE_OUI = b'\x00\x0f\xac'
AK_PSK = 2
AK_PSKSHA256 = 6
AK_SAFE = -1
DB_ESSID_MAX = 50000
DB_EXCPKT_MAX = 100000
MAX_WORK_PER_PROCESS = 100
# Log Levels
INFO = 10
WARNING = 20
ERROR = 30
CRITICAL = 40
DEBUG = 50
###
### LOGGER ###
class l_messages(dict):
def log(self, key, value=1):
"""
key => message
value => counter of message
"""
if key not in self:
dict.__setitem__(self, key, value)
else:
self[key] += value
class Logger(object):
def __init__(self):
super(Logger, self).__init__()
self.info = l_messages()
self.warning = l_messages()
self.error = l_messages()
self.critical = l_messages()
self.debug = l_messages()
def log(self, message, level):
if level >= DEBUG:
self.debug.log(message)
elif level >= CRITICAL:
self.critical.log(message)
elif level >= ERROR:
self.error.log(message)
elif level >= WARNING:
self.warning.log(message)
else:
self.info.log(message)
LOGGER = Logger()
###
### H-Functions ###
def GetUint16(b):
return b[0] | b[1] << 8
def GetUint32(b):
return b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24
def GetUint64(b):
return b[0] | b[1] << 8 | b[2] << 16 | b[3] << 24 | b[4] << 32 | b[5] << 40 | b[6] << 48 | b[7] << 56
def PutUint16(v):
return ((v & 0x00ff), (v & 0xff00) >> 8)
def PutUint32(v):
return ((v & 0x000000ff), (v & 0x0000ff00) >> 8, (v & 0x00ff0000) >> 16, (v & 0xff000000) >> 24)
def byte_swap_16(n):
return (n & 0xff00) >> 8 \
| (n & 0x00ff) << 8
def byte_swap_32(n):
return (n & 0xff000000) >> 24 \
| (n & 0x00ff0000) >> 8 \
| (n & 0x0000ff00) << 8 \
| (n & 0x000000ff) << 24
def byte_swap_64(n):
return (n & 0xff00000000000000) >> 56 \
| (n & 0x00ff000000000000) >> 40 \
| (n & 0x0000ff0000000000) >> 24 \
| (n & 0x000000ff00000000) >> 8 \
| (n & 0x00000000ff000000) << 8 \
| (n & 0x0000000000ff0000) << 24 \
| (n & 0x000000000000ff00) << 40 \
| (n & 0x00000000000000ff) << 56
def to_signed_32(n):
n = n & 0xffffffff
return (n ^ 0x80000000) - 0x80000000
#
def get_valid_bssid(bssid):
bssid = re.match("[0-9a-f]{2}([-:]?)[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", bssid.lower())
if bssid:
return bssid[0].replace(':', '').replace('-', '')
def get_valid_filename(s, r='_'):
s = str(s).strip().replace(' ', '_')
return re.sub(r'(?u)[^-\w.\@]', r, s)
def xprint(text="", end='\n', flush=True):
print(text, end=end, flush=flush)
###
### MAC LOOKUP ###
# VENDOR LOOKUP
class MAC_VENDOR_LOOKUP(object):
def __init__(self, db):
super(MAC_VENDOR_LOOKUP, self).__init__()
self.db_isUpdated = False
if not os.path.isfile(db):
self.download_db(db)
self.db = db
self.data = {}
self.load_data()
def download_db(self, db):
if self.db_isUpdated:
return
if os.path.isfile(db):
os.remove(db)
xprint("[i] Downloading OUI Database...", end='\r', flush=True)
response = requests.get(OUI_DB_URL, stream=True)
filesize_total = int(response.headers.get('content-length', 1))
filesize_downloaded = 0
prev_time = time.time()
with open(db+'.tmp', "wb") as handle:
for data in response.iter_content():
filesize_downloaded += len(data)
if time.time() - prev_time > 1:
if filesize_total > 1:
xprint('[i] Downloading OUI Database...{:05.2f}%'.format((filesize_downloaded/filesize_total)*100), end='\r', flush=True)
prev_time = time.time()
handle.write(data)
os.rename(db+'.tmp', db)
self.db_isUpdated = True
xprint("[i] Downloading OUI Database.......OK", flush=True)
def load_data(self):
with open(self.db, 'r') as dbfile:
for line in dbfile:
try:
vendor = re.search(r',([0-9A-F]{6}),(?:(?:"(.+?)",)|(.+?),)', line)
self.data[vendor.group(1)] = vendor.group(2) or vendor.group(3)
except:
pass
def lookup(self, mac):
return self.data.get(mac[:6].upper(), 'N/A')
# GEOLOCATION LOOKUP
class MAC_GEO_LOOKUP(object):
def __init__(self):
super(MAC_GEO_LOOKUP, self).__init__()
self.bbox = {
'Afghanistan': [29.3772, 38.4910682, 60.5176034, 74.889862],
'Aland Islands': [59.4541578, 60.87665, 19.0832098, 21.3456556],
'Albania': [39.6448625, 42.6610848, 19.1246095, 21.0574335],
'Algeria': [18.968147, 37.2962055, -8.668908, 11.997337],
'American Samoa': [-14.7608358, -10.8449746, -171.2951296, -167.9322899],
'Andorra': [42.4288238, 42.6559357, 1.4135781, 1.7863837],
'Angola': [-18.038945, -4.3880634, 11.4609793, 24.0878856],
'Anguilla': [18.0615454, 18.7951194, -63.6391992, -62.7125449],
'Antarctica': [-85.0511287, -60.0, -180.0, 180.0],
'Antigua and Barbuda': [16.7573901, 17.929, -62.5536517, -61.447857],
'Argentina': [-55.1850761, -21.781168, -73.5600329, -53.6374515],
'Armenia': [38.8404775, 41.300712, 43.4471395, 46.6333087],
'Aruba': [12.1702998, 12.8102998, -70.2809842, -69.6409842],
'Australia': [-55.3228175, -9.0882278, 72.2460938, 168.2249543],
'Austria': [46.3722761, 49.0205305, 9.5307487, 17.160776],
'Azerbaijan': [38.3929551, 41.9502947, 44.7633701, 51.0090302],
'Bahamas': [20.7059846, 27.4734551, -80.7001941, -72.4477521],
'Bahrain': [25.535, 26.6872444, 50.2697989, 50.9233693],
'Bangladesh': [20.3756582, 26.6382534, 88.0075306, 92.6804979],
'Barbados': [12.845, 13.535, -59.8562115, -59.2147175],
'Belarus': [51.2575982, 56.17218, 23.1783344, 32.7627809],
'Belgium': [49.4969821, 51.5516667, 2.3889137, 6.408097],
'Belize': [15.8857286, 18.496001, -89.2262083, -87.3098494],
'Benin': [6.0398696, 12.4092447, 0.776667, 3.843343],
'Bermuda': [32.0469651, 32.5913693, -65.1232222, -64.4109842],
'Bhutan': [26.702016, 28.246987, 88.7464724, 92.1252321],
'Bolivia': [-22.8982742, -9.6689438, -69.6450073, -57.453],
'Bosnia and Herzegovina': [42.5553114, 45.2764135, 15.7287433, 19.6237311],
'Botswana': [-26.9059669, -17.778137, 19.9986474, 29.375304],
'Bouvet Island': [-54.654, -54.187, 2.9345531, 3.7791099],
'Brazil': [-33.8689056, 5.2842873, -73.9830625, -28.6341164],
'British Indian Ocean Territory': [-7.6454079, -5.037066, 71.036504, 72.7020157],
'British Virgin Islands': [17.623468, 18.464984, -65.159094, -64.512674],
'Brunei': [4.002508, 5.1011857, 114.0758734, 115.3635623],
'Bulgaria': [41.2353929, 44.2167064, 22.3571459, 28.8875409],
'Burkina Faso': [9.4104718, 15.084, -5.5132416, 2.4089717],
'Burundi': [-4.4693155, -2.3096796, 29.0007401, 30.8498462],
'Cambodia': [9.4752639, 14.6904224, 102.3338282, 107.6276788],
'Cameroon': [1.6546659, 13.083333, 8.3822176, 16.1921476],
'Canada': [41.6765556, 83.3362128, -141.00275, -52.3231981],
'Cape Verde': [14.8031546, 17.2053108, -25.3609478, -22.6673416],
'Cayman Islands': [19.0620619, 19.9573759, -81.6313748, -79.5110954],
'Central African Republic': [2.2156553, 11.001389, 14.4155426, 27.4540764],
'Chad': [7.44107, 23.4975, 13.47348, 24.0],
'Chile': [-56.725, -17.4983998, -109.6795789, -66.0753474],
'China': [8.8383436, 53.5608154, 73.4997347, 134.7754563],
'Christmas Island': [-10.5698515, -10.4123553, 105.5336422, 105.7130159],
'Cocos Islands': [-12.4055983, -11.6213132, 96.612524, 97.1357343],
'Colombia': [-4.2316872, 16.0571269, -82.1243666, -66.8511907],
'Comoros': [-12.621, -11.165, 43.025305, 44.7451922],
'Cook Islands': [-22.15807, -8.7168792, -166.0856468, -157.1089329],
'Costa Rica': [5.3329698, 11.2195684, -87.2722647, -82.5060208],
'Croatia': [42.1765993, 46.555029, 13.2104814, 19.4470842],
'Cuba': [19.6275294, 23.4816972, -85.1679702, -73.9190004],
'Cyprus': [34.4383706, 35.913252, 32.0227581, 34.8553182],
'Czech Republic': [48.5518083, 51.0557036, 12.0905901, 18.859216],
'Democratic Republic of the Congo': [-13.459035, 5.3920026, 12.039074, 31.3056758],
'Denmark': [54.4516667, 57.9524297, 7.7153255, 15.5530641],
'Djibouti': [10.9149547, 12.7923081, 41.7713139, 43.6579046],
'Dominica': [15.0074207, 15.7872222, -61.6869184, -61.0329895],
'Dominican Republic': [17.2701708, 21.303433, -72.0574706, -68.1101463],
'East Timor': [-9.5642775, -8.0895459, 124.0415703, 127.5335392],
'Ecuador': [-5.0159314, 1.8835964, -92.2072392, -75.192504],
'Egypt': [22.0, 31.8330854, 24.6499112, 37.1153517],
'El Salvador': [12.976046, 14.4510488, -90.1790975, -87.6351394],
'Equatorial Guinea': [-1.6732196, 3.989, 5.4172943, 11.3598628],
'Eritrea': [12.3548219, 18.0709917, 36.4333653, 43.3001714],
'Estonia': [57.5092997, 59.9383754, 21.3826069, 28.2100175],
'Ethiopia': [3.397448, 14.8940537, 32.9975838, 47.9823797],
'Falkland Islands': [-53.1186766, -50.7973007, -61.7726772, -57.3662367],
'Faroe Islands': [61.3915553, 62.3942991, -7.6882939, -6.2565525],
'Fiji': [-21.9434274, -12.2613866, 172.0, -178.5],
'Finland': [59.4541578, 70.0922939, 19.0832098, 31.5867071],
'France': [41.2632185, 51.268318, -5.4534286, 9.8678344],
'French Guiana': [2.112222, 5.7507111, -54.60278, -51.6346139],
'French Polynesia': [-28.0990232, -7.6592173, -154.9360599, -134.244799],
'French Southern Territories': [-50.2187169, -11.3139928, 39.4138676, 77.8494974],
'Gabon': [-4.1012261, 2.3182171, 8.5002246, 14.539444],
'Gambia': [13.061, 13.8253137, -17.0288254, -13.797778],
'Georgia': [41.0552922, 43.5864294, 39.8844803, 46.7365373],
'Germany': [47.2701114, 55.099161, 5.8663153, 15.0419319],
'Ghana': [4.5392525, 11.1748562, -3.260786, 1.2732942],
'Gibraltar': [36.100807, 36.180807, -5.3941295, -5.3141295],
'Greece': [34.7006096, 41.7488862, 19.2477876, 29.7296986],
'Greenland': [59.515387, 83.875172, -74.1250416, -10.0288759],
'Grenada': [11.786, 12.5966532, -62.0065868, -61.1732143],
'Guadeloupe': [15.8320085, 16.5144664, -61.809764, -61.0003663],
'Guam': [13.182335, 13.706179, 144.563426, 145.009167],
'Guatemala': [13.6345804, 17.8165947, -92.3105242, -88.1755849],
'Guernsey': [49.4155331, 49.5090776, -2.6751703, -2.501814],
'Guinea': [7.1906045, 12.67563, -15.5680508, -7.6381993],
'Guinea-Bissau': [10.6514215, 12.6862384, -16.894523, -13.6348777],
'Guyana': [1.1710017, 8.6038842, -61.414905, -56.4689543],
'Haiti': [17.9099291, 20.2181368, -75.2384618, -71.6217461],
'Heard Island and McDonald Islands': [-53.394741, -52.7030677, 72.2460938, 74.1988754],
'Honduras': [12.9808485, 17.619526, -89.3568207, -82.1729621],
'Hong Kong': [22.1193278, 22.4393278, 114.0028131, 114.3228131],
'Hungary': [45.737128, 48.585257, 16.1138867, 22.8977094],
'Iceland': [63.0859177, 67.353, -25.0135069, -12.8046162],
'India': [6.5546079, 35.6745457, 68.1113787, 97.395561],
'Indonesia': [-11.2085669, 6.2744496, 94.7717124, 141.0194444],
'Iran': [24.8465103, 39.7816502, 44.0318908, 63.3332704],
'Iraq': [29.0585661, 37.380932, 38.7936719, 48.8412702],
'Ireland': [51.222, 55.636, -11.0133788, -5.6582363],
'Isle of Man': [54.0539576, 54.4178705, -4.7946845, -4.3076853],
'Israel': [29.4533796, 33.3356317, 34.2674994, 35.8950234],
'Italy': [35.2889616, 47.0921462, 6.6272658, 18.7844746],
'Ivory Coast': [4.1621205, 10.740197, -8.601725, -2.493031],
'Jamaica': [16.5899443, 18.7256394, -78.5782366, -75.7541143],
'Japan': [20.2145811, 45.7112046, 122.7141754, 154.205541],
'Jersey': [49.1625179, 49.2621288, -2.254512, -2.0104193],
'Jordan': [29.183401, 33.3750617, 34.8844372, 39.3012981],
'Kazakhstan': [40.5686476, 55.4421701, 46.4932179, 87.3156316],
'Kenya': [-4.8995204, 4.62, 33.9098987, 41.899578],
'Kiribati': [-7.0516717, 7.9483283, -179.1645388, -164.1645388],
'Kuwait': [28.5243622, 30.1038082, 46.5526837, 49.0046809],
'Kyrgyzstan': [39.1728437, 43.2667971, 69.2649523, 80.2295793],
'Laos': [13.9096752, 22.5086717, 100.0843247, 107.6349989],
'Latvia': [55.6746505, 58.0855688, 20.6715407, 28.2414904],
'Lebanon': [33.0479858, 34.6923543, 34.8825667, 36.625],
'Lesotho': [-30.6772773, -28.570615, 27.0114632, 29.4557099],
'Liberia': [4.1555907, 8.5519861, -11.6080764, -7.367323],
'Libya': [19.5008138, 33.3545898, 9.391081, 25.3770629],
'Liechtenstein': [47.0484291, 47.270581, 9.4716736, 9.6357143],
'Lithuania': [53.8967893, 56.4504213, 20.653783, 26.8355198],
'Luxembourg': [49.4969821, 50.430377, 4.9684415, 6.0344254],
'Macao': [22.0766667, 22.2170361, 113.5281666, 113.6301389],
'Macedonia': [40.8536596, 42.3735359, 20.4529023, 23.034051],
'Madagascar': [-25.6071002, -11.9519693, 43.2202072, 50.4862553],
'Malawi': [-17.1296031, -9.3683261, 32.6703616, 35.9185731],
'Malaysia': [-5.1076241, 9.8923759, 105.3471939, 120.3471939],
'Maldives': [-0.9074935, 7.3106246, 72.3554187, 73.9700962],
'Mali': [10.147811, 25.001084, -12.2402835, 4.2673828],
'Malta': [35.6029696, 36.2852706, 13.9324226, 14.8267966],
'Marshall Islands': [-0.5481258, 14.4518742, 163.4985095, 178.4985095],
'Martinique': [14.3948596, 14.8787029, -61.2290815, -60.8095833],
'Mauritania': [14.7209909, 27.314942, -17.068081, -4.8333344],
'Mauritius': [-20.725, -10.138, 56.3825151, 63.7151319],
'Mayotte': [-13.0210119, -12.6365902, 45.0183298, 45.2999917],
'Mexico': [14.3886243, 32.7186553, -118.59919, -86.493266],
'Micronesia': [0.827, 10.291, 137.2234512, 163.2364054],
'Moldova': [45.4674139, 48.4918695, 26.6162189, 30.1636756],
'Monaco': [43.7247599, 43.7519311, 7.4090279, 7.4398704],
'Mongolia': [41.5800276, 52.1496, 87.73762, 119.931949],
'Montenegro': [41.7495999, 43.5585061, 18.4195781, 20.3561641],
'Montserrat': [16.475, 17.0152978, -62.450667, -61.9353818],
'Morocco': [21.3365321, 36.0505269, -17.2551456, -0.998429],
'Mozambique': [-26.9209427, -10.3252149, 30.2138197, 41.0545908],
'Myanmar': [9.4399432, 28.547835, 92.1719423, 101.1700796],
'Namibia': [-28.96945, -16.9634855, 11.5280384, 25.2617671],
'Nauru': [-0.5541334, -0.5025906, 166.9091794, 166.9589235],
'Nepal': [26.3477581, 30.446945, 80.0586226, 88.2015257],
'Netherlands': [50.7295671, 53.7253321, 1.9193492, 7.2274985],
'Netherlands Antilles': [12.1544542, 12.1547472, -68.940593, -68.9403518],
'New Caledonia': [-23.2217509, -17.6868616, 162.6034343, 167.8109827],
'New Zealand': [-52.8213687, -29.0303303, -179.059153, 179.3643594],
'Nicaragua': [10.7076565, 15.0331183, -87.901532, -82.6227023],
'Niger': [11.693756, 23.517178, 0.1689653, 15.996667],
'Nigeria': [4.0690959, 13.885645, 2.676932, 14.678014],
'Niue': [-19.3548665, -18.7534559, -170.1595029, -169.5647229],
'Norfolk Island': [-29.333, -28.796, 167.6873878, 168.2249543],
'North Korea': [37.5867855, 43.0089642, 124.0913902, 130.924647],
'Northern Mariana Islands': [14.036565, 20.616556, 144.813338, 146.154418],
'Norway': [57.7590052, 71.3848787, 4.0875274, 31.7614911],
'Oman': [16.4649608, 26.7026737, 52, 60.054577],
'Pakistan': [23.5393916, 37.084107, 60.872855, 77.1203914],
'Palau': [2.748, 8.222, 131.0685462, 134.7714735],
'Palestinian Territory': [31.2201289, 32.5521479, 34.0689732, 35.5739235],
'Panama': [7.0338679, 9.8701757, -83.0517245, -77.1393779],
'Papua New Guinea': [-13.1816069, 1.8183931, 136.7489081, 151.7489081],
'Paraguay': [-27.6063935, -19.2876472, -62.6442036, -54.258],
'Peru': [-20.1984472, -0.0392818, -84.6356535, -68.6519906],
'Philippines': [4.2158064, 21.3217806, 114.0952145, 126.8072562],
'Pitcairn': [-25.1306736, -23.8655769, -130.8049862, -124.717534],
'Poland': [49.0020468, 55.0336963, 14.1229707, 24.145783],
'Portugal': [29.8288021, 42.1543112, -31.5575303, -6.1891593],
'Puerto Rico': [17.9268695, 18.5159789, -67.271492, -65.5897525],
'Qatar': [24.4707534, 26.3830212, 50.5675, 52.638011],
'Republic of the Congo': [-5.149089, 3.713056, 11.0048205, 18.643611],
'Reunion': [-21.3897308, -20.8717136, 55.2164268, 55.8366924],
'Romania': [43.618682, 48.2653964, 20.2619773, 30.0454257],
'Russia': [41.1850968, 82.0586232, 19.6389, 180],
'Rwanda': [-2.8389804, -1.0474083, 28.8617546, 30.8990738],
'Saint Barthelemy': [17.670931, 18.1375569, -63.06639, -62.5844019],
'Saint Helena': [-16.23, -15.704, -5.9973424, -5.4234153],
'Saint Kitts and Nevis': [16.895, 17.6158146, -63.051129, -62.3303519],
'Saint Lucia': [13.508, 14.2725, -61.2853867, -60.6669363],
'Saint Martin': [17.8963535, 18.1902778, -63.3605643, -62.7644063],
'Saint Pierre and Miquelon': [46.5507173, 47.365, -56.6972961, -55.9033333],
'Saint Vincent and the Grenadines': [12.5166548, 13.583, -61.6657471, -60.9094146],
'Samoa': [-14.2770916, -13.2381892, -173.0091864, -171.1929229],
'San Marino': [43.8937002, 43.992093, 12.4033246, 12.5160665],
'Sao Tome and Principe': [-0.2135137, 1.9257601, 6.260642, 7.6704783],
'Saudi Arabia': [16.29, 32.1543377, 34.4571718, 55.6666851],
'Senegal': [12.2372838, 16.6919712, -17.7862419, -11.3458996],
'Serbia': [42.2322435, 46.1900524, 18.8142875, 23.006309],
'Seychelles': [-10.4649258, -3.512, 45.9988759, 56.4979396],
'Sierra Leone': [6.755, 9.999973, -13.5003389, -10.271683],
'Singapore': [1.1304753, 1.4504753, 103.6920359, 104.0120359],
'Slovakia': [47.7314286, 49.6138162, 16.8331891, 22.56571],
'Slovenia': [45.4214242, 46.8766816, 13.3754696, 16.5967702],
'Solomon Islands': [-13.2424298, -4.81085, 155.3190556, 170.3964667],
'Somalia': [-1.8031969, 12.1889121, 40.98918, 51.6177696],
'South Africa': [-47.1788335, -22.1250301, 16.3335213, 38.2898954],
'South Georgia and the South Sandwich Islands': [-59.684, -53.3500755, -42.354739, -25.8468303],
'South Korea': [32.9104556, 38.623477, 124.354847, 132.1467806],
'Spain': [27.4335426, 43.9933088, -18.3936845, 4.5918885],
'Sri Lanka': [5.719, 10.035, 79.3959205, 82.0810141],
'Sudan': [8.685278, 22.224918, 21.8145046, 39.0576252],
'Suriname': [1.8312802, 6.225, -58.070833, -53.8433358],
'Svalbard and Jan Mayen': [70.6260825, 81.028076, -9.6848146, 34.6891253],
'Swaziland': [-27.3175201, -25.71876, 30.7908, 32.1349923],
'Sweden': [55.1331192, 69.0599699, 10.5930952, 24.1776819],
'Switzerland': [45.817995, 47.8084648, 5.9559113, 10.4922941],
'Syria': [32.311354, 37.3184589, 35.4714427, 42.3745687],
'Taiwan': [10.374269, 26.4372222, 114.3599058, 122.297],
'Tajikistan': [36.6711153, 41.0450935, 67.3332775, 75.1539563],
'Tanzania': [-11.761254, -0.9854812, 29.3269773, 40.6584071],
'Thailand': [5.612851, 20.4648337, 97.3438072, 105.636812],
'Togo': [5.926547, 11.1395102, -0.1439746, 1.8087605],
'Tokelau': [-9.6442499, -8.3328631, -172.7213673, -170.9797586],
'Tonga': [-24.1034499, -15.3655722, -179.3866055, -173.5295458],
'Trinidad and Tobago': [9.8732106, 11.5628372, -62.083056, -60.2895848],
'Tunisia': [30.230236, 37.7612052, 7.5219807, 11.8801133],
'Turkey': [35.8076804, 42.297, 25.6212891, 44.8176638],
'Turkmenistan': [35.129093, 42.7975571, 52.335076, 66.6895177],
'Turks and Caicos Islands': [20.9553418, 22.1630989, -72.6799046, -70.8643591],
'Tuvalu': [-9.9939389, -5.4369611, 175.1590468, 178.7344938],
'U.S. Virgin Islands': [17.623468, 18.464984, -65.159094, -64.512674],
'Uganda': [-1.4823179, 4.2340766, 29.573433, 35.000308],
'Ukraine': [44.184598, 52.3791473, 22.137059, 40.2275801],
'United Arab Emirates': [22.6444, 26.2822, 51.498, 56.3834],
'United Kingdom': [49.674, 61.061, -14.015517, 2.0919117],
'United States': [24.9493, 49.5904, -125.0011, -66.9326],
'United States Minor Outlying Islands': [6.1779744, 6.6514388, -162.6816297, -162.1339885],
'Uruguay': [-35.7824481, -30.0853962, -58.4948438, -53.0755833],
'Uzbekistan': [37.1821164, 45.590118, 55.9977865, 73.1397362],
'Vanuatu': [-20.4627425, -12.8713777, 166.3355255, 170.449982],
'Vatican': [41.9002044, 41.9073912, 12.4457442, 12.4583653],
'Venezuela': [0.647529, 15.9158431, -73.3529632, -59.5427079],
'Vietnam': [8.1790665, 23.393395, 102.14441, 114.3337595],
'Wallis and Futuna': [-14.5630748, -12.9827961, -178.3873749, -175.9190391],
'Western Sahara': [20.556883, 27.6666834, -17.3494721, -8.666389],
'Yemen': [11.9084802, 19.0, 41.60825, 54.7389375],
'Zambia': [-18.0765945, -8.2712822, 21.9993509, 33.701111],
'Zimbabwe': [-22.4241096, -15.6097033, 25.2373, 33.0683413]
}
def ReverseGeocoding(self, lat, lng):
countries = []
for country, box in self.bbox.items():
if lat >= box[0] and lat <= box[1] and lng >= box[2] and lng <= box[3]:
countries.append(country)
if not countries:
return "Earth"
else:
return '/'.join(countries)
def lookup(self, mac):
url = "https://hashc.co.uk/api/locate/mac/"
data = {
'apikey': hashC_APIKEY,
'mac': mac
}
try:
response = requests.post(url, data=data, timeout=30)
response_json = response.json()
lat, lng = response_json.get('lat'), response_json.get('lng')
if lat and lng:
return '{} ({}, {})'.format(self.ReverseGeocoding(lat, lng), lat, lng)
return response_json
except:
return {}
##################
### Database-Like ###
## Tables:
class statistics(dict):
"""
Convention:
statistics[bssid][X] = Number of frames type X in bssid
where X is a cosnt int (ESSID_SOURCE_* / EXC_PKT_NUM_*)
Examples:
statistics[bssid][1] = 5; means bssid packets contains 5 eapol-m1 frames
statistics[bssid][40] = 3; means bssid packets contains 3 undirected probe frames
"""
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, {value: 1})
else:
if value not in self[key]:
self[key].__setitem__(value, 1)
else:
self[key][value] += 1
class passwords(list):
def __init__(self):
list.__init__(self)
class essids(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
elif value['essid_source'] > self[key]['essid_source']:
self[key]['essid_source'] = value['essid_source']
class excpkts(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
else:
subkey = list(value.keys())[0]
if subkey not in self[key]:
self[key].__setitem__(subkey, list(value.values())[0])
else:
subsubkey = list(list(value.values())[0].keys())[0]
if subsubkey not in self[key][subkey]:
self[key][subkey].__setitem__(subsubkey, list(list(value.values())[0].values())[0])
else:
self[key][subkey][subsubkey].append(list(list(value.values())[0].values())[0][0])
class eapmd5s(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
else:
subkey = list(value.keys())[0]
if subkey not in self[key]:
self[key].__setitem__(subkey, list(value.values())[0])
else:
if not self[key][subkey]['hash'] and list(value.values())[0]['hash']:
self[key][subkey]['hash'] = list(value.values())[0]['hash']
if not self[key][subkey]['salt'] and list(value.values())[0]['salt']:
self[key][subkey]['salt'] = list(value.values())[0]['salt']
class eapleaps(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
else:
subkey = list(value.keys())[0]
if subkey not in self[key]:
self[key].__setitem__(subkey, list(value.values())[0])
else:
if not self[key][subkey]['resp1'] and list(value.values())[0]['resp1']:
self[key][subkey]['resp1'] = list(value.values())[0]['resp1']
if not self[key][subkey]['resp2'] and list(value.values())[0]['resp2']:
self[key][subkey]['resp2'] = list(value.values())[0]['resp2']
class hccaps(list):
def __init__(self):
list.__init__(self)
class hccapxs(list):
def __init__(self):
list.__init__(self)
class hcwpaxs(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
class hcpmkids(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
class pmkids(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
else:
self[key]['pmkid'] = value['pmkid']
class pcapng_info(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, [value])
else:
self[key].append(value)
class hceapmd5s(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
class hceapleaps(dict):
def __setitem__(self, key, value):
if key not in self:
dict.__setitem__(self, key, value)
## Database:
class Database(object):
def __init__(self):
super(Database, self).__init__()
self.statistics = statistics()
self.passwords = passwords()
self.essids = essids()
self.excpkts = excpkts()
self.eapmd5s = eapmd5s()
self.eapleaps = eapleaps()
self.hccaps = hccaps()
self.hccapxs = hccapxs()
self.hcwpaxs = hcwpaxs()
self.hcpmkids = hcpmkids()
self.pmkids = pmkids()
self.pcapng_info = pcapng_info()
self.hceapmd5s = hceapmd5s()
self.hceapleaps = hceapleaps()
def statistic_add(self, bssid, data):
self.statistics.__setitem__(bssid, data)
def password_add(self, password):
for char in password:
if char < 0x20 or char > 0x7e:
self.passwords.append("$HEX[{}]".format(password.hex()))
return
self.passwords.append(password.decode('ascii'))
def essid_add(self, bssid, essid, essid_len, essid_source):
# Init
key = bssid
# Record data to statistics
self.statistic_add(key, essid_source)
# Check
if essid_len == 0 or not essid:
return
if len(self.essids) == DB_ESSID_MAX:
LOGGER.log('DB_ESSID_MAX Exceeded!', CRITICAL)
raise ValueError('DB_ESSID_MAX Exceeded!')
# Add
self.essids.__setitem__(key, {
'bssid': key,
'essid': essid,
'essid_len': essid_len,
'essid_source': essid_source
})
def excpkt_add(self, excpkt_num, tv_sec, tv_usec, replay_counter, mac_ap, mac_sta, nonce, eapol_len, eapol, keyver, keymic):
# Init
key = mac_ap
subkey = mac_sta
subsubkey = 'ap' if excpkt_num in [EXC_PKT_NUM_1, EXC_PKT_NUM_3] else 'sta'
# Record data to statistics
self.statistic_add(key, excpkt_num)
# Check
if nonce == ZERO*32:
return
if len(self.excpkts) == DB_EXCPKT_MAX:
LOGGER.log('DB_EXCPKT_MAX Exceeded!', CRITICAL)
raise ValueError('DB_EXCPKT_MAX Exceeded!')
# Add
self.excpkts.__setitem__(key, {subkey: {subsubkey: [{
'excpkt_num': excpkt_num,
'tv_sec': tv_sec,
'tv_usec': tv_usec,
'tv_abs': (tv_sec*1000*1000)+tv_usec,
'replay_counter': replay_counter,
'mac_ap': key,
'mac_sta': subkey,
'nonce': nonce,
'eapol_len': eapol_len,
'eapol': eapol,
'keyver': keyver,
'keymic': keymic
}]}})
def eapmd5_add(self, auth_id, mac_ap, mac_sta, auth_hash, auth_salt):
key = mac_ap
subkey = hash(auth_id+bytes(mac_ap+mac_sta).hex())
self.eapmd5s.__setitem__(key, {subkey: {
'id': auth_id,
'mac_ap': mac_ap,
'mac_sta': mac_sta,
'hash': auth_hash,
'salt': auth_salt
}})
def eapleap_add(self, auth_id, mac_ap, mac_sta, auth_resp1, auth_resp2, auth_name):
key = mac_ap
subkey = hash(auth_id+bytes(mac_ap+mac_sta).hex())
self.eapleaps.__setitem__(key, {subkey: {
'id': auth_id,
'mac_ap': mac_ap,
'mac_sta': mac_sta,
'resp1': auth_resp1,
'resp2': auth_resp2,
'name': auth_name,
}})
def hccap_add(self, bssid, essid, raw_data):
self.hccaps.append({ \
'bssid': bssid, \
'essid': essid, \
'raw_data': raw_data \
})
def hccap_groupby(self, group_by):
if group_by is None or group_by == "none":
self.hccaps = [{'key': 'none', 'raw_data': [v['raw_data'] for v in self.hccaps]}]
elif group_by == "handshake":
self.hccaps = [{'key': v['bssid']+"_"+str(k), 'raw_data': [v['raw_data']]} for k, v in enumerate(self.hccaps)]
else:
self.hccaps.sort(key=itemgetter(group_by))
self.hccaps = groupby(self.hccaps, key=itemgetter(group_by))
self.hccaps = [{'key': k, 'raw_data': [x['raw_data'] for x in v]} for k, v in self.hccaps]
def hccapx_add(self, bssid, essid, raw_data):
self.hccapxs.append({ \
'bssid': bssid, \
'essid': essid, \
'raw_data': raw_data \
})
def hccapx_groupby(self, group_by):
if group_by is None or group_by == "none":
self.hccapxs = [{'key': 'none', 'raw_data': [v['raw_data'] for v in self.hccapxs]}]
elif group_by == "handshake":
self.hccapxs = [{'key': v['bssid']+"_"+str(k), 'raw_data': [v['raw_data']]} for k, v in enumerate(self.hccapxs)]
else:
self.hccapxs.sort(key=itemgetter(group_by))
self.hccapxs = groupby(self.hccapxs, key=itemgetter(group_by))
self.hccapxs = [{'key': k, 'raw_data': [x['raw_data'] for x in v]} for k, v in self.hccapxs]
def hcwpaxs_add(self, signature, ftype, pmkid_or_mic, mac_ap, mac_sta, essid, anonce=None, eapol=None, message_pair=None):
if ftype == "01":
key = pmkid_or_mic
self.hcwpaxs.__setitem__(key, { \
'signature': signature, \
'type': ftype, \
'pmkid_or_mic': pmkid_or_mic, \
'mac_ap': mac_ap, \
'mac_sta': mac_sta, \
'essid': bytes(essid).hex(), \
'anonce': '', \
'eapol': '', \
'message_pair': '' \
})
else:
key = hash((pmkid_or_mic, message_pair))
self.hcwpaxs.__setitem__(key, { \
'signature': signature, \
'type': ftype, \
'pmkid_or_mic': bytes(pmkid_or_mic).hex(), \
'mac_ap': bytes(mac_ap).hex(), \
'mac_sta': bytes(mac_sta).hex(), \
'essid': bytes(essid).hex(), \
'anonce': bytes(anonce).hex(), \
'eapol': bytes(eapol).hex(), \
'message_pair': '{:02x}'.format(message_pair) \
})
def hcpmkid_add(self, pmkid, mac_ap, mac_sta, essid):
key = pmkid
self.hcpmkids.__setitem__(key, { \
'pmkid': pmkid, \
'mac_ap': mac_ap, \
'mac_sta': mac_sta, \
'essid': bytes(essid).hex() \
})
def pmkid_add(self, mac_ap, mac_sta, pmkid, akm):
key = hash(mac_ap+mac_sta)
self.pmkids.__setitem__(key, {
'mac_ap': bytes(mac_ap).hex(),
'mac_sta': bytes(mac_sta).hex(),
'pmkid': pmkid,
'akm': akm
})
def pcapng_info_add(self, key, info):
self.pcapng_info.__setitem__(key, info)
def hceapmd5_add(self, auth_id, auth_hash, auth_salt):
if not (auth_id and auth_hash and auth_salt):
return
key = hash(auth_id+auth_hash+auth_salt)
self.hceapmd5s.__setitem__(key, { \
'auth_hash': auth_hash, \
'auth_salt': auth_salt, \
'auth_id': auth_id \
})
def hceapleap_add(self, auth_resp1, auth_resp2, auth_name):
if not (auth_resp1 and auth_resp2 and auth_name):
return
key = hash(auth_resp1+auth_resp2+auth_name)
self.hceapleaps.__setitem__(key, { \
'auth_name': auth_name, \
'unused1': '', \
'unused2': '', \
'unused3': '', \
'resp1': auth_resp1, \
'resp2': auth_resp2 \
})
DB = Database()
###
### STATUS ###
class Status(object):
def __init__(self):
super(Status, self).__init__()
self.total_filesize = 0
self.current_filepos = 0
self.current_packet = 0
def set_filesize(self, filesize):
self.total_filesize = filesize
def step_packet(self):
self.current_packet += 1
def set_filepos(self, filepos):
self.current_filepos = filepos
###
### HX-Functions ###
def get_essid_from_tag(packet, header, length_skip):
if length_skip > header['caplen']:
return -1, None
length = header['caplen'] - length_skip
beacon = packet[length_skip:length_skip+length]
cur = 0
end = len(beacon)
while cur < end:
if (cur + 2) >= end:
break
tagtype = beacon[cur]
cur += 1
taglen = beacon[cur]
cur += 1
if (cur + taglen) >= end:
break
if tagtype == MFIE_TYPE_SSID:
if taglen <= MAX_ESSID_LEN:
essid = {}
essid['essid'] = beacon[cur:cur+taglen]
essid['essid'] += b'\x00'*(MAX_ESSID_LEN - len(essid['essid']))
essid['essid_len'] = taglen
return 0, essid
cur += taglen
return -1, None
def get_pmkid_from_packet(packet, source):
if source == "EAPOL-M1":
akm = None # Unknown AKM
if packet:
pos = 0
while True:
try:
tag_id = packet[pos]
tag_len = packet[pos+1]
tag_data = packet[pos+2:pos+2+tag_len]
if tag_id == 221:
if tag_data[0:3] == SUITE_OUI:
pmkid = tag_data[4:].hex()
if pmkid != '0'*32:
yield pmkid, akm
pos = pos+2+tag_len
except:
break
return
elif source == "EAPOL-M2":
pos = 0
elif source == IEEE80211_STYPE_ASSOC_REQ:
pos = 28
elif source == IEEE80211_STYPE_REASSOC_REQ:
pos = 34
else:
return
while True:
try:
tag_id = packet[pos]
tag_len = packet[pos+1]
tag_data = packet[pos+2:pos+2+tag_len]
if tag_id == 48:
#tag_version = tag_data[0:2]
#tag_group_cipher_suite = tag_data[2:6]
# Pairwise Cipher Suite
tag_pairwise_suite_count = GetUint16(tag_data[6:8])
if BIG_ENDIAN_HOST:
tag_pairwise_suite_count = byte_swap_16(tag_pairwise_suite_count)
#tag_pairwise_suite = []
pos = 8
#for i in range(0, tag_pairwise_suite_count):
# pos += (4*i)+4
# tag_pairwise_suite.append(tag_data[pos-4:pos])
pos += 4*tag_pairwise_suite_count
# AKM Suite
tag_authentication_suite_count = GetUint16(tag_data[pos:pos+2])
if BIG_ENDIAN_HOST:
tag_authentication_suite_count = byte_swap_16(tag_authentication_suite_count)
#tag_authentication_suite = []
pos = pos+2
skip = 0
for i in range(0, tag_authentication_suite_count):
pos += (4*i)+4
akm = tag_data[pos-4:pos]
if akm[0:3] != SUITE_OUI:
skip = 1
break
if skip == 1:
break
###############
#tag_capabilities = tag_data[pos:pos+2]
##############################
try:
pmkid_count = GetUint16(tag_data[pos+2:pos+4])
if BIG_ENDIAN_HOST:
pmkid_count = byte_swap_16(pmkid_count)
pos = pos+4
for i in range(0, pmkid_count):
pos += (16*i)+16
pmkid = tag_data[pos-16:pos].hex()
if pmkid != '0'*32:
yield pmkid, akm[3]
except:
break
##############################
break
pos = pos+2+tag_len
except:
break
def handle_llc(ieee80211_llc_snap_header):
if ieee80211_llc_snap_header['dsap'] != IEEE80211_LLC_DSAP:
return -1
if ieee80211_llc_snap_header['ssap'] != IEEE80211_LLC_SSAP:
return -1
if ieee80211_llc_snap_header['ctrl'] != IEEE80211_LLC_CTRL:
return -1
if ieee80211_llc_snap_header['ethertype'] != IEEE80211_DOT1X_AUTHENTICATION:
return -1
return 0
def handle_auth(auth_packet, auth_packet_copy, auth_packet_t_size, keymic_size, rest_packet, pkt_offset, pkt_size):
ap_length = byte_swap_16(auth_packet['length'])
ap_key_information = byte_swap_16(auth_packet['key_information'])
ap_replay_counter = byte_swap_64(auth_packet['replay_counter'])
ap_wpa_key_data_length = byte_swap_16(auth_packet['wpa_key_data_length'])
if ap_length == 0:
return -1, None
if ap_key_information & WPA_KEY_INFO_ACK:
if ap_key_information & WPA_KEY_INFO_INSTALL:
excpkt_num = EXC_PKT_NUM_3
else:
excpkt_num = EXC_PKT_NUM_1