Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
derv82
GitHub Repository: derv82/wifite2
Path: blob/master/wifite/tools/pyrit.py
412 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
from .dependency import Dependency
5
from ..util.process import Process
6
import re
7
8
class Pyrit(Dependency):
9
''' Wrapper for Pyrit program. '''
10
dependency_required = False
11
dependency_name = 'pyrit'
12
dependency_url = 'https://github.com/JPaulMora/Pyrit/wiki'
13
14
def __init__(self):
15
pass
16
17
18
@staticmethod
19
def bssid_essid_with_handshakes(capfile, bssid=None, essid=None):
20
if not Pyrit.exists():
21
return []
22
23
command = [
24
'pyrit',
25
'-r', capfile,
26
'analyze'
27
]
28
pyrit = Process(command, devnull=False)
29
30
current_bssid = current_essid = None
31
bssid_essid_pairs = set()
32
33
'''
34
#1: AccessPoint 18:a6:f7:31:d2:06 ('TP-LINK_D206'):
35
#1: Station 08:66:98:b2:ab:28, 1 handshake(s):
36
#1: HMAC_SHA1_AES, good, spread 1
37
#2: Station ac:63:be:3a:a2:f4
38
'''
39
40
for line in pyrit.stdout().split('\n'):
41
mac_regex = ('[a-zA-Z0-9]{2}:' * 6)[:-1]
42
match = re.search("^#\d+: AccessPoint (%s) \('(.*)'\):$" % (mac_regex), line)
43
if match:
44
# We found a new BSSID and ESSID
45
(current_bssid, current_essid) = match.groups()
46
47
if bssid is not None and bssid.lower() != current_bssid:
48
current_bssid = None
49
current_essid = None
50
elif essid is not None and essid != current_essid:
51
current_bssid = None
52
current_essid = None
53
54
elif current_bssid is not None and current_essid is not None:
55
# We hit an AP that we care about.
56
# Line does not contain AccessPoint, see if it's 'good'
57
if ', good' in line:
58
bssid_essid_pairs.add( (current_bssid, current_essid) )
59
60
return list(bssid_essid_pairs)
61
62