Path: blob/master/modules/auxiliary/admin/mssql/mssql_sql_file.rb
19664 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'English'6class MetasploitModule < Msf::Auxiliary7include Msf::Exploit::Remote::MSSQL8include Msf::OptionalSession::MSSQL910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Microsoft SQL Server Generic Query from File',15'Description' => %q{16This module will allow for multiple SQL queries contained within a specified17file to be executed against a Microsoft SQL (MSSQL) Server instance, given18the appropriate credentials.19},20'Author' => [ 'j0hn__f : <jf[at]tinternet.org.uk>' ],21'License' => MSF_LICENSE,22'Notes' => {23'Stability' => [CRASH_SAFE],24'SideEffects' => [IOC_IN_LOGS],25'Reliability' => []26}27)28)2930register_options(31[32OptPath.new('SQL_FILE', [ true, 'File containing multiple SQL queries execute (one per line)']),33OptString.new('QUERY_PREFIX', [ false, 'string to append each line of the file', '']),34OptString.new('QUERY_SUFFIX', [ false, 'string to prepend each line of the file', ''])35]36)37end3839def run40queries = File.readlines(datastore['SQL_FILE'])4142prefix = datastore['QUERY_PREFIX']43suffix = datastore['QUERY_SUFFIX']4445if session46set_mssql_session(session.client)47else48unless mssql_login_datastore49print_error("#{datastore['RHOST']}:#{datastore['RPORT']} - Invalid SQL Server credentials")50return51end52end53queries.each do |sql_query|54vprint_status("Executing: #{sql_query}")55mssql_query(prefix + sql_query.chomp + suffix, true)56end57rescue Rex::ConnectionRefused, Rex::ConnectionTimeout58print_error "Error connecting to server: #{$ERROR_INFO}"59ensure60disconnect unless session61end62end636465