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/mysql/mysql_sql.rb
Views: 11783
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::MYSQL
8
include Msf::OptionalSession::MySQL
9
10
def initialize(info = {})
11
super(update_info(info,
12
'Name' => 'MySQL SQL Generic Query',
13
'Description' => %q{
14
This module allows for simple SQL statements to be executed
15
against a MySQL instance given the appropriate credentials.
16
},
17
'Author' => [ 'Bernardo Damele A. G. <bernardo.damele[at]gmail.com>' ],
18
'License' => MSF_LICENSE,
19
))
20
21
register_options(
22
[
23
OptString.new('SQL', [ true, 'The SQL to execute.', 'select version()'])
24
])
25
end
26
27
def auxiliary_commands
28
{ "select" => "Run a select query (a LIMIT clause is probably a really good idea)" }
29
end
30
31
def cmd_select(*args)
32
datastore["SQL"] = "select #{args.join(" ")}"
33
run
34
end
35
36
def run
37
# If we have a session make use of it
38
if session
39
print_status("Using existing session #{session.sid}")
40
self.mysql_conn = session.client
41
else
42
# otherwise fallback to attempting to login
43
return unless mysql_login_datastore
44
end
45
46
print_status("Sending statement: '#{datastore['SQL']}'...")
47
res = mysql_query(datastore['SQL']) || []
48
res.each do |row|
49
print_status(" | #{row.join(" | ")} |")
50
end
51
end
52
end
53
54