@@ -25,8 +25,9 @@ def initialize
25
25
'Actions' => [
26
26
[ 'john' , { 'Description' => 'Use John the Ripper' } ] ,
27
27
[ 'hashcat' , { 'Description' => 'Use Hashcat' } ] ,
28
+ [ 'auto' , { 'Description' => 'Use either John the Ripper or Hashcat, if both are present, use Hashcat' } ]
28
29
] ,
29
- 'DefaultAction' => 'john ' ,
30
+ 'DefaultAction' => 'auto ' ,
30
31
'Notes' => {
31
32
'Stability' => [ CRASH_SAFE ] ,
32
33
'SideEffects' => [ ] ,
@@ -44,16 +45,21 @@ def initialize
44
45
45
46
def show_command ( cracker_instance )
46
47
return unless datastore [ 'ShowCommand' ]
48
+
49
+ newaction = getaction ( )
47
50
48
- if action . name == 'john'
51
+ if newaction == 'john'
49
52
cmd = cracker_instance . john_crack_command
50
- elsif action . name == 'hashcat'
53
+ elsif newaction == 'hashcat'
51
54
cmd = cracker_instance . hashcat_crack_command
52
55
end
53
56
print_status ( " Cracking Command: #{ cmd . join ( ' ' ) } " )
54
57
end
55
58
56
59
def check_results ( passwords , results , hash_type , method )
60
+
61
+ newaction = getaction ( )
62
+
57
63
passwords . each do |password_line |
58
64
password_line . chomp!
59
65
next if password_line . blank?
@@ -63,12 +69,12 @@ def check_results(passwords, results, hash_type, method)
63
69
next unless fields . count >= 3
64
70
65
71
cred = { 'hash_type' => hash_type , 'method' => method }
66
- if action . name == 'john'
72
+ if newaction == 'john'
67
73
cred [ 'username' ] = fields . shift
68
74
cred [ 'core_id' ] = fields . pop
69
75
4 . times { fields . pop } # Get rid of extra :
70
76
cred [ 'password' ] = fields . join ( ':' ) # Anything left must be the password. This accounts for passwords with semi-colons in it
71
- elsif action . name == 'hashcat'
77
+ elsif newaction == 'hashcat'
72
78
cred [ 'core_id' ] = fields . shift
73
79
cred [ 'hash' ] = fields . shift
74
80
cred [ 'password' ] = fields . join ( ':' ) # Anything left must be the password. This accounts for passwords with semi-colons in it
@@ -85,14 +91,17 @@ def check_results(passwords, results, hash_type, method)
85
91
end
86
92
87
93
def run
94
+
95
+ newaction = getaction ( )
96
+
88
97
tbl = tbl = cracker_results_table
89
98
90
99
hash_types_to_crack = [ 'descrypt' ]
91
100
jobs_to_do = [ ]
92
101
93
102
# build our job list
94
103
hash_types_to_crack . each do |hash_type |
95
- job = hash_job ( hash_type , action . name )
104
+ job = hash_job ( hash_type , newaction )
96
105
if job . nil?
97
106
print_status ( "No #{ hash_type } found to crack" )
98
107
else
@@ -110,7 +119,7 @@ def run
110
119
# Inner array format: db_id, hash_type, username, password, method_of_crack
111
120
results = [ ]
112
121
113
- cracker = new_password_cracker ( action . name )
122
+ cracker = new_password_cracker ( newaction )
114
123
115
124
# generate our wordlist and close the file handle. max length of DES is 8
116
125
wordlist = wordlist_file ( 8 )
@@ -136,7 +145,7 @@ def run
136
145
cracker_instance = cracker . dup
137
146
cracker_instance . format = format
138
147
139
- if action . name == 'john'
148
+ if newaction == 'john'
140
149
cracker_instance . fork = datastore [ 'FORK' ]
141
150
end
142
151
@@ -147,7 +156,7 @@ def run
147
156
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
148
157
next if job [ 'cred_ids_left_to_crack' ] . empty?
149
158
150
- if action . name == 'john'
159
+ if newaction == 'john'
151
160
print_status "Cracking #{ format } hashes in single mode..."
152
161
cracker_instance . mode_single ( wordlist . path )
153
162
show_command cracker_instance
@@ -189,7 +198,7 @@ def run
189
198
print_status "Cracking #{ format } hashes in wordlist mode..."
190
199
cracker_instance . mode_wordlist ( wordlist . path )
191
200
# Turn on KoreLogic rules if the user asked for it
192
- if action . name == 'john' && datastore [ 'KORELOGIC' ]
201
+ if newaction == 'john' && datastore [ 'KORELOGIC' ]
193
202
cracker_instance . rules = 'KoreLogicRules'
194
203
print_status 'Applying KoreLogic ruleset...'
195
204
end
@@ -213,4 +222,24 @@ def run
213
222
end
214
223
end
215
224
end
225
+
226
+ def getaction
227
+ newaction = action . name
228
+ if action . name == 'auto'
229
+ path = Rex ::FileUtils . find_full_path ( 'hashcat' ) ||
230
+ Rex ::FileUtils . find_full_path ( 'hashcat.exe' )
231
+ if path
232
+ newaction = 'hashcat'
233
+ else
234
+ path = Rex ::FileUtils . find_full_path ( 'john' ) ||
235
+ Rex ::FileUtils . find_full_path ( 'john.exe' )
236
+ if path
237
+ newaction = 'john'
238
+ else
239
+ raise PasswordCrackerNotFoundError , 'No suitable john/hashcat binary was found on the system'
240
+ end
241
+ end
242
+ end
243
+ return newaction
244
+ end
216
245
end
0 commit comments