@@ -24,8 +24,9 @@ def initialize
24
24
'Actions' => [
25
25
[ 'john' , { 'Description' => 'Use John the Ripper' } ] ,
26
26
[ 'hashcat' , { 'Description' => 'Use Hashcat' } ] ,
27
+ [ 'auto' , { 'Description' => 'Use either John the Ripper or Hashcat, if both are present, use Hashcat' } ]
27
28
] ,
28
- 'DefaultAction' => 'john ' ,
29
+ 'DefaultAction' => 'auto ' ,
29
30
'Notes' => {
30
31
'Stability' => [ CRASH_SAFE ] ,
31
32
'SideEffects' => [ ] ,
@@ -48,29 +49,34 @@ def initialize
48
49
def show_command ( cracker_instance )
49
50
return unless datastore [ 'ShowCommand' ]
50
51
51
- if action . name == 'john'
52
+ newaction = getaction ( )
53
+
54
+ if newaction == 'john'
52
55
cmd = cracker_instance . john_crack_command
53
- elsif action . name == 'hashcat'
56
+ elsif newaction == 'hashcat'
54
57
cmd = cracker_instance . hashcat_crack_command
55
58
end
56
59
print_status ( " Cracking Command: #{ cmd . join ( ' ' ) } " )
57
60
end
58
61
59
62
def check_results ( passwords , results , hash_type , method )
63
+
64
+ newaction = getaction ( )
65
+
60
66
passwords . each do |password_line |
61
67
password_line . chomp!
62
68
next if password_line . blank?
63
69
64
70
fields = password_line . split ( ':' )
65
71
cred = { 'hash_type' => hash_type , 'method' => method }
66
72
# If we don't have an expected minimum number of fields, this is probably not a hash line
67
- if action . name == 'john'
73
+ if newaction == 'john'
68
74
next unless fields . count >= 3
69
75
70
76
cred [ 'username' ] = fields . shift
71
77
cred [ 'core_id' ] = fields . pop
72
78
cred [ 'password' ] = fields . join ( ':' ) # Anything left must be the password. This accounts for passwords with semi-colons in it
73
- elsif action . name == 'hashcat'
79
+ elsif newaction == 'hashcat'
74
80
next unless fields . count >= 2
75
81
76
82
cred [ 'core_id' ] = fields . shift
@@ -89,6 +95,9 @@ def check_results(passwords, results, hash_type, method)
89
95
end
90
96
91
97
def run
98
+
99
+ newaction = getaction ( )
100
+
92
101
tbl = tbl = cracker_results_table
93
102
94
103
hash_types_to_crack = [ ]
@@ -100,7 +109,7 @@ def run
100
109
101
110
# build our job list
102
111
hash_types_to_crack . each do |hash_type |
103
- job = hash_job ( hash_type , action . name )
112
+ job = hash_job ( hash_type , newaction )
104
113
if job . nil?
105
114
print_status ( "No #{ hash_type } found to crack" )
106
115
else
@@ -118,7 +127,7 @@ def run
118
127
# Inner array format: db_id, hash_type, username, password, method_of_crack
119
128
results = [ ]
120
129
121
- cracker = new_password_cracker ( action . name )
130
+ cracker = new_password_cracker ( newaction )
122
131
123
132
# generate our wordlist and close the file handle.
124
133
wordlist = wordlist_file
@@ -142,7 +151,7 @@ def run
142
151
# dupe our original cracker so we can safely change options between each run
143
152
cracker_instance = cracker . dup
144
153
cracker_instance . format = format
145
- if action . name == 'john'
154
+ if newaction == 'john'
146
155
cracker_instance . fork = datastore [ 'FORK' ]
147
156
end
148
157
@@ -153,7 +162,7 @@ def run
153
162
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
154
163
next if job [ 'cred_ids_left_to_crack' ] . empty?
155
164
156
- if action . name == 'john'
165
+ if newaction == 'john'
157
166
print_status "Cracking #{ format } hashes in single mode..."
158
167
cracker_instance . mode_single ( wordlist . path )
159
168
show_command cracker_instance
@@ -194,7 +203,7 @@ def run
194
203
print_status "Cracking #{ format } hashes in wordlist mode..."
195
204
cracker_instance . mode_wordlist ( wordlist . path )
196
205
# Turn on KoreLogic rules if the user asked for it
197
- if action . name == 'john' && datastore [ 'KORELOGIC' ]
206
+ if newaction == 'john' && datastore [ 'KORELOGIC' ]
198
207
cracker_instance . rules = 'KoreLogicRules'
199
208
print_status 'Applying KoreLogic ruleset...'
200
209
end
@@ -218,4 +227,25 @@ def run
218
227
end
219
228
end
220
229
end
230
+
231
+ def getaction
232
+ newaction = action . name
233
+ if action . name == 'auto'
234
+ path = Rex ::FileUtils . find_full_path ( 'hashcat' ) ||
235
+ Rex ::FileUtils . find_full_path ( 'hashcat.exe' )
236
+ if path
237
+ newaction = 'hashcat'
238
+ else
239
+ path = Rex ::FileUtils . find_full_path ( 'john' ) ||
240
+ Rex ::FileUtils . find_full_path ( 'john.exe' )
241
+ if path
242
+ newaction = 'john'
243
+ else
244
+ raise PasswordCrackerNotFoundError , 'No suitable john/hashcat binary was found on the system'
245
+ end
246
+ end
247
+ end
248
+ return newaction
249
+ end
250
+
221
251
end
0 commit comments