Skip to content

Commit e3265c4

Browse files
author
Brent Cook
committed
Land rapid7#8697, fix oracle_hashdump and jtr_oracle_fast modules
2 parents 69c4ae9 + 6d7a066 commit e3265c4

File tree

2 files changed

+63
-72
lines changed

2 files changed

+63
-72
lines changed

modules/auxiliary/analyze/jtr_oracle_fast.rb

Lines changed: 62 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -26,85 +26,76 @@ def initialize
2626
end
2727

2828
def run
29-
@wordlist = Rex::Quickfile.new("jtrtmp")
30-
31-
@wordlist.write( build_seed().flatten.uniq.join("\n") + "\n" )
32-
@wordlist.close
33-
crack("oracle")
34-
crack("oracle11g")
35-
end
36-
37-
def report_cred(opts)
38-
service_data = {
39-
address: opts[:ip],
40-
port: opts[:port],
41-
service_name: opts[:service_name],
42-
protocol: 'tcp',
43-
workspace_id: myworkspace_id
44-
}
45-
46-
credential_data = {
47-
origin_type: :service,
48-
module_fullname: fullname,
49-
username: opts[:user],
50-
private_data: opts[:password],
51-
private_type: :nonreplayable_hash,
52-
jtr_format: opts[:format]
53-
}.merge(service_data)
54-
55-
login_data = {
56-
core: create_credential(credential_data),
57-
status: Metasploit::Model::Login::Status::UNTRIED,
58-
proof: opts[:proof]
59-
}.merge(service_data)
60-
61-
create_credential_login(login_data)
62-
end
63-
64-
65-
def crack(format)
29+
cracker = new_john_cracker
30+
31+
# generate our wordlist and close the file handle
32+
wordlist = wordlist_file
33+
wordlist.close
34+
print_status "Wordlist file written out to #{wordlist.path}"
35+
cracker.wordlist = wordlist.path
36+
#cracker.hash_path = hash_file("des")
37+
38+
['oracle', 'oracle11'].each do |format|
39+
cracker_instance = cracker.dup
40+
cracker_instance.format = format
41+
42+
case format
43+
when 'oracle'
44+
cracker_instance.hash_path = hash_file('des')
45+
when 'oracle11'
46+
cracker_instance.hash_path = hash_file('raw-sha1')
47+
end
6648

67-
hashlist = Rex::Quickfile.new("jtrtmp")
68-
ltype= "#{format}.hashes"
69-
myloots = myworkspace.loots.where('ltype=?', ltype)
70-
unless myloots.nil? or myloots.empty?
71-
myloots.each do |myloot|
72-
begin
73-
oracle_array = CSV.read(myloot.path).drop(1)
74-
rescue Exception => e
75-
print_error("Unable to read #{myloot.path} \n #{e}")
76-
end
77-
oracle_array.each do |row|
78-
hashlist.write("#{row[0]}:#{row[1]}:#{myloot.host.address}:#{myloot.service.port}\n")
79-
end
49+
print_status "Cracking #{format} hashes in normal wordlist mode..."
50+
# Turn on KoreLogic rules if the user asked for it
51+
if datastore['KoreLogic']
52+
cracker_instance.rules = 'KoreLogicRules'
53+
print_status "Applying KoreLogic ruleset..."
54+
end
55+
print_status "Crack command #{cracker_instance.crack_command.join(' ')}"
56+
cracker_instance.crack do |line|
57+
print_status line.chomp
8058
end
81-
hashlist.close
8259

83-
print_status("HashList: #{hashlist.path}")
84-
print_status("Trying Wordlist: #{@wordlist.path}")
85-
john_crack(hashlist.path, :wordlist => @wordlist.path, :rules => 'single', :format => format)
60+
print_status "Cracking #{format} hashes in single mode..."
61+
cracker_instance.rules = 'single'
62+
cracker_instance.crack do |line|
63+
print_status line.chomp
64+
end
8665

87-
print_status("Trying Rule: All4...")
88-
john_crack(hashlist.path, :incremental => "All4", :format => format)
66+
print_status "Cracked passwords this run:"
67+
cracker_instance.each_cracked_password do |password_line|
68+
password_line.chomp!
69+
next if password_line.blank?
70+
fields = password_line.split(":")
71+
# If we don't have an expected minimum number of fields, this is probably not a hash line
72+
next unless fields.count >=3
73+
username = fields.shift
74+
core_id = fields.pop
75+
password = fields.join(':') # Anything left must be the password. This accounts for passwords with : in them
76+
77+
# Postgres hashes always prepend the username to the password before hashing. So we strip the username back off here.
78+
password.gsub!(/^#{username}/,'')
79+
print_good "#{username}:#{password}:#{core_id}"
80+
create_cracked_credential( username: username, password: password, core_id: core_id)
81+
end
82+
end
8983

90-
print_status("Trying Rule: Digits5...")
91-
john_crack(hashlist.path, :incremental => "Digits5", :format => format)
84+
end
9285

93-
cracked = john_show_passwords(hashlist.path, format)
9486

95-
print_status("#{cracked[:cracked]} hashes were cracked!")
96-
cracked[:users].each_pair do |k,v|
97-
print_good("Host: #{v[1]} Port: #{v[2]} User: #{k} Pass: #{v[0]}")
98-
report_cred(
99-
ip: v[1],
100-
port: v[2],
101-
service_name: 'oracle',
102-
user: k,
103-
pass: v[0],
104-
format: format,
105-
proof: cracked.inspect
106-
)
87+
def hash_file(format)
88+
hashlist = Rex::Quickfile.new("hashes_tmp")
89+
Metasploit::Credential::NonreplayableHash.joins(:cores).where(metasploit_credential_cores: { workspace_id: myworkspace.id }, jtr_format: format).each do |hash|
90+
hash.cores.each do |core|
91+
user = core.public.username
92+
hash_string = "#{hash.data.split(':')[1]}"
93+
id = core.id
94+
hashlist.puts "#{user}:#{hash_string}:#{id}:"
10795
end
10896
end
97+
hashlist.close
98+
print_status "Hashes Written out to #{hashlist.path}"
99+
hashlist.path
109100
end
110101
end

modules/auxiliary/scanner/oracle/oracle_hashdump.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def run_host(ip)
7777
unless results.empty?
7878
results.each do |result|
7979
row= result.split(/,/)
80-
row[2] = 'No'
80+
next unless row.length == 2
8181
tbl << row
8282
end
8383
end

0 commit comments

Comments
 (0)