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_sql.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::OptionalSession::PostgreSQL89def initialize(info = {})10super(update_info(info,11'Name' => 'PostgreSQL Server Generic Query',12'Description' => %q{13This module will allow for simple SQL statements to be executed against a14PostgreSQL instance given the appropriate credentials.15},16'Author' => [ 'todb' ],17'License' => MSF_LICENSE,18'References' =>19[20[ 'URL', 'https://www.postgresql.org' ]21]22))23end2425def auxiliary_commands26{ "select" => "Run a select query (a LIMIT clause is probably a really good idea)" }27end2829def cmd_select(*args)30datastore["SQL"] = "select #{args.join(" ")}"31run32end3334def rhost35datastore['RHOST']36end3738def rport39datastore['RPORT']40end4142def run43self.postgres_conn = session.client if session44ret = postgres_query(datastore['SQL'],datastore['RETURN_ROWSET'])45case ret.keys[0]46when :conn_error47print_error "#{rhost}:#{rport} Postgres - Authentication failure, could not connect."48when :sql_error49print_error "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - #{ret[:sql_error]}"50when :complete51vprint_good "#{postgres_conn.peerhost}:#{postgres_conn.peerport} Postgres - Command complete."52end53postgres_logout if self.postgres_conn && session.blank?54end55end565758