PostgreSQL Server Generic Query - Metasploit


This page contains detailed information about how to use the auxiliary/admin/postgres/postgres_readfile 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_readfile
Source code: modules/auxiliary/admin/postgres/postgres_readfile.rb
Disclosure date: -
Last modification time: 2017-07-24 06:26:21 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: postgres
Target network port(s): 5432
List of CVEs: -

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.

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_readfile
msf auxiliary(postgres_readfile) > show targets
    ... a list of targets ...
msf auxiliary(postgres_readfile) > set TARGET target-id
msf auxiliary(postgres_readfile) > show options
    ... show and set options ...
msf auxiliary(postgres_readfile) > 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_readfile auxiliary module looks in the msfconsole:

msf6 > use auxiliary/admin/postgres/postgres_readfile

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

       Name: PostgreSQL Server Generic Query
     Module: auxiliary/admin/postgres/postgres_readfile
    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.
  RFILE     /etc/passwd      yes       The remote file
  RHOSTS                     yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  RPORT     5432             yes       The target port
  USERNAME  postgres         yes       The username to authenticate as
  VERBOSE   false            no        Enable verbose output

Description:
  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.

Module Options


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

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

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

   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.
   RFILE     /etc/passwd      yes       The remote file
   RHOSTS                     yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT     5432             yes       The target port
   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_readfile auxiliary module:

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

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

   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_readfile module can do:

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

Auxiliary actions:

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

Evasion Options


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

msf6 auxiliary(admin/postgres/postgres_readfile) > 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:

38:	
39:	  def run
40:	    ret = postgres_read_textfile(datastore['RFILE'])
41:	    case ret.keys[0]
42:	    when :conn_error
43:	      print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."
44:	    when :sql_error
45:	      case ret[:sql_error]
46:	      when /^C58P01/
47:	        print_error "#{rhost}:#{rport} Postgres - No such file or directory."
48:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"

<RHOST>:<RPORT> Postgres - No such file or directory.


Here is a relevant code snippet related to the "<RHOST>:<RPORT> Postgres - No such file or directory." error message:

42:	    when :conn_error
43:	      print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."
44:	    when :sql_error
45:	      case ret[:sql_error]
46:	      when /^C58P01/
47:	        print_error "#{rhost}:#{rport} Postgres - No such file or directory."
48:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
49:	      when /^C42501/
50:	        print_error "#{rhost}:#{rport} Postgres - Insufficent file permissions."
51:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
52:	      else

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


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

43:	      print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."
44:	    when :sql_error
45:	      case ret[:sql_error]
46:	      when /^C58P01/
47:	        print_error "#{rhost}:#{rport} Postgres - No such file or directory."
48:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
49:	      when /^C42501/
50:	        print_error "#{rhost}:#{rport} Postgres - Insufficent file permissions."
51:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
52:	      else
53:	        print_error "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"

<RHOST>:<RPORT> Postgres - Insufficent file permissions.


Here is a relevant code snippet related to the "<RHOST>:<RPORT> Postgres - Insufficent file permissions." error message:

45:	      case ret[:sql_error]
46:	      when /^C58P01/
47:	        print_error "#{rhost}:#{rport} Postgres - No such file or directory."
48:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
49:	      when /^C42501/
50:	        print_error "#{rhost}:#{rport} Postgres - Insufficent file permissions."
51:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
52:	      else
53:	        print_error "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
54:	      end
55:	    when :complete

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


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

46:	      when /^C58P01/
47:	        print_error "#{rhost}:#{rport} Postgres - No such file or directory."
48:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
49:	      when /^C42501/
50:	        print_error "#{rhost}:#{rport} Postgres - Insufficent file permissions."
51:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
52:	      else
53:	        print_error "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
54:	      end
55:	    when :complete
56:	      loot = ''

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


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

48:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
49:	      when /^C42501/
50:	        print_error "#{rhost}:#{rport} Postgres - Insufficent file permissions."
51:	        vprint_status "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
52:	      else
53:	        print_error "#{rhost}:#{rport} Postgres - #{ret[:sql_error]}"
54:	      end
55:	    when :complete
56:	      loot = ''
57:	      ret[:complete].rows.each { |row|
58:	        print_line(row.first)

Go back to menu.


Go back to menu.

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.