Skip to content

Commit 6d7a066

Browse files
David MaloneyDavid Maloney
authored andcommitted
fixes oracle_hashdump and jtr_oracle_fast modules
fixes functionality in the oracle database hashdumper and the oracle hash cracker modules
1 parent 2ee6df6 commit 6d7a066

File tree

2 files changed

+65
-74
lines changed

2 files changed

+65
-74
lines changed

modules/auxiliary/analyze/jtr_oracle_fast.rb

Lines changed: 64 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -28,86 +28,77 @@ def initialize
2828
end
2929

3030
def run
31-
@wordlist = Rex::Quickfile.new("jtrtmp")
31+
cracker = new_john_cracker
32+
33+
# generate our wordlist and close the file handle
34+
wordlist = wordlist_file
35+
wordlist.close
36+
print_status "Wordlist file written out to #{wordlist.path}"
37+
cracker.wordlist = wordlist.path
38+
#cracker.hash_path = hash_file("des")
39+
40+
['oracle', 'oracle11'].each do |format|
41+
cracker_instance = cracker.dup
42+
cracker_instance.format = format
43+
44+
case format
45+
when 'oracle'
46+
cracker_instance.hash_path = hash_file('des')
47+
when 'oracle11'
48+
cracker_instance.hash_path = hash_file('raw-sha1')
49+
end
3250

33-
@wordlist.write( build_seed().flatten.uniq.join("\n") + "\n" )
34-
@wordlist.close
35-
crack("oracle")
36-
crack("oracle11g")
37-
end
51+
print_status "Cracking #{format} hashes in normal wordlist mode..."
52+
# Turn on KoreLogic rules if the user asked for it
53+
if datastore['KoreLogic']
54+
cracker_instance.rules = 'KoreLogicRules'
55+
print_status "Applying KoreLogic ruleset..."
56+
end
57+
print_status "Crack command #{cracker_instance.crack_command.join(' ')}"
58+
cracker_instance.crack do |line|
59+
print_status line.chomp
60+
end
61+
62+
print_status "Cracking #{format} hashes in single mode..."
63+
cracker_instance.rules = 'single'
64+
cracker_instance.crack do |line|
65+
print_status line.chomp
66+
end
67+
68+
print_status "Cracked passwords this run:"
69+
cracker_instance.each_cracked_password do |password_line|
70+
password_line.chomp!
71+
next if password_line.blank?
72+
fields = password_line.split(":")
73+
# If we don't have an expected minimum number of fields, this is probably not a hash line
74+
next unless fields.count >=3
75+
username = fields.shift
76+
core_id = fields.pop
77+
password = fields.join(':') # Anything left must be the password. This accounts for passwords with : in them
78+
79+
# Postgres hashes always prepend the username to the password before hashing. So we strip the username back off here.
80+
password.gsub!(/^#{username}/,'')
81+
print_good "#{username}:#{password}:#{core_id}"
82+
create_cracked_credential( username: username, password: password, core_id: core_id)
83+
end
84+
end
3885

39-
def report_cred(opts)
40-
service_data = {
41-
address: opts[:ip],
42-
port: opts[:port],
43-
service_name: opts[:service_name],
44-
protocol: 'tcp',
45-
workspace_id: myworkspace_id
46-
}
47-
48-
credential_data = {
49-
origin_type: :service,
50-
module_fullname: fullname,
51-
username: opts[:user],
52-
private_data: opts[:password],
53-
private_type: :nonreplayable_hash,
54-
jtr_format: opts[:format]
55-
}.merge(service_data)
56-
57-
login_data = {
58-
core: create_credential(credential_data),
59-
status: Metasploit::Model::Login::Status::UNTRIED,
60-
proof: opts[:proof]
61-
}.merge(service_data)
62-
63-
create_credential_login(login_data)
6486
end
6587

6688

67-
def crack(format)
68-
69-
hashlist = Rex::Quickfile.new("jtrtmp")
70-
ltype= "#{format}.hashes"
71-
myloots = myworkspace.loots.where('ltype=?', ltype)
72-
unless myloots.nil? or myloots.empty?
73-
myloots.each do |myloot|
74-
begin
75-
oracle_array = CSV.read(myloot.path).drop(1)
76-
rescue Exception => e
77-
print_error("Unable to read #{myloot.path} \n #{e}")
78-
end
79-
oracle_array.each do |row|
80-
hashlist.write("#{row[0]}:#{row[1]}:#{myloot.host.address}:#{myloot.service.port}\n")
81-
end
82-
end
83-
hashlist.close
84-
85-
print_status("HashList: #{hashlist.path}")
86-
print_status("Trying Wordlist: #{@wordlist.path}")
87-
john_crack(hashlist.path, :wordlist => @wordlist.path, :rules => 'single', :format => format)
88-
89-
print_status("Trying Rule: All4...")
90-
john_crack(hashlist.path, :incremental => "All4", :format => format)
91-
92-
print_status("Trying Rule: Digits5...")
93-
john_crack(hashlist.path, :incremental => "Digits5", :format => format)
94-
95-
cracked = john_show_passwords(hashlist.path, format)
96-
97-
print_status("#{cracked[:cracked]} hashes were cracked!")
98-
cracked[:users].each_pair do |k,v|
99-
print_good("Host: #{v[1]} Port: #{v[2]} User: #{k} Pass: #{v[0]}")
100-
report_cred(
101-
ip: v[1],
102-
port: v[2],
103-
service_name: 'oracle',
104-
user: k,
105-
pass: v[0],
106-
format: format,
107-
proof: cracked.inspect
108-
)
89+
def hash_file(format)
90+
hashlist = Rex::Quickfile.new("hashes_tmp")
91+
Metasploit::Credential::NonreplayableHash.joins(:cores).where(metasploit_credential_cores: { workspace_id: myworkspace.id }, jtr_format: format).each do |hash|
92+
hash.cores.each do |core|
93+
user = core.public.username
94+
hash_string = "#{hash.data.split(':')[1]}"
95+
id = core.id
96+
hashlist.puts "#{user}:#{hash_string}:#{id}:"
10997
end
11098
end
99+
hashlist.close
100+
print_status "Hashes Written out to #{hashlist.path}"
101+
hashlist.path
111102
end
112103

113104
end

modules/auxiliary/scanner/oracle/oracle_hashdump.rb

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

0 commit comments

Comments
 (0)