Path: blob/master/modules/auxiliary/admin/mysql/mysql_sql.rb
19592 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::MYSQL7include Msf::OptionalSession::MySQL89def initialize(info = {})10super(11update_info(12info,13'Name' => 'MySQL SQL Generic Query',14'Description' => %q{15This module allows for simple SQL statements to be executed16against a MySQL instance given the appropriate credentials.17},18'Author' => [ 'Bernardo Damele A. G. <bernardo.damele[at]gmail.com>' ],19'License' => MSF_LICENSE,20'Notes' => {21'Stability' => [CRASH_SAFE],22'SideEffects' => [IOC_IN_LOGS],23'Reliability' => []24}25)26)2728register_options(29[30OptString.new('SQL', [ true, 'The SQL to execute.', 'select version()'])31]32)33end3435def auxiliary_commands36{ 'select' => 'Run a select query (a LIMIT clause is probably a really good idea)' }37end3839def cmd_select(*args)40datastore['SQL'] = "select #{args.join(' ')}"41run42end4344def run45# If we have a session make use of it46if session47print_status("Using existing session #{session.sid}")48self.mysql_conn = session.client49else50# otherwise fallback to attempting to login51return unless mysql_login_datastore52end5354print_status("Sending statement: '#{datastore['SQL']}'...")55res = mysql_query(datastore['SQL']) || []56res.each do |row|57print_status(" | #{row.join(' | ')} |")58end59end60end616263