Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.7 KiB
Ruby
Raw Permalink Normal View History

##
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
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Auxiliary
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
def initialize(info = {})
super(
update_info(
info,
'Name' => 'PostgreSQL Server Generic Query',
'Description' => %q{
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.
},
'Author' => [ 'todb' ],
'License' => MSF_LICENSE,
'References' => [
2024-03-05 17:49:13 +00:00
[ 'URL', 'https://www.postgresql.org' ]
],
'Notes' => {
'Stability' => [CRASH_SAFE],
'SideEffects' => [IOC_IN_LOGS],
'Reliability' => []
}
)
)
end
2013-08-30 16:28:54 -05:00
def auxiliary_commands
{ 'select' => 'Run a select query (a LIMIT clause is probably a really good idea)' }
end
2013-08-30 16:28:54 -05:00
def cmd_select(*args)
datastore['SQL'] = "select #{args.join(' ')}"
run
end
2013-08-30 16:28:54 -05:00
def rhost
datastore['RHOST']
end
2013-08-30 16:28:54 -05:00
def rport
datastore['RPORT']
end
2013-08-30 16:28:54 -05:00
def run
2024-01-24 13:47:22 +00:00
self.postgres_conn = session.client if session
ret = postgres_query(datastore['SQL'], datastore['RETURN_ROWSET'])
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]}"
when :complete
2024-02-19 10:57:53 +00:00
vprint_good "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Command complete."
end
postgres_logout if postgres_conn && session.blank?
end
end