Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/admin/mysql/mysql_sql.rb
19592 views
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(
12
update_info(
13
info,
14
'Name' => 'MySQL SQL Generic Query',
15
'Description' => %q{
16
This module allows for simple SQL statements to be executed
17
against a MySQL instance given the appropriate credentials.
18
},
19
'Author' => [ 'Bernardo Damele A. G. <bernardo.damele[at]gmail.com>' ],
20
'License' => MSF_LICENSE,
21
'Notes' => {
22
'Stability' => [CRASH_SAFE],
23
'SideEffects' => [IOC_IN_LOGS],
24
'Reliability' => []
25
}
26
)
27
)
28
29
register_options(
30
[
31
OptString.new('SQL', [ true, 'The SQL to execute.', 'select version()'])
32
]
33
)
34
end
35
36
def auxiliary_commands
37
{ 'select' => 'Run a select query (a LIMIT clause is probably a really good idea)' }
38
end
39
40
def cmd_select(*args)
41
datastore['SQL'] = "select #{args.join(' ')}"
42
run
43
end
44
45
def run
46
# If we have a session make use of it
47
if session
48
print_status("Using existing session #{session.sid}")
49
self.mysql_conn = session.client
50
else
51
# otherwise fallback to attempting to login
52
return unless mysql_login_datastore
53
end
54
55
print_status("Sending statement: '#{datastore['SQL']}'...")
56
res = mysql_query(datastore['SQL']) || []
57
res.each do |row|
58
print_status(" | #{row.join(' | ')} |")
59
end
60
end
61
end
62
63