2007-02-18 00:10:39 +00:00
|
|
|
##
|
2008-10-02 05:23:59 +00:00
|
|
|
# $Id$
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-02-18 00:10:39 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
|
2006-08-13 18:03:49 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Auxiliary
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::MSSQL
|
|
|
|
include Msf::Auxiliary::Scanner
|
2010-02-12 16:53:46 +00:00
|
|
|
include Msf::Auxiliary::Report
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2006-08-13 18:03:49 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'MSSQL Ping Utility',
|
2007-02-18 00:10:39 +00:00
|
|
|
'Version' => '$Revision$',
|
2006-08-13 18:03:49 +00:00
|
|
|
'Description' => 'This module simply queries the MSSQL instance for information.',
|
|
|
|
'Author' => 'MC',
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2006-08-13 18:03:49 +00:00
|
|
|
deregister_options('RPORT', 'RHOST')
|
|
|
|
end
|
|
|
|
|
2010-02-12 16:53:46 +00:00
|
|
|
def rport
|
|
|
|
datastore['RPORT']
|
|
|
|
end
|
2006-08-13 18:03:49 +00:00
|
|
|
|
|
|
|
def run_host(ip)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2006-08-13 18:03:49 +00:00
|
|
|
begin
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2006-08-13 18:03:49 +00:00
|
|
|
info = mssql_ping(2)
|
|
|
|
if (info['ServerName'])
|
|
|
|
print_status("SQL Server information for #{ip}:")
|
|
|
|
info.each_pair { |k,v|
|
|
|
|
print_status(" #{k + (" " * (15-k.length))} = #{v}")
|
|
|
|
}
|
2010-02-12 16:53:46 +00:00
|
|
|
if info['tcp']
|
|
|
|
report_mssql_service(ip,info)
|
|
|
|
end
|
|
|
|
|
2006-08-13 18:03:49 +00:00
|
|
|
end
|
2010-02-12 16:53:46 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2008-11-11 05:12:52 +00:00
|
|
|
rescue ::Rex::ConnectionError
|
2006-08-13 18:03:49 +00:00
|
|
|
end
|
|
|
|
end
|
2010-02-12 16:53:46 +00:00
|
|
|
|
|
|
|
def test_connection(ip,port)
|
|
|
|
begin
|
|
|
|
sock = Rex::Socket::Tcp.create(
|
|
|
|
'PeerHost' => ip,
|
|
|
|
'PeerPort' => port
|
|
|
|
)
|
|
|
|
rescue Rex::ConnectionError
|
|
|
|
return :down
|
|
|
|
end
|
|
|
|
sock.close
|
|
|
|
return :up
|
|
|
|
end
|
|
|
|
|
|
|
|
def report_mssql_service(ip,info)
|
|
|
|
mssql_info = "Version: %s, ServerName: %s, InstanceName: %s, Clustered: %s" % [
|
|
|
|
info['Version'],
|
|
|
|
info['ServerName'],
|
|
|
|
info['InstanceName'],
|
|
|
|
info['IsClustered']
|
|
|
|
]
|
|
|
|
report_service(
|
|
|
|
:host => ip,
|
|
|
|
:port => 1434,
|
2010-02-12 19:53:18 +00:00
|
|
|
:name => "mssql-m",
|
2010-02-12 16:53:46 +00:00
|
|
|
:proto => "udp",
|
|
|
|
:info => "TCP: #{info['tcp']}, Servername: #{info['ServerName']}"
|
|
|
|
)
|
|
|
|
mssql_tcp_state = (test_connection(ip,info['tcp']) == :up ? "open" : "closed")
|
|
|
|
report_service(
|
|
|
|
:host => ip,
|
|
|
|
:port => info['tcp'],
|
2010-02-12 19:53:18 +00:00
|
|
|
:name => "mssql",
|
2010-02-12 16:53:46 +00:00
|
|
|
:info => mssql_info,
|
|
|
|
:state => mssql_tcp_state
|
2010-04-30 08:40:19 +00:00
|
|
|
)
|
2010-02-12 16:53:46 +00:00
|
|
|
|
|
|
|
end
|
2008-11-11 05:12:52 +00:00
|
|
|
end
|