Path: blob/master/lib/metasploit/framework/login_scanner.rb
19778 views
require 'metasploit/framework/credential'12module Metasploit3module Framework4# This module provides the namespace for all LoginScanner classes.5# LoginScanners are the classes that provide functionality for testing6# authentication against various different protocols and mechanisms.7module LoginScanner8require 'metasploit/framework/login_scanner/result'9require 'metasploit/framework/login_scanner/invalid'1011# Gather a list of LoginScanner classes that can potentially be12# used for a given `service`, which should usually be an13# `Mdm::Service` object, but can be anything that responds to14# #name and #port.15#16# @param service [Mdm::Service,#port,#name]17# @return [Array<LoginScanner::Base>] A collection of LoginScanner18# classes that will probably give useful results when run19# against `service`.20def self.classes_for_service(service)21require_login_scanners2223self.constants.map{|sym| const_get(sym)}.select do |const|24next unless const.kind_of?(Class)2526(27const.const_defined?(:LIKELY_PORTS) &&28const.const_get(:LIKELY_PORTS).include?(service.port)29) || (30const.const_defined?(:LIKELY_SERVICE_NAMES) &&31const.const_get(:LIKELY_SERVICE_NAMES).include?(service.name)32)33end34end3536# Gather a list of LoginScanner classes that can potentially be37# used against an HTTP service38#39# @return [Array<LoginScanner::Base>] A collection of LoginScanner40# classes that will probably give useful results when run41# against an HTTP service42def self.all_http_classes43require_login_scanners4445http_base_class = Metasploit::Framework::LoginScanner::HTTP46Metasploit::Framework::LoginScanner.constants.sort.filter_map do |sym|47const = Metasploit::Framework::LoginScanner.const_get(sym)48next unless const.kind_of?(Class) && const.ancestors.include?(http_base_class) && const != http_base_class4950const51end52end5354def self.all_service_names55require_login_scanners5657service_names = Set.new58self.constants.map{|sym| const_get(sym)}.select do |const|59next unless const.kind_of?(Class)60next unless const.const_defined?(:LIKELY_SERVICE_NAMES)6162const.const_get(:LIKELY_SERVICE_NAMES).each do |service_name|63service_names << service_name64end65end6667service_names68end6970private7172def self.require_login_scanners73unless @required74# Make sure we've required all the scanner classes75dir = File.expand_path("../login_scanner/", __FILE__)76Dir.glob(File.join(dir, "*.rb")).each do |f|77require f if File.file?(f)78end79@required = true80end81end82end83end84end858687