CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/mssql/mssql_sql_file.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Auxiliary
7
include Msf::Exploit::Remote::MSSQL
8
include Msf::OptionalSession::MSSQL
9
10
def initialize(info = {})
11
super(update_info(info,
12
'Name' => 'Microsoft SQL Server Generic Query from File',
13
'Description' => %q{
14
This module will allow for multiple SQL queries contained within a specified
15
file to be executed against a Microsoft SQL (MSSQL) Server instance, given
16
the appropriate credentials.
17
},
18
'Author' => [ 'j0hn__f : <jf[at]tinternet.org.uk>' ],
19
'License' => MSF_LICENSE
20
))
21
22
register_options(
23
[
24
OptPath.new('SQL_FILE', [ true, "File containing multiple SQL queries execute (one per line)"]),
25
OptString.new('QUERY_PREFIX', [ false, "string to append each line of the file",""]),
26
OptString.new('QUERY_SUFFIX', [ false, "string to prepend each line of the file",""])
27
])
28
end
29
30
31
def run
32
queries = File.readlines(datastore['SQL_FILE'])
33
34
prefix = datastore['QUERY_PREFIX']
35
suffix = datastore['QUERY_SUFFIX']
36
37
begin
38
if session
39
set_mssql_session(session.client)
40
else
41
unless mssql_login_datastore
42
print_error("#{datastore['RHOST']}:#{datastore['RPORT']} - Invalid SQL Server credentials")
43
return
44
end
45
end
46
queries.each do |sql_query|
47
vprint_status("Executing: #{sql_query}")
48
mssql_query(prefix+sql_query.chomp+suffix,true)
49
end
50
rescue Rex::ConnectionRefused, Rex::ConnectionTimeout
51
print_error "Error connecting to server: #{$!}"
52
ensure
53
disconnect unless session
54
end
55
end
56
end
57
58