Skip to content

Commit

Permalink
Make check_multiple() thread-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
wchen-r7 committed Jan 30, 2014
1 parent 6435ddd commit 9f669a8
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions lib/msf/ui/console/module_command_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,28 @@ def check_multiple(hosts)
break unless ip

@tl << framework.threads.spawn("CheckHost-#{ip}", false, ip.dup) { |tip|
mod.datastore['RHOST'] = tip
check_simple
# Make sure this is thread-safe when assigning an IP to the RHOST
# datastore option
instance = mod.replicant
instance.datastore['RHOST'] = tip.dup
framework.events.on_module_created(instance)
check_simple(instance)
}
end

break if @tl.length == 0

tla = @tl.length
@tl.first.join

# This exception handling is necessary, the first thread with errors can kill the
# whole check_multiple and leave the rest of the threads running in background and
# only accessible with the threads command (Thread.list)
begin
@tl.first.join
rescue ::Exception => exception
elog("#{exception} #{exception.class}:\n#{exception.backtrace.join("\n")}")
end

@tl.delete_if { |t| not t.alive? }
tlb = @tl.length

Expand Down Expand Up @@ -141,12 +154,16 @@ def cmd_check(*args)
end
end

def check_simple
rhost = mod.rhost
rport = mod.rport
def check_simple(instance=nil)
unless instance
instance = mod
end

rhost = instance.rhost
rport = instance.rport

begin
code = mod.check_simple(
code = instance.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output)
if (code and code.kind_of?(Array) and code.length > 1)
Expand Down

0 comments on commit 9f669a8

Please sign in to comment.