Files
metasploit-gs/modules/auxiliary/admin/mssql/mssql_sql_file.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.8 KiB
Ruby
Raw Normal View History

2012-06-25 15:07:17 +01:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2012-06-25 15:07:17 +01:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Auxiliary
2012-06-25 15:07:17 +01:00
include Msf::Exploit::Remote::MSSQL
include Msf::OptionalSession::MSSQL
2013-08-30 16:28:54 -05:00
2012-06-25 15:07:17 +01:00
def initialize(info = {})
super(update_info(info,
2012-08-04 11:05:38 -05:00
'Name' => 'Microsoft SQL Server Generic Query from File',
2012-06-25 15:07:17 +01:00
'Description' => %q{
2012-08-04 11:05:38 -05:00
This module will allow for multiple SQL queries contained within a specified
file to be executed against a Microsoft SQL (MSSQL) Server instance, given
2017-08-24 21:38:44 -04:00
the appropriate credentials.
2012-06-25 15:07:17 +01:00
},
2012-06-26 12:40:34 +01:00
'Author' => [ 'j0hn__f : <jf[at]tinternet.org.uk>' ],
'License' => MSF_LICENSE
2012-06-25 15:07:17 +01:00
))
2013-08-30 16:28:54 -05:00
2012-06-25 15:07:17 +01:00
register_options(
[
2012-07-17 08:39:56 -05:00
OptPath.new('SQL_FILE', [ true, "File containing multiple SQL queries execute (one per line)"]),
2012-06-25 15:07:17 +01:00
OptString.new('QUERY_PREFIX', [ false, "string to append each line of the file",""]),
OptString.new('QUERY_SUFFIX', [ false, "string to prepend each line of the file",""])
])
2012-06-25 15:07:17 +01:00
end
2013-08-30 16:28:54 -05:00
2012-06-25 15:07:17 +01:00
def run
queries = File.readlines(datastore['SQL_FILE'])
2013-08-30 16:28:54 -05:00
2012-06-25 15:07:17 +01:00
prefix = datastore['QUERY_PREFIX']
suffix = datastore['QUERY_SUFFIX']
2013-08-30 16:28:54 -05:00
2012-06-26 12:40:34 +01:00
begin
2024-02-12 15:47:49 -06:00
if session
set_session(session.client)
else
unless mssql_login_datastore
print_error("#{datastore['RHOST']}:#{datastore['RPORT']} - Invalid SQL Server credentials")
return
end
end
2012-06-26 12:40:34 +01:00
queries.each do |sql_query|
2012-07-17 08:39:56 -05:00
vprint_status("Executing: #{sql_query}")
2024-02-12 15:47:49 -06:00
mssql_query(prefix+sql_query.chomp+suffix,true)
2012-06-26 12:40:34 +01:00
end
rescue Rex::ConnectionRefused, Rex::ConnectionTimeout
print_error "Error connecting to server: #{$!}"
ensure
2024-02-12 15:47:49 -06:00
disconnect unless session
2012-06-25 15:07:17 +01:00
end
end
end