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/lib/msf/ui/console/command_dispatcher/auxiliary.rb
Views: 11784
# -*- coding: binary -*-1module Msf2module Ui3module Console4module CommandDispatcher56###7#8# Recon module command dispatcher.9#10###11class Auxiliary1213include Msf::Ui::Console::ModuleCommandDispatcher14include Msf::Ui::Console::ModuleActionCommands15include Msf::Ui::Console::ModuleOptionTabCompletion1617#18# Returns the hash of commands specific to auxiliary modules.19#20def commands21super.merge({22"run" => "Launches the auxiliary module",23"rcheck" => "Reloads the module and checks if the target is vulnerable",24"rerun" => "Reloads and launches the auxiliary module",25"exploit" => "This is an alias for the run command",26"recheck" => "This is an alias for the rcheck command",27"rexploit" => "This is an alias for the rerun command",28"reload" => "Reloads the auxiliary module"29}).merge( (mod ? mod.auxiliary_commands : {}) )30end3132#33#34# Returns the command dispatcher name.35#36def name37"Auxiliary"38end3940#41# Executes an auxiliary module42#43def cmd_run(*args, action: nil, opts: {})44if (args.include?('-r') || args.include?('--reload-libs')) && !opts[:previously_reloaded]45driver.run_single('reload_lib -a')46end4748return false unless (args = parse_run_opts(args, action: action))49jobify = args[:jobify]5051# Always run passive modules in the background52if mod.is_a?(Msf::Module::HasActions) &&53(mod.passive || mod.passive_action?(args[:action] || mod.default_action))54jobify = true55end5657mod_with_opts = mod.replicant58mod_with_opts.datastore.import_options_from_hash(args[:datastore_options])59rhosts = mod_with_opts.datastore['RHOSTS']60rhosts_walker = Msf::RhostsWalker.new(rhosts, mod_with_opts.datastore)6162begin63mod_with_opts.validate64rescue ::Msf::OptionValidateError => e65::Msf::Ui::Formatter::OptionValidateError.print_error(mod_with_opts, e)66return false67end6869begin70# Check if this is a scanner module or doesn't target remote hosts71if rhosts.blank? || mod.class.included_modules.include?(Msf::Auxiliary::Scanner)72mod_with_opts.run_simple(73'Action' => args[:action],74'LocalInput' => driver.input,75'LocalOutput' => driver.output,76'RunAsJob' => jobify,77'Quiet' => args[:quiet]78)79# For multi target attempts with non-scanner modules.80else81rhosts_walker.each do |datastore|82mod_with_opts = mod.replicant83mod_with_opts.datastore.merge!(datastore)84print_status("Running module against #{datastore['RHOSTS']}")85mod_with_opts.run_simple(86'Action' => args[:action],87'LocalInput' => driver.input,88'LocalOutput' => driver.output,89'RunAsJob' => false,90'Quiet' => args[:quiet]91)92end93end94rescue ::Timeout::Error95print_error("Auxiliary triggered a timeout exception")96print_error("Call stack:")97e.backtrace.each do |line|98break if line =~ /lib.msf.base.simple/99print_error(" #{line}")100end101rescue ::Interrupt102print_error("Auxiliary interrupted by the console user")103rescue ::Msf::OptionValidateError => e104::Msf::Ui::Formatter::OptionValidateError.print_error(running_mod, e)105rescue ::Exception => e106print_error("Auxiliary failed: #{e.class} #{e}")107if(e.class.to_s != 'Msf::OptionValidateError')108print_error("Call stack:")109e.backtrace.each do |line|110break if line =~ /lib.msf.base.simple/111print_error(" #{line}")112end113end114115return false116end117118if (jobify && mod_with_opts.job_id)119print_status("Auxiliary module running as background job #{mod_with_opts.job_id}.")120else121print_status("Auxiliary module execution completed")122end123end124125alias cmd_exploit cmd_run126alias cmd_exploit_tabs cmd_run_tabs127128def cmd_run_help129print_module_run_or_check_usage(command: :run, options: @@module_opts)130end131132alias cmd_exploit_help cmd_run_help133134#135# Reloads an auxiliary module and executes it136#137def cmd_rerun(*args)138opts = {}139if args.include?('-r') || args.include?('--reload-libs')140driver.run_single('reload_lib -a')141opts[:previously_reloaded] = true142end143144if reload(true)145cmd_run(*args, opts: opts)146end147end148149alias cmd_rerun_tabs cmd_run_tabs150alias cmd_rexploit cmd_rerun151alias cmd_rexploit_tabs cmd_exploit_tabs152153#154# Reloads an auxiliary module and checks the target to see if it's155# vulnerable.156#157def cmd_rcheck(*args)158opts = {}159if args.include?('-r') || args.include?('--reload-libs')160driver.run_single('reload_lib -a')161opts[:previously_reloaded] = true162end163164reload()165166cmd_check(*args, opts: opts)167end168169alias cmd_recheck cmd_rcheck170171end172173end end end end174175176177