Skip to content

Commit 5aee8d5

Browse files
authored
Fix issue #20396
1 parent bd3ce5f commit 5aee8d5

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

modules/auxiliary/analyze/crack_linux.rb

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def initialize
3232
'Actions' => [
3333
['john', { 'Description' => 'Use John the Ripper' }],
3434
['hashcat', { 'Description' => 'Use Hashcat' }],
35+
['auto', { 'Description' => 'Use either John the Ripper or Hashcat, if both are present, use Hashcat' }]
3536
],
36-
'DefaultAction' => 'john',
37+
'DefaultAction' => 'auto',
3738
'Notes' => {
3839
'Stability' => [CRASH_SAFE],
3940
'SideEffects' => [],
@@ -58,30 +59,35 @@ def initialize
5859
def show_command(cracker_instance)
5960
return unless datastore['ShowCommand']
6061

61-
if action.name == 'john'
62+
newaction = getaction()
63+
64+
if newaction == 'john'
6265
cmd = cracker_instance.john_crack_command
63-
elsif action.name == 'hashcat'
66+
elsif newaction == 'hashcat'
6467
cmd = cracker_instance.hashcat_crack_command
6568
end
6669
print_status(" Cracking Command: #{cmd.join(' ')}")
6770
end
6871

6972
def check_results(passwords, results, hash_type, method)
73+
74+
newaction = getaction()
75+
7076
passwords.each do |password_line|
7177
password_line.chomp!
7278
next if password_line.blank?
7379

7480
fields = password_line.split(':')
7581
cred = { 'hash_type' => hash_type, 'method' => method }
7682

77-
if action.name == 'john'
83+
if newaction == 'john'
7884
next unless fields.count >= 3 # If we don't have an expected minimum number of fields, this is probably not a hash line
7985

8086
cred['username'] = fields.shift
8187
cred['core_id'] = fields.pop
8288
4.times { fields.pop } # Get rid of extra :
8389
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'
8591
next unless fields.count >= 2 # If we don't have an expected minimum number of fields, this is probably not a hash line
8692

8793
cred['core_id'] = fields.shift
@@ -100,6 +106,9 @@ def check_results(passwords, results, hash_type, method)
100106
end
101107

102108
def run
109+
110+
newaction = getaction()
111+
103112
tbl = tbl = cracker_results_table
104113

105114
# array of hashes in jtr_format in the db, converted to an OR combined regex
@@ -115,7 +124,7 @@ def run
115124

116125
# build our job list
117126
hash_types_to_crack.each do |hash_type|
118-
job = hash_job(hash_type, action.name)
127+
job = hash_job(hash_type, newaction)
119128
if job.nil?
120129
print_status("No #{hash_type} found to crack")
121130
else
@@ -133,7 +142,7 @@ def run
133142
# Inner array format: db_id, hash_type, username, password, method_of_crack
134143
results = []
135144

136-
cracker = new_password_cracker(action.name)
145+
cracker = new_password_cracker(newaction)
137146

138147
# generate our wordlist and close the file handle.
139148
wordlist = wordlist_file
@@ -158,7 +167,7 @@ def run
158167
cracker_instance = cracker.dup
159168
cracker_instance.format = format
160169

161-
if action.name == 'john'
170+
if newaction == 'john'
162171
cracker_instance.fork = datastore['FORK']
163172
end
164173

@@ -169,7 +178,7 @@ def run
169178
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
170179
next if job['cred_ids_left_to_crack'].empty?
171180

172-
if action.name == 'john'
181+
if newaction == 'john'
173182
print_status "Cracking #{format} hashes in single mode..."
174183
cracker_instance.mode_single(wordlist.path)
175184
show_command cracker_instance
@@ -211,7 +220,7 @@ def run
211220
print_status "Cracking #{format} hashes in wordlist mode..."
212221
cracker_instance.mode_wordlist(wordlist.path)
213222
# Turn on KoreLogic rules if the user asked for it
214-
if action.name == 'john' && datastore['KORELOGIC']
223+
if newaction == 'john' && datastore['KORELOGIC']
215224
cracker_instance.rules = 'KoreLogicRules'
216225
print_status 'Applying KoreLogic ruleset...'
217226
end
@@ -235,4 +244,24 @@ def run
235244
end
236245
end
237246
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
238267
end

0 commit comments

Comments
 (0)