@@ -32,8 +32,9 @@ def initialize
32
32
'Actions' => [
33
33
[ 'john' , { 'Description' => 'Use John the Ripper' } ] ,
34
34
[ 'hashcat' , { 'Description' => 'Use Hashcat' } ] ,
35
+ [ 'auto' , { 'Description' => 'Use either John the Ripper or Hashcat, if both are present, use Hashcat' } ]
35
36
] ,
36
- 'DefaultAction' => 'john ' ,
37
+ 'DefaultAction' => 'auto ' ,
37
38
'Notes' => {
38
39
'Stability' => [ CRASH_SAFE ] ,
39
40
'SideEffects' => [ ] ,
@@ -58,30 +59,35 @@ def initialize
58
59
def show_command ( cracker_instance )
59
60
return unless datastore [ 'ShowCommand' ]
60
61
61
- if action . name == 'john'
62
+ newaction = getaction ( )
63
+
64
+ if newaction == 'john'
62
65
cmd = cracker_instance . john_crack_command
63
- elsif action . name == 'hashcat'
66
+ elsif newaction == 'hashcat'
64
67
cmd = cracker_instance . hashcat_crack_command
65
68
end
66
69
print_status ( " Cracking Command: #{ cmd . join ( ' ' ) } " )
67
70
end
68
71
69
72
def check_results ( passwords , results , hash_type , method )
73
+
74
+ newaction = getaction ( )
75
+
70
76
passwords . each do |password_line |
71
77
password_line . chomp!
72
78
next if password_line . blank?
73
79
74
80
fields = password_line . split ( ':' )
75
81
cred = { 'hash_type' => hash_type , 'method' => method }
76
82
77
- if action . name == 'john'
83
+ if newaction == 'john'
78
84
next unless fields . count >= 3 # If we don't have an expected minimum number of fields, this is probably not a hash line
79
85
80
86
cred [ 'username' ] = fields . shift
81
87
cred [ 'core_id' ] = fields . pop
82
88
4 . times { fields . pop } # Get rid of extra :
83
89
cred [ 'password' ] = fields . join ( ':' ) # Anything left must be the password. This accounts for passwords with semi-colons in it
84
- elsif action . name == 'hashcat'
90
+ elsif newaction == 'hashcat'
85
91
next unless fields . count >= 2 # If we don't have an expected minimum number of fields, this is probably not a hash line
86
92
87
93
cred [ 'core_id' ] = fields . shift
@@ -100,6 +106,9 @@ def check_results(passwords, results, hash_type, method)
100
106
end
101
107
102
108
def run
109
+
110
+ newaction = getaction ( )
111
+
103
112
tbl = tbl = cracker_results_table
104
113
105
114
# array of hashes in jtr_format in the db, converted to an OR combined regex
@@ -115,7 +124,7 @@ def run
115
124
116
125
# build our job list
117
126
hash_types_to_crack . each do |hash_type |
118
- job = hash_job ( hash_type , action . name )
127
+ job = hash_job ( hash_type , newaction )
119
128
if job . nil?
120
129
print_status ( "No #{ hash_type } found to crack" )
121
130
else
@@ -133,7 +142,7 @@ def run
133
142
# Inner array format: db_id, hash_type, username, password, method_of_crack
134
143
results = [ ]
135
144
136
- cracker = new_password_cracker ( action . name )
145
+ cracker = new_password_cracker ( newaction )
137
146
138
147
# generate our wordlist and close the file handle.
139
148
wordlist = wordlist_file
@@ -158,7 +167,7 @@ def run
158
167
cracker_instance = cracker . dup
159
168
cracker_instance . format = format
160
169
161
- if action . name == 'john'
170
+ if newaction == 'john'
162
171
cracker_instance . fork = datastore [ 'FORK' ]
163
172
end
164
173
@@ -169,7 +178,7 @@ def run
169
178
job [ 'cred_ids_left_to_crack' ] = job [ 'cred_ids_left_to_crack' ] - results . map { |i | i [ 0 ] . to_i } # remove cracked hashes from the hash list
170
179
next if job [ 'cred_ids_left_to_crack' ] . empty?
171
180
172
- if action . name == 'john'
181
+ if newaction == 'john'
173
182
print_status "Cracking #{ format } hashes in single mode..."
174
183
cracker_instance . mode_single ( wordlist . path )
175
184
show_command cracker_instance
@@ -211,7 +220,7 @@ def run
211
220
print_status "Cracking #{ format } hashes in wordlist mode..."
212
221
cracker_instance . mode_wordlist ( wordlist . path )
213
222
# Turn on KoreLogic rules if the user asked for it
214
- if action . name == 'john' && datastore [ 'KORELOGIC' ]
223
+ if newaction == 'john' && datastore [ 'KORELOGIC' ]
215
224
cracker_instance . rules = 'KoreLogicRules'
216
225
print_status 'Applying KoreLogic ruleset...'
217
226
end
@@ -235,4 +244,24 @@ def run
235
244
end
236
245
end
237
246
end
247
+
248
+ def getaction
249
+ newaction = action . name
250
+ if action . name == 'auto'
251
+ path = Rex ::FileUtils . find_full_path ( 'hashcat' ) ||
252
+ Rex ::FileUtils . find_full_path ( 'hashcat.exe' )
253
+ if path
254
+ newaction = 'hashcat'
255
+ else
256
+ path = Rex ::FileUtils . find_full_path ( 'john' ) ||
257
+ Rex ::FileUtils . find_full_path ( 'john.exe' )
258
+ if path
259
+ newaction = 'john'
260
+ else
261
+ raise PasswordCrackerNotFoundError , 'No suitable john/hashcat binary was found on the system'
262
+ end
263
+ end
264
+ end
265
+ return newaction
266
+ end
238
267
end
0 commit comments