2010-02-02 01:40:48 +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-02 01:40:48 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2010-02-02 01:40:48 +00:00
|
|
|
include Msf::Exploit::Remote::Postgres
|
2024-02-12 11:52:48 +00:00
|
|
|
include Msf::OptionalSession::PostgreSQL
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2010-02-02 01:40:48 +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-02 01:40:48 +00:00
|
|
|
This module will allow for simple SQL statements to be executed against a
|
2017-08-24 21:38:44 -04:00
|
|
|
PostgreSQL instance given the appropriate credentials.
|
2025-05-21 08:32:40 +10:00
|
|
|
},
|
|
|
|
|
'Author' => [ 'todb' ],
|
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
|
'References' => [
|
2024-03-05 17:49:13 +00:00
|
|
|
[ 'URL', 'https://www.postgresql.org' ]
|
2025-05-21 08:32:40 +10:00
|
|
|
],
|
|
|
|
|
'Notes' => {
|
|
|
|
|
'Stability' => [CRASH_SAFE],
|
|
|
|
|
'SideEffects' => [IOC_IN_LOGS],
|
|
|
|
|
'Reliability' => []
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
2010-02-02 21:02:12 +00:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2012-06-18 23:59:57 -06:00
|
|
|
def auxiliary_commands
|
2025-05-21 08:32:40 +10:00
|
|
|
{ 'select' => 'Run a select query (a LIMIT clause is probably a really good idea)' }
|
2012-06-18 23:59:57 -06:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2012-06-18 23:59:57 -06:00
|
|
|
def cmd_select(*args)
|
2025-05-21 08:32:40 +10:00
|
|
|
datastore['SQL'] = "select #{args.join(' ')}"
|
2012-06-18 23:59:57 -06:00
|
|
|
run
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2010-02-02 21:02:12 +00:00
|
|
|
def rhost
|
|
|
|
|
datastore['RHOST']
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2010-02-02 21:02:12 +00:00
|
|
|
def rport
|
|
|
|
|
datastore['RPORT']
|
2010-02-02 01:40:48 +00:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2010-02-02 01:40:48 +00:00
|
|
|
def run
|
2024-01-24 13:47:22 +00:00
|
|
|
self.postgres_conn = session.client if session
|
2025-05-21 08:32:40 +10:00
|
|
|
ret = postgres_query(datastore['SQL'], datastore['RETURN_ROWSET'])
|
2010-02-08 16:43:44 +00:00
|
|
|
case ret.keys[0]
|
|
|
|
|
when :conn_error
|
|
|
|
|
print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."
|
|
|
|
|
when :sql_error
|
2024-02-19 10:57:53 +00:00
|
|
|
print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"
|
2010-02-08 16:43:44 +00:00
|
|
|
when :complete
|
2024-02-19 10:57:53 +00:00
|
|
|
vprint_good "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Command complete."
|
2010-02-08 16:43:44 +00:00
|
|
|
end
|
2025-05-21 08:32:40 +10:00
|
|
|
postgres_logout if postgres_conn && session.blank?
|
2010-02-02 01:40:48 +00:00
|
|
|
end
|
|
|
|
|
end
|