PostgreSQL Server Generic Query - Metasploit


This page contains detailed information about how to use the auxiliary/admin/postgres/postgres_sql metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: PostgreSQL Server Generic Query
Module: auxiliary/admin/postgres/postgres_sql
Source code: modules/auxiliary/admin/postgres/postgres_sql.rb
Disclosure date: -
Last modification time: 2017-08-24 21:38:44 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: postgres
Target network port(s): 5432
List of CVEs: -

This module will allow for simple SQL statements to be executed against a PostgreSQL instance given the appropriate credentials.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


msf > use auxiliary/admin/postgres/postgres_sql
msf auxiliary(postgres_sql) > show targets
    ... a list of targets ...
msf auxiliary(postgres_sql) > set TARGET target-id
msf auxiliary(postgres_sql) > show options
    ... show and set options ...
msf auxiliary(postgres_sql) > exploit

Required Options


  • RHOSTS: The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'

Go back to menu.

Msfconsole Usage


Here is how the admin/postgres/postgres_sql auxiliary module looks in the msfconsole:

msf6 > use auxiliary/admin/postgres/postgres_sql

msf6 auxiliary(admin/postgres/postgres_sql) > show info

       Name: PostgreSQL Server Generic Query
     Module: auxiliary/admin/postgres/postgres_sql
    License: Metasploit Framework License (BSD)
       Rank: Normal

Provided by:
  todb <[email protected]>

Check supported:
  No

Basic options:
  Name           Current Setting   Required  Description
  ----           ---------------   --------  -----------
  DATABASE       template1         yes       The database to authenticate against
  PASSWORD       postgres          no        The password for the specified username. Leave blank for a random password.
  RETURN_ROWSET  true              no        Set to true to see query result sets
  RHOSTS                           yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  RPORT          5432              yes       The target port
  SQL            select version()  no        The SQL query to execute
  USERNAME       postgres          yes       The username to authenticate as
  VERBOSE        false             no        Enable verbose output

Description:
  This module will allow for simple SQL statements to be executed 
  against a PostgreSQL instance given the appropriate credentials.

References:
  www.postgresql.org

Module Options


This is a complete list of options available in the admin/postgres/postgres_sql auxiliary module:

msf6 auxiliary(admin/postgres/postgres_sql) > show options

Module options (auxiliary/admin/postgres/postgres_sql):

   Name           Current Setting   Required  Description
   ----           ---------------   --------  -----------
   DATABASE       template1         yes       The database to authenticate against
   PASSWORD       postgres          no        The password for the specified username. Leave blank for a random password.
   RETURN_ROWSET  true              no        Set to true to see query result sets
   RHOSTS                           yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT          5432              yes       The target port
   SQL            select version()  no        The SQL query to execute
   USERNAME       postgres          yes       The username to authenticate as
   VERBOSE        false             no        Enable verbose output

Advanced Options


Here is a complete list of advanced options supported by the admin/postgres/postgres_sql auxiliary module:

msf6 auxiliary(admin/postgres/postgres_sql) > show advanced

Module advanced options (auxiliary/admin/postgres/postgres_sql):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   WORKSPACE                   no        Specify the workspace for this module

Auxiliary Actions


This is a list of all auxiliary actions that the admin/postgres/postgres_sql module can do:

msf6 auxiliary(admin/postgres/postgres_sql) > show actions

Auxiliary actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the admin/postgres/postgres_sql auxiliary module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 auxiliary(admin/postgres/postgres_sql) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

<RHOST>:<RPORT> Postgres - Authentication failure, could not connect.


Here is a relevant code snippet related to the "<RHOST>:<RPORT> Postgres - Authentication failure, could not connect." error message:

43:	
44:	  def run
45:	    ret = postgres_query(datastore['SQL'],datastore['RETURN_ROWSET'])
46:	    case ret.keys[0]
47:	    when :conn_error
48:	      print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."
49:	    when :sql_error
50:	      print_error "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
51:	    when :complete
52:	      vprint_good  "#{rhost}:#{rport} Postgres - Command complete."
53:	    end

<RHOST>:<RPORT> Postgres - <RET:SQL_ERROR>


Here is a relevant code snippet related to the "<RHOST>:<RPORT> Postgres - <RET:SQL_ERROR>" error message:

45:	    ret = postgres_query(datastore['SQL'],datastore['RETURN_ROWSET'])
46:	    case ret.keys[0]
47:	    when :conn_error
48:	      print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."
49:	    when :sql_error
50:	      print_error "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
51:	    when :complete
52:	      vprint_good  "#{rhost}:#{rport} Postgres - Command complete."
53:	    end
54:	    postgres_logout if self.postgres_conn
55:	  end

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • todb

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.