Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
derv82
GitHub Repository: derv82/wifite2
Path: blob/master/wifite/tools/john.py
412 views
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
from .dependency import Dependency
5
from ..config import Configuration
6
from ..util.color import Color
7
from ..util.process import Process
8
from ..tools.hashcat import HcxPcapTool
9
10
import os
11
12
13
class John(Dependency):
14
''' Wrapper for John program. '''
15
dependency_required = False
16
dependency_name = 'john'
17
dependency_url = 'http://www.openwall.com/john/'
18
19
20
@staticmethod
21
def crack_handshake(handshake, show_command=False):
22
john_file = HcxPcapTool.generate_john_file(handshake, show_command=show_command)
23
24
# Use `john --list=formats` to find if OpenCL or CUDA is supported.
25
formats_stdout = Process(['john', '--list=formats']).stdout()
26
if 'wpapsk-opencl' in formats_stdout:
27
john_format = 'wpapsk-opencl'
28
elif 'wpapsk-cuda' in formats_stdout:
29
john_format = 'wpapsk-cuda'
30
else:
31
john_format = 'wpapsk'
32
33
# Crack john file
34
command = [
35
'john',
36
'--format=%s' % john_format,
37
'--wordlist', Configuration.wordlist,
38
john_file
39
]
40
41
if show_command:
42
Color.pl('{+} {D}Running: {W}{P}%s{W}' % ' '.join(command))
43
process = Process(command)
44
process.wait()
45
46
# Run again with --show to consistently get the password
47
command = ['john', '--show', john_file]
48
if show_command:
49
Color.pl('{+} {D}Running: {W}{P}%s{W}' % ' '.join(command))
50
process = Process(command)
51
stdout, stderr = process.get_output()
52
53
# Parse password (regex doesn't work for some reason)
54
if '0 password hashes cracked' in stdout:
55
key = None
56
else:
57
for line in stdout.split('\n'):
58
if handshake.capfile in line:
59
key = line.split(':')[1]
60
break
61
62
if os.path.exists(john_file):
63
os.remove(john_file)
64
65
return key
66
67