Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/scanner/mssql/mssql_ping.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::MSSQL7include Msf::Auxiliary::Scanner8include Msf::Auxiliary::Report910def initialize11super(12'Name' => 'MSSQL Ping Utility',13'Description' => 'This module simply queries the MSSQL Browser service for server information.',14'Author' => 'MC',15'License' => MSF_LICENSE16)1718deregister_options('RPORT')19end2021def run_host(ip)2223begin2425info = mssql_ping(2)26#print_status info.inspect27if info and not info.empty?28info.each do |instance|29if (instance['ServerName'])30print_status("SQL Server information for #{ip}:")31instance.each_pair {|k,v| print_good(" #{k + (" " * (15-k.length))} = #{v}")}32if instance['tcp']33report_mssql_service(ip,instance)34end35end36end37end3839rescue ::Rex::ConnectionError40end41end4243def test_connection(ip,port)44begin45sock = Rex::Socket::Tcp.create(46'PeerHost' => ip,47'PeerPort' => port48)49rescue Rex::ConnectionError50return :down51end52sock.close53return :up54end5556def report_mssql_service(ip,info)57mssql_info = "Version: %s, ServerName: %s, InstanceName: %s, Clustered: %s" % [58info['Version'],59info['ServerName'],60info['InstanceName'],61info['IsClustered']62]63report_service(64:host => ip,65:port => 1434,66:name => "mssql-m",67:proto => "udp",68:info => "TCP: #{info['tcp']}, Servername: #{info['ServerName']}"69)70mssql_tcp_state = (test_connection(ip,info['tcp']) == :up ? "open" : "closed")71report_service(72:host => ip,73:port => info['tcp'],74:name => "mssql",75:info => mssql_info,76:state => mssql_tcp_state77)7879end80end818283