Allow for things external to a scanner module to come in an kill all the threads with the mod.seppuko!() method.
git-svn-id: file:///home/svn/framework3/trunk@11117 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
7581ce0153
commit
fb79d97bca
|
@ -44,7 +44,7 @@ def run
|
||||||
@range_percent = 0
|
@range_percent = 0
|
||||||
|
|
||||||
threads_max = datastore['THREADS'].to_i
|
threads_max = datastore['THREADS'].to_i
|
||||||
tl = []
|
@tl = []
|
||||||
|
|
||||||
#
|
#
|
||||||
# Sanity check threading on different platforms
|
# Sanity check threading on different platforms
|
||||||
|
@ -75,15 +75,15 @@ def run
|
||||||
|
|
||||||
if (self.respond_to?('run_host'))
|
if (self.respond_to?('run_host'))
|
||||||
|
|
||||||
tl = []
|
@tl = []
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
# Spawn threads for each host
|
# Spawn threads for each host
|
||||||
while (tl.length < threads_max)
|
while (@tl.length < threads_max)
|
||||||
ip = ar.next_ip
|
ip = ar.next_ip
|
||||||
break if not ip
|
break if not ip
|
||||||
|
|
||||||
tl << framework.threads.spawn("ScannerHost(#{self.refname})-#{ip}", false, ip.dup) do |tip|
|
@tl << framework.threads.spawn("ScannerHost(#{self.refname})-#{ip}", false, ip.dup) do |tip|
|
||||||
targ = tip
|
targ = tip
|
||||||
nmod = self.replicant
|
nmod = self.replicant
|
||||||
nmod.datastore['RHOST'] = targ
|
nmod.datastore['RHOST'] = targ
|
||||||
|
@ -103,7 +103,7 @@ def run
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exit once we run out of hosts
|
# Exit once we run out of hosts
|
||||||
if(tl.length == 0)
|
if(@tl.length == 0)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -112,10 +112,10 @@ def run
|
||||||
# done, remove any finished threads from the list
|
# done, remove any finished threads from the list
|
||||||
# and continue on. This will open up at least one
|
# and continue on. This will open up at least one
|
||||||
# spot for a new thread
|
# spot for a new thread
|
||||||
tla = tl.length
|
tla = @tl.length
|
||||||
tl.first.join
|
@tl.first.join
|
||||||
tl.delete_if { |t| not t.alive? }
|
@tl.delete_if { |t| not t.alive? }
|
||||||
tlb = tl.length
|
tlb = @tl.length
|
||||||
|
|
||||||
@range_done += tla - tlb
|
@range_done += tla - tlb
|
||||||
scanner_show_progress()
|
scanner_show_progress()
|
||||||
|
@ -135,11 +135,11 @@ def run
|
||||||
|
|
||||||
ar = Rex::Socket::RangeWalker.new(datastore['RHOSTS'])
|
ar = Rex::Socket::RangeWalker.new(datastore['RHOSTS'])
|
||||||
|
|
||||||
tl = []
|
@tl = []
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
nohosts = false
|
nohosts = false
|
||||||
while (tl.length < threads_max)
|
while (@tl.length < threads_max)
|
||||||
|
|
||||||
batch = []
|
batch = []
|
||||||
|
|
||||||
|
@ -170,17 +170,17 @@ def run
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
thread[:batch_size] = batch.length
|
thread[:batch_size] = batch.length
|
||||||
tl << thread
|
@tl << thread
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exit once we run out of hosts
|
# Exit once we run out of hosts
|
||||||
if (tl.length == 0 or nohosts)
|
if (@tl.length == 0 or nohosts)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Exit if there are no more pending threads
|
# Exit if there are no more pending threads
|
||||||
if (tl.length == 0)
|
if (@tl.length == 0)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -190,11 +190,11 @@ def run
|
||||||
# and continue on. This will open up at least one
|
# and continue on. This will open up at least one
|
||||||
# spot for a new thread
|
# spot for a new thread
|
||||||
tla = 0
|
tla = 0
|
||||||
tl.map {|t| tla += t[:batch_size] }
|
@tl.map {|t| tla += t[:batch_size] }
|
||||||
tl.first.join
|
@tl.first.join
|
||||||
tl.delete_if { |t| not t.alive? }
|
@tl.delete_if { |t| not t.alive? }
|
||||||
tlb = 0
|
tlb = 0
|
||||||
tl.map {|t| tlb += t[:batch_size] }
|
@tl.map {|t| tlb += t[:batch_size] }
|
||||||
|
|
||||||
@range_done += tla - tlb
|
@range_done += tla - tlb
|
||||||
scanner_show_progress()
|
scanner_show_progress()
|
||||||
|
@ -209,12 +209,16 @@ def run
|
||||||
print_status("Caught interrupt from the console...")
|
print_status("Caught interrupt from the console...")
|
||||||
return
|
return
|
||||||
ensure
|
ensure
|
||||||
tl.each do |t|
|
seppuko!()
|
||||||
begin
|
|
||||||
t.kill
|
|
||||||
rescue ::Exception
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def seppuko!
|
||||||
|
@tl.each do |t|
|
||||||
|
begin
|
||||||
|
t.kill if t.alive?
|
||||||
|
rescue ::Exception
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue