Wrap Msf::Framework#threads in Metasploit::Framework::ThreadFactoryProvider
MSP-11605 `Rex::ThreadFactory.provider` needs to be set in `Msf::Framework#initialize`, but setting it directly to `Msf::Framework#threads` eliminates the laziness of `Msf::Framework#threads`. In order keep `framework.threads` lazy, `framework` is wrapped in a `Metasploit::Framework::ThreadFactoryProvider`, which responds to `spawn`, which is needed by `Rex::ThreadFactory`, by calling `framework.threads.spawn`, which lazily initialized `framework.threads` when the first thread needs to be spawned.bug/bundler_fix
parent
0bc27334c1
commit
d9a25005a6
|
@ -35,6 +35,7 @@ module Metasploit
|
|||
extend ActiveSupport::Autoload
|
||||
|
||||
autoload :Spec
|
||||
autoload :ThreadFactoryProvider
|
||||
|
||||
# Returns the root of the metasploit-framework project. Use in place of
|
||||
# `Rails.root`.
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
# Wraps {Msf::Framework} so that {Msf::Framework#threads} is only created on the first call to {#spawn} by
|
||||
# {Rex::ThreadFactory#spawn}, which allows the threads used by {Msf::ThreadManager} to be created lazily.
|
||||
#
|
||||
# @example Setting Rex::ThreadFactory.provider and spawning threads
|
||||
# Rex::ThreadFactory.provider = Metasploit::Framework::ThreadFactoryProvider.new(framework: framework)
|
||||
# # framework.threads created here
|
||||
# Rex::ThreadFactory.spawn("name", false) { ... }
|
||||
#
|
||||
class Metasploit::Framework::ThreadFactoryProvider < Metasploit::Model::Base
|
||||
#
|
||||
# Attributes
|
||||
#
|
||||
|
||||
# @!attribute framework
|
||||
# The framework managing the spawned threads.
|
||||
#
|
||||
# @return [Msf::Framework]
|
||||
attr_accessor :framework
|
||||
|
||||
# Spawns a thread monitored by {Msf::ThreadManager} in {Msf::Framework#threads}.
|
||||
#
|
||||
# (see Msf::ThreadManager#spawn)
|
||||
def spawn(name, critical, *args, &block)
|
||||
framework.threads.spawn(name, critical, *args, &block)
|
||||
end
|
||||
end
|
|
@ -93,7 +93,7 @@ class Framework
|
|||
self.plugins = PluginManager.new(self)
|
||||
|
||||
# Configure the thread factory
|
||||
Rex::ThreadFactory.provider = self.threads
|
||||
Rex::ThreadFactory.provider = Metasploit::Framework::ThreadFactoryProvider.new(framework: self)
|
||||
|
||||
subscriber = FrameworkEventSubscriber.new(self)
|
||||
events.add_exploit_subscriber(subscriber)
|
||||
|
|
Loading…
Reference in New Issue