Path: blob/master/BlueKeep/cve_2019_0708_bluekeep_rce/rdp_scanner.rb
1306 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::RDP7include Msf::Auxiliary::Scanner8include Msf::Auxiliary::Report910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Identify endpoints speaking the Remote Desktop Protocol (RDP)',15'Description' => %q(16This module attempts to connect to the specified Remote Desktop Protocol port17and determines if it speaks RDP.1819When available, the Credential Security Support Provider (CredSSP) protocol will be used to identify the20version of Windows on which the server is running. Enabling the DETECT_NLA option will cause a second21connection to be made to the server to identify if Network Level Authentication (NLA) is required.22),23'Author' => 'Jon Hart <jon_hart[at]rapid7.com>',24'References' =>25[26['URL', 'https://msdn.microsoft.com/en-us/library/cc240445.aspx']27],28'License' => MSF_LICENSE29)30)3132register_options(33[34Opt::RPORT(3389),35OptBool.new('DETECT_NLA', [true, 'Detect Network Level Authentication (NLA)', true])36]37)38end3940def check_rdp41begin42rdp_connect43is_rdp, version_info = rdp_fingerprint44rescue ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError45return false, nil46ensure47rdp_disconnect48end4950service_info = nil51if is_rdp52product_version = (version_info && version_info[:product_version]) ? version_info[:product_version] : 'N/A'53info = "Detected RDP on #{peer} (Windows version: #{product_version})"5455if datastore['DETECT_NLA']56service_info = "Requires NLA: #{(!version_info[:product_version].nil? && requires_nla?) ? 'Yes' : 'No'}"57info << " (#{service_info})"58end5960print_status(info)61end6263return is_rdp, service_info64end6566def requires_nla?67begin68rdp_connect69is_rdp, server_selected_proto = rdp_check_protocol70rescue ::Errno::ETIMEDOUT, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, ::Timeout::Error, ::EOFError71return false72ensure73rdp_disconnect74end7576return false unless is_rdp77return [RDPConstants::PROTOCOL_HYBRID, RDPConstants::PROTOCOL_HYBRID_EX].include? server_selected_proto78end7980def run_host(_ip)81is_rdp = false82begin83rdp_connect84is_rdp, service_info = check_rdp85rescue Rex::ConnectionError => e86vprint_error("Error while connecting and negotiating RDP: #{e}")87return88ensure89rdp_disconnect90end91return unless is_rdp9293report_service(94host: rhost,95port: rport,96proto: 'tcp',97name: 'RDP',98info: service_info99)100end101end102103104105