Skip to content

Commit

Permalink
This patch allows the framework to be created with only specific modu…
Browse files Browse the repository at this point in the history
…le types enabled, speeding up msfpayload and msfencode.

git-svn-id: file:///home/svn/framework3/trunk@6055 4d416f70-5f16-0410-b530-b9f4589650da
  • Loading branch information
HD Moore committed Jan 2, 2009
1 parent a0aa29b commit af1675b
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 36 deletions.
8 changes: 4 additions & 4 deletions lib/msf/base/simple/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def on_module_created(instance)
# instance is created.
#
def self.create(opts = {})
framework = Msf::Framework.new

framework = Msf::Framework.new(opts)
return simplify(framework, opts)
end

Expand All @@ -84,7 +83,7 @@ def self.simplify(framework, opts)

# Initialize the simplified framework
framework.init_simplified()

# Call the creation procedure if one was supplied
if (opts['OnCreateProc'])
opts['OnCreateProc'].call(framework)
Expand All @@ -94,6 +93,7 @@ def self.simplify(framework, opts)
Msf::Config.init
Msf::Logging.init


# Load the configuration
framework.load_config

Expand Down Expand Up @@ -178,4 +178,4 @@ def save_config
end

end
end
end
2 changes: 1 addition & 1 deletion lib/msf/core/event_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,4 @@ def remove_event_subscriber(array, subscriber) # :nodoc:

end

end
end
8 changes: 6 additions & 2 deletions lib/msf/core/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ module Offspring
#
# Creates an instance of the framework context.
#
def initialize()
def initialize(opts={})

# Allow specific module types to be loaded
types = opts[:module_types] || MODULE_TYPES

self.events = EventDispatcher.new(self)
self.modules = ModuleManager.new(self)
self.modules = ModuleManager.new(self,types)
self.sessions = SessionManager.new(self)
self.datastore = DataStore.new
self.jobs = Rex::JobContainer.new
Expand Down
70 changes: 43 additions & 27 deletions lib/msf/core/module_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,20 @@ class ModuleManager < ModuleSet

#
# Initializes an instance of the overall module manager using the supplied
# framework instance.
# framework instance. The types parameter can be used to only load specific
# module types on initialization
#
def initialize(framework)
def initialize(framework,types=MODULE_TYPES)
self.module_paths = []
self.module_history = {}
self.module_history_mtime = {}
self.module_sets = {}
self.module_failed = {}
self.enabled_types = {}
self.framework = framework

MODULE_TYPES.each { |type|
types.each { |type|
self.enabled_types[type] = true
case type
when MODULE_PAYLOAD
instance = PayloadSet.new(self)
Expand Down Expand Up @@ -444,7 +447,9 @@ def set_module_cache_file(file_path)
@modcache.add_group(type, false)

@modcache[type].each_key { |name|

next if not @modcache[type]
next if not module_sets[type]

fullname = type + '/' + name

# Make sure the files associated with this module exist. If it
Expand Down Expand Up @@ -508,6 +513,7 @@ def save_module_cache
@modcache['ModuleTypeCounts'].clear

MODULE_TYPES.each { |type|
next if not @modcache['ModuleTypeCounts'][type]
@modcache['ModuleTypeCounts'][type] = module_sets[type].length.to_s
}
end
Expand Down Expand Up @@ -797,38 +803,47 @@ def module_names(set)
# Load all of the modules from the supplied module path (independent of
# module type).
#
def load_modules(path, demand = false)
def load_modules(bpath, demand = false)
loaded = {}
recalc = {}
counts = {}
delay = {}
ks = true

dbase = Dir.new(bpath)
dbase.entries.each do |ent|
path = File.join(bpath, ent)
mtype = ent.gsub(/s$/, '')
next if not File.directory?(path)
next if not MODULE_TYPES.include?(mtype)
next if not enabled_types[mtype]

# Try to load modules from all the files in the supplied path
Rex::Find.find(path) { |file|

# Skip non-ruby files
next if (file !~ /\.rb$/i)

# Skip unit test files
next if (file =~ /rb\.(ut|ts)\.rb$/)
# Try to load modules from all the files in the supplied path
Rex::Find.find(path) do |file|

# Skip files with a leading period
next if (file =~ /^\./)
# Skip non-ruby files
next if (file !~ /\.rb$/i)

begin
load_module_from_file(path, file, loaded, recalc, counts, demand)
rescue NameError

# As of Jan-06-2007 this code isn't hit with the official module tree

# If we get a name error, it's possible that this module depends
# on another one that we haven't loaded yet. Let's postpone
# the load operation for now so that we can resolve all
# dependencies. This is pretty much a hack.
delay[file] = $!
# Skip unit test files
next if (file =~ /rb\.(ut|ts)\.rb$/)

# Skip files with a leading period
next if (file =~ /^\./)

begin
load_module_from_file(bpath, file, loaded, recalc, counts, demand)
rescue NameError

# As of Jan-06-2007 this code isn't hit with the official module tree

# If we get a name error, it's possible that this module depends
# on another one that we haven't loaded yet. Let's postpone
# the load operation for now so that we can resolve all
# dependencies. This is pretty much a hack.
delay[file] = $!
end
end
}
end

# Keep processing all delayed module loads until we've gotten
# all the dependencies resolved or until we just suck.
Expand Down Expand Up @@ -1049,6 +1064,7 @@ def auto_subscribe_module(mod)
attr_accessor :module_paths # :nodoc:
attr_accessor :module_history, :module_history_mtime # :nodoc:
attr_accessor :module_failed # :nodoc:
attr_accessor :enabled_types # :nodoc:

end

Expand Down
4 changes: 3 additions & 1 deletion msfencode
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def usage
end

# Initialize the simplified framework instance.
$framework = Msf::Simple::Framework.create
$framework = Msf::Simple::Framework.create(
:module_types => [ Msf::MODULE_ENCODER ]
)

# Defaults
cmd = "encode"
Expand Down
5 changes: 4 additions & 1 deletion msfpayload
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def dump_payloads
end

# Initialize the simplified framework instance.
$framework = Msf::Simple::Framework.create
$framework = Msf::Simple::Framework.create(
:module_types => [ Msf::MODULE_PAYLOAD ]
)


if (ARGV.length <= 1)
puts "\n" + " Usage: #{$0} <payload> [var=val] <S[ummary]|C|P[erl]|[Rub]y|R[aw]|J[avascript]|e[X]ecutable|[V]BA>\n"
Expand Down

0 comments on commit af1675b

Please sign in to comment.