Skip to content

Commit 06c17a6

Browse files
authored
Update crack_webapps.rb
1 parent d88c4bd commit 06c17a6

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

modules/auxiliary/analyze/crack_webapps.rb

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ def initialize
2424
'Actions' => [
2525
['john', { 'Description' => 'Use John the Ripper' }],
2626
['hashcat', { 'Description' => 'Use Hashcat' }],
27+
['auto', { 'Description' => 'Use either John the Ripper or Hashcat, if both are present, use Hashcat' }]
2728
],
28-
'DefaultAction' => 'john',
29+
'DefaultAction' => 'auto',
2930
'Notes' => {
3031
'Stability' => [CRASH_SAFE],
3132
'SideEffects' => [],
@@ -48,29 +49,34 @@ def initialize
4849
def show_command(cracker_instance)
4950
return unless datastore['ShowCommand']
5051

51-
if action.name == 'john'
52+
newaction = getaction()
53+
54+
if newaction == 'john'
5255
cmd = cracker_instance.john_crack_command
53-
elsif action.name == 'hashcat'
56+
elsif newaction == 'hashcat'
5457
cmd = cracker_instance.hashcat_crack_command
5558
end
5659
print_status(" Cracking Command: #{cmd.join(' ')}")
5760
end
5861

5962
def check_results(passwords, results, hash_type, method)
63+
64+
newaction = getaction()
65+
6066
passwords.each do |password_line|
6167
password_line.chomp!
6268
next if password_line.blank?
6369

6470
fields = password_line.split(':')
6571
cred = { 'hash_type' => hash_type, 'method' => method }
6672
# 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'
6874
next unless fields.count >= 3
6975

7076
cred['username'] = fields.shift
7177
cred['core_id'] = fields.pop
7278
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'
7480
next unless fields.count >= 2
7581

7682
cred['core_id'] = fields.shift
@@ -89,6 +95,9 @@ def check_results(passwords, results, hash_type, method)
8995
end
9096

9197
def run
98+
99+
newaction = getaction()
100+
92101
tbl = tbl = cracker_results_table
93102

94103
hash_types_to_crack = []
@@ -100,7 +109,7 @@ def run
100109

101110
# build our job list
102111
hash_types_to_crack.each do |hash_type|
103-
job = hash_job(hash_type, action.name)
112+
job = hash_job(hash_type, newaction)
104113
if job.nil?
105114
print_status("No #{hash_type} found to crack")
106115
else
@@ -118,7 +127,7 @@ def run
118127
# Inner array format: db_id, hash_type, username, password, method_of_crack
119128
results = []
120129

121-
cracker = new_password_cracker(action.name)
130+
cracker = new_password_cracker(newaction)
122131

123132
# generate our wordlist and close the file handle.
124133
wordlist = wordlist_file
@@ -142,7 +151,7 @@ def run
142151
# dupe our original cracker so we can safely change options between each run
143152
cracker_instance = cracker.dup
144153
cracker_instance.format = format
145-
if action.name == 'john'
154+
if newaction == 'john'
146155
cracker_instance.fork = datastore['FORK']
147156
end
148157

@@ -153,7 +162,7 @@ def run
153162
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
154163
next if job['cred_ids_left_to_crack'].empty?
155164

156-
if action.name == 'john'
165+
if newaction == 'john'
157166
print_status "Cracking #{format} hashes in single mode..."
158167
cracker_instance.mode_single(wordlist.path)
159168
show_command cracker_instance
@@ -194,7 +203,7 @@ def run
194203
print_status "Cracking #{format} hashes in wordlist mode..."
195204
cracker_instance.mode_wordlist(wordlist.path)
196205
# Turn on KoreLogic rules if the user asked for it
197-
if action.name == 'john' && datastore['KORELOGIC']
206+
if newaction == 'john' && datastore['KORELOGIC']
198207
cracker_instance.rules = 'KoreLogicRules'
199208
print_status 'Applying KoreLogic ruleset...'
200209
end
@@ -218,4 +227,25 @@ def run
218227
end
219228
end
220229
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+
221251
end

0 commit comments

Comments
 (0)