Skip to content

Commit 56f138c

Browse files
authored
Fix issue #20396
1 parent 7450d72 commit 56f138c

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

modules/auxiliary/analyze/crack_aix.rb

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ def initialize
2525
'Actions' => [
2626
['john', { 'Description' => 'Use John the Ripper' }],
2727
['hashcat', { 'Description' => 'Use Hashcat' }],
28+
['auto', { 'Description' => 'Use either John the Ripper or Hashcat, if both are present, use Hashcat' }]
2829
],
29-
'DefaultAction' => 'john',
30+
'DefaultAction' => 'auto',
3031
'Notes' => {
3132
'Stability' => [CRASH_SAFE],
3233
'SideEffects' => [],
@@ -44,16 +45,21 @@ def initialize
4445

4546
def show_command(cracker_instance)
4647
return unless datastore['ShowCommand']
48+
49+
newaction = getaction()
4750

48-
if action.name == 'john'
51+
if newaction == 'john'
4952
cmd = cracker_instance.john_crack_command
50-
elsif action.name == 'hashcat'
53+
elsif newaction == 'hashcat'
5154
cmd = cracker_instance.hashcat_crack_command
5255
end
5356
print_status(" Cracking Command: #{cmd.join(' ')}")
5457
end
5558

5659
def check_results(passwords, results, hash_type, method)
60+
61+
newaction = getaction()
62+
5763
passwords.each do |password_line|
5864
password_line.chomp!
5965
next if password_line.blank?
@@ -63,12 +69,12 @@ def check_results(passwords, results, hash_type, method)
6369
next unless fields.count >= 3
6470

6571
cred = { 'hash_type' => hash_type, 'method' => method }
66-
if action.name == 'john'
72+
if newaction == 'john'
6773
cred['username'] = fields.shift
6874
cred['core_id'] = fields.pop
6975
4.times { fields.pop } # Get rid of extra :
7076
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'
7278
cred['core_id'] = fields.shift
7379
cred['hash'] = fields.shift
7480
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)
8591
end
8692

8793
def run
94+
95+
newaction = getaction()
96+
8897
tbl = tbl = cracker_results_table
8998

9099
hash_types_to_crack = ['descrypt']
91100
jobs_to_do = []
92101

93102
# build our job list
94103
hash_types_to_crack.each do |hash_type|
95-
job = hash_job(hash_type, action.name)
104+
job = hash_job(hash_type, newaction)
96105
if job.nil?
97106
print_status("No #{hash_type} found to crack")
98107
else
@@ -110,7 +119,7 @@ def run
110119
# Inner array format: db_id, hash_type, username, password, method_of_crack
111120
results = []
112121

113-
cracker = new_password_cracker(action.name)
122+
cracker = new_password_cracker(newaction)
114123

115124
# generate our wordlist and close the file handle. max length of DES is 8
116125
wordlist = wordlist_file(8)
@@ -136,7 +145,7 @@ def run
136145
cracker_instance = cracker.dup
137146
cracker_instance.format = format
138147

139-
if action.name == 'john'
148+
if newaction == 'john'
140149
cracker_instance.fork = datastore['FORK']
141150
end
142151

@@ -147,7 +156,7 @@ def run
147156
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
148157
next if job['cred_ids_left_to_crack'].empty?
149158

150-
if action.name == 'john'
159+
if newaction == 'john'
151160
print_status "Cracking #{format} hashes in single mode..."
152161
cracker_instance.mode_single(wordlist.path)
153162
show_command cracker_instance
@@ -189,7 +198,7 @@ def run
189198
print_status "Cracking #{format} hashes in wordlist mode..."
190199
cracker_instance.mode_wordlist(wordlist.path)
191200
# Turn on KoreLogic rules if the user asked for it
192-
if action.name == 'john' && datastore['KORELOGIC']
201+
if newaction == 'john' && datastore['KORELOGIC']
193202
cracker_instance.rules = 'KoreLogicRules'
194203
print_status 'Applying KoreLogic ruleset...'
195204
end
@@ -213,4 +222,24 @@ def run
213222
end
214223
end
215224
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
216245
end

0 commit comments

Comments
 (0)