From 689355e47f2aea29f41a5d0a01e2dc5da4729d21 Mon Sep 17 00:00:00 2001 From: Green-m Date: Tue, 25 Dec 2018 17:39:50 +0800 Subject: [PATCH] Support multiple rhosts for auxiliary modules. --- .../console/command_dispatcher/auxiliary.rb | 49 +++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/lib/msf/ui/console/command_dispatcher/auxiliary.rb b/lib/msf/ui/console/command_dispatcher/auxiliary.rb index b2549c9484..4697357f2a 100644 --- a/lib/msf/ui/console/command_dispatcher/auxiliary.rb +++ b/lib/msf/ui/console/command_dispatcher/auxiliary.rb @@ -60,8 +60,29 @@ class Auxiliary end # - # Tab completion for the run command + # Reloads an auxiliary module and executes it # + + # Launches an auxiliary module for single attempt. + # + def run_single(mod, opts) + begin + mod.run_simple( + 'Action' => action, + 'OptionStr' => opts.join(','), + 'LocalInput' => driver.input, + 'LocalOutput' => driver.output, + 'RunAsJob' => jobify, + 'Quiet' => quiet + ) + rescue + raise $! + end + end + + + # + # Tab completion for the run command def cmd_run_tabs(str, words) return [] if words.length > 1 @@auxiliary_opts.fmt.keys @@ -105,15 +126,25 @@ class Auxiliary jobify = true end + rhosts_range = Rex::Socket::RangeWalker.new(mod.datastore['RHOSTS']) + unless rhosts_range && rhosts_range.length + print_error("Auxiliary failed: option RHOSTS failed to validate.") + return false + end + begin - mod.run_simple( - 'Action' => action, - 'OptionStr' => opts.join(','), - 'LocalInput' => driver.input, - 'LocalOutput' => driver.output, - 'RunAsJob' => jobify, - 'Quiet' => quiet - ) + # Check whether run a scanner module. + if mod.class.included_modules.include?(Msf::Auxiliary::Scanner) + run_single(mod, opts) + # For multi target attempts. + else + rhosts_range.each do |rhost| + nmod = mod.replicant + nmod.datastore['RHOST'] = rhost + vprint_status("Running module against #{rhost}") + run_single(nmod, opts) + end + end rescue ::Timeout::Error print_error("Auxiliary triggered a timeout exception") print_error("Call stack:")