CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/mssql/mssql_sql.rb
Views: 11784
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',
13
'Description' => %q{
14
This module will allow for simple SQL statements to be executed against a
15
MSSQL/MSDE instance given the appropriate credentials.
16
},
17
'Author' => [ 'tebo <tebo[at]attackresearch.com>' ],
18
'License' => MSF_LICENSE,
19
'References' =>
20
[
21
[ 'URL', 'http://www.attackresearch.com' ],
22
[ 'URL', 'http://msdn.microsoft.com/en-us/library/cc448435(PROT.10).aspx'],
23
]
24
))
25
26
register_options(
27
[
28
OptString.new('SQL', [ false, 'The SQL query to execute', 'select @@version']),
29
])
30
end
31
32
def auxiliary_commands
33
{ "select" => "Run a select query (a LIMIT clause is probably a really good idea)" }
34
end
35
36
def cmd_select(*args)
37
datastore["SQL"] = "select #{args.join(" ")}"
38
run
39
end
40
41
def run
42
if session
43
set_mssql_session(session.client)
44
else
45
unless mssql_login_datastore
46
print_error("Error with mssql_login call")
47
info = self.mssql_client.initial_connection_info
48
if info[:errors] && !info[:errors].empty?
49
info[:errors].each do |err|
50
print_error(err)
51
end
52
end
53
return
54
end
55
end
56
57
mssql_query(datastore['SQL'], true)
58
end
59
end
60
61