Path: blob/master/modules/auxiliary/admin/postgres/postgres_sql.rb
19850 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Postgres7include Msf::OptionalSession::PostgreSQL89def initialize(info = {})10super(11update_info(12info,13'Name' => 'PostgreSQL Server Generic Query',14'Description' => %q{15This module will allow for simple SQL statements to be executed against a16PostgreSQL instance given the appropriate credentials.17},18'Author' => [ 'todb' ],19'License' => MSF_LICENSE,20'References' => [21[ 'URL', 'https://www.postgresql.org' ]22],23'Notes' => {24'Stability' => [CRASH_SAFE],25'SideEffects' => [IOC_IN_LOGS],26'Reliability' => []27}28)29)30end3132def auxiliary_commands33{ 'select' => 'Run a select query (a LIMIT clause is probably a really good idea)' }34end3536def cmd_select(*args)37datastore['SQL'] = "select #{args.join(' ')}"38run39end4041def rhost42datastore['RHOST']43end4445def rport46datastore['RPORT']47end4849def run50self.postgres_conn = session.client if session51ret = postgres_query(datastore['SQL'], datastore['RETURN_ROWSET'])52case ret.keys[0]53when :conn_error54print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."55when :sql_error56print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"57when :complete58vprint_good "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Command complete."59end60postgres_logout if postgres_conn && session.blank?61end62end636465