Path: blob/master/lib/msf/core/auxiliary.rb
19851 views
# -*- coding: binary -*-12module Msf34###5#6# The auxiliary class acts as a base class for all modules that perform7# reconnaissance, retrieve data, brute force logins, or any other action8# that doesn't fit our concept of an 'exploit' (involving payloads and9# targets and whatnot).10#11###12class Auxiliary < Msf::Module1314class Complete < RuntimeError15end1617class Failed < RuntimeError18end192021include HasActions2223#24# Returns MODULE_AUX to indicate that this is an auxiliary module.25#26def self.type27Msf::MODULE_AUX28end2930#31# Returns MODULE_AUX to indicate that this is an auxiliary module.32#33def type34Msf::MODULE_AUX35end3637#38# Creates an instance of the auxiliary module.39#40def initialize(info = {})4142# Call the parent constructor after making any necessary modifications43# to the information hash.44super(info)4546self.sockets = Array.new47self.queue = Array.new48self.fail_reason = Msf::Module::Failure::None49end5051#52# Creates a singleton instance of this auxiliary class53#54def self.create(info = {})55return @@aux_singleton if @@aux_singleton56@@aux_singleton = self.new(info)57end5859def run60print_status("Running the default Auxiliary handler")61end6263def auxiliary_commands64return { }65end6667#68# Performs last-minute sanity checking of auxiliary parameters. This method69# is called during automated exploitation attempts and allows an70# auxiliary module to filter bad attempts, obtain more information, and choose71# better parameters based on the available data. Returning anything that72# evaluates to "false" will cause this specific auxiliary attempt to73# be skipped. This method can and will change datastore values and74# may interact with the backend database. The default value for auxiliary75# modules is false, since not all auxiliary modules actually attempt76# to exploit a vulnerability.77#78def autofilter79false80end8182#83# Provides a list of ports that can be used for matching this module84# against target systems.85#86def autofilter_ports87@autofilter_ports || []88end8990#91# Provides a list of services that can be used for matching this module92# against target systems.93#94def autofilter_services95@autofilter_services || []96end9798#99# Adds a port into the list of ports100#101def register_autofilter_ports(ports=[])102@autofilter_ports ||= []103@autofilter_ports << ports104@autofilter_ports.flatten!105@autofilter_ports.uniq!106end107108def register_autofilter_services(services=[])109@autofilter_services ||= []110@autofilter_services << services111@autofilter_services.flatten!112@autofilter_services.uniq!113end114115116#117# Called directly before 'run'118#119def setup120alert_user121end122123#124# Called after 'run' returns125#126def cleanup127abort_sockets()128end129130#131# Adds a socket to the list of sockets opened by this exploit.132#133def add_socket(sock)134self.sockets << sock135end136137#138# Removes a socket from the list of sockets.139#140def remove_socket(sock)141self.sockets.delete(sock)142end143144#145# This method is called once a new session has been created on behalf of146# this module instance and all socket connections created by this147# module should be closed.148#149def abort_sockets150sockets.delete_if { |sock|151152begin153sock.close154rescue ::Exception155end156true157}158end159160# Override Msf::Module#fail_with for Msf::Simple::Auxiliary::job_run_proc161def fail_with(reason, msg = nil)162allowed_values = Msf::Module::Failure.constants.collect {|e| Msf::Module::Failure.const_get(e)}163if allowed_values.include?(reason)164self.fail_reason = reason165else166self.fail_reason = Msf::Module::Failure::Unknown167end168169self.fail_detail = msg170raise Msf::Auxiliary::Failed, "#{reason.to_s}: #{(msg || "No failure message given")}"171end172173#174# The reason why the module was not successful (one of the constant defined above)175#176attr_accessor :fail_reason177178#179# Detailed exception string indicating why the module was not successful180#181attr_accessor :fail_detail182183attr_accessor :queue184185protected186187attr_accessor :sockets188attr_writer :passive189190end191192end193194195196