Skip to content

Commit 5a548c3

Browse files
committed
Land rapid7#5453, Update dbvis_enum to use the new cred API
2 parents 2587595 + 7485cf7 commit 5a548c3

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

modules/post/multi/gather/dbvis_enum.rb

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def parse_new_config_file(raw_xml)
149149
db[:Namespace] = "";
150150
end
151151
# save
152-
dbs << db if (db[:Alias] and db[:Type] and db[:Server] and db[:Port] )
152+
dbs << db if (db[:Alias] and db[:Type] and db[:Server] and db[:Port])
153153
db = {}
154154
end
155155

@@ -205,6 +205,13 @@ def parse_new_config_file(raw_xml)
205205
end
206206

207207
db_table << [ db[:Alias], db[:Type], db[:Server], db[:Port], db[:Database], db[:Namespace], db[:UserID], db[:Password] ]
208+
report_cred(
209+
ip: db[:Server],
210+
port: db[:Port].to_i,
211+
service_name: db[:Type],
212+
username: db[:UserID],
213+
password: db[:Password]
214+
)
208215
end
209216
return db_table
210217
end
@@ -278,12 +285,20 @@ def parse_old_config_file(raw_xml)
278285
# Fill the tab
279286
dbs.each do |db|
280287
if (db[:URL] =~ /[\S+\s+]+[\/]+([\S+\s+]+):[\S+]+/i)
281-
if ::Rex::Socket.is_ipv4?($1.to_s)
282-
print_good("Reporting #{$1}")
283-
report_host(:host => $1.to_s)
288+
server = $1
289+
if ::Rex::Socket.is_ipv4?(server)
290+
print_good("Reporting #{server}")
291+
report_host(:host => server)
284292
end
285293
end
286294
db_table << [ db[:Alias] , db[:Type] , db[:URL], db[:UserID], db[:Password] ]
295+
report_cred(
296+
ip: server,
297+
port: '',
298+
service_name: db[:Type],
299+
username: db[:UserID],
300+
password: db[:Password]
301+
)
287302
end
288303
return db_table
289304
end
@@ -297,6 +312,32 @@ def find_version(tag)
297312
found
298313
end
299314

315+
def report_cred(opts)
316+
service_data = {
317+
address: opts[:ip],
318+
port: opts[:port],
319+
service_name: opts[:service_name],
320+
protocol: 'tcp',
321+
workspace_id: myworkspace_id
322+
}
323+
324+
credential_data = {
325+
post_reference_name: self.refname,
326+
session_id: session_db_id,
327+
origin_type: :session,
328+
private_data: opts[:password],
329+
private_type: :password,
330+
username: opts[:username]
331+
}.merge(service_data)
332+
333+
login_data = {
334+
core: create_credential(credential_data),
335+
status: Metasploit::Model::Login::Status::UNTRIED,
336+
}.merge(service_data)
337+
338+
create_credential_login(login_data)
339+
end
340+
300341
def decrypt_password(enc_password)
301342
enc_password = Rex::Text.decode_base64(enc_password)
302343
dk, iv = get_derived_key

0 commit comments

Comments
 (0)