2009-01-12 05:18:05 +00: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
|
2009-01-12 05:18:05 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2009-01-12 05:18:05 +00:00
|
|
|
include Msf::Exploit::Remote::MSSQL
|
2024-02-14 12:15:23 +00:00
|
|
|
include Msf::OptionalSession::MSSQL
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2009-01-12 05:18:05 +00:00
|
|
|
def initialize(info = {})
|
2025-05-17 13:21:09 +10:00
|
|
|
super(
|
|
|
|
|
update_info(
|
|
|
|
|
info,
|
|
|
|
|
'Name' => 'Microsoft SQL Server Generic Query',
|
|
|
|
|
'Description' => %q{
|
2009-01-12 05:18:05 +00:00
|
|
|
This module will allow for simple SQL statements to be executed against a
|
2017-08-24 21:38:44 -04:00
|
|
|
MSSQL/MSDE instance given the appropriate credentials.
|
2025-05-17 13:21:09 +10:00
|
|
|
},
|
|
|
|
|
'Author' => [ 'tebo <tebo[at]attackresearch.com>' ],
|
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
|
'References' => [
|
2011-07-24 19:36:37 +00:00
|
|
|
[ 'URL', 'http://www.attackresearch.com' ],
|
2009-01-12 05:18:05 +00:00
|
|
|
[ 'URL', 'http://msdn.microsoft.com/en-us/library/cc448435(PROT.10).aspx'],
|
2025-05-17 13:21:09 +10:00
|
|
|
],
|
|
|
|
|
'Notes' => {
|
|
|
|
|
'Stability' => [CRASH_SAFE],
|
|
|
|
|
'SideEffects' => [IOC_IN_LOGS],
|
|
|
|
|
'Reliability' => []
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
)
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
register_options(
|
2009-10-13 22:24:47 +00:00
|
|
|
[
|
2025-05-17 13:21:09 +10:00
|
|
|
OptString.new('SQL', [ false, 'The SQL query to execute', 'select @@version']),
|
|
|
|
|
]
|
|
|
|
|
)
|
2009-01-12 05:18:05 +00:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2012-06-18 23:59:57 -06:00
|
|
|
def auxiliary_commands
|
2025-05-17 13:21:09 +10:00
|
|
|
{ 'select' => 'Run a select query (a LIMIT clause is probably a really good idea)' }
|
2012-06-18 23:59:57 -06:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2012-06-18 23:59:57 -06:00
|
|
|
def cmd_select(*args)
|
2025-05-17 13:21:09 +10:00
|
|
|
datastore['SQL'] = "select #{args.join(' ')}"
|
2012-06-18 23:59:57 -06:00
|
|
|
run
|
|
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2009-01-12 05:18:05 +00:00
|
|
|
def run
|
2024-02-12 15:47:49 -06:00
|
|
|
if session
|
2024-03-05 13:27:00 -06:00
|
|
|
set_mssql_session(session.client)
|
2024-02-12 15:47:49 -06:00
|
|
|
else
|
2024-03-27 09:54:38 -05:00
|
|
|
unless mssql_login_datastore
|
2025-05-17 13:21:09 +10:00
|
|
|
print_error('Error with mssql_login call')
|
|
|
|
|
info = mssql_client.initial_connection_info
|
2024-03-27 09:54:38 -05:00
|
|
|
if info[:errors] && !info[:errors].empty?
|
|
|
|
|
info[:errors].each do |err|
|
|
|
|
|
print_error(err)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return
|
|
|
|
|
end
|
2024-01-29 17:17:29 -05:00
|
|
|
end
|
|
|
|
|
|
2024-02-12 15:47:49 -06:00
|
|
|
mssql_query(datastore['SQL'], true)
|
2009-01-12 05:18:05 +00:00
|
|
|
end
|
|
|
|
|
end
|