Skip to content

Commit 0431720

Browse files
author
Tod Beardsley
committed
Land rapid7#4294, msfconsole speedups on module load
Related to rapid7#4257 and rapid7#4195 vaguely, and possibly even rapid7#4147.
2 parents 85e0d72 + 9272fe9 commit 0431720

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

lib/msf/base/simple/framework/module_paths.rb

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ module ModulePaths
77
#
88
# @return [void]
99
def init_module_paths(opts={})
10-
# Ensure the module cache is accurate
11-
self.modules.refresh_cache_from_database
10+
if @module_paths_inited
11+
fail "Module paths already initialized. To add more module paths call `modules.add_module_path`"
12+
else
13+
# Ensure the module cache is accurate
14+
self.modules.refresh_cache_from_database
1215

13-
add_engine_module_paths(Rails.application, opts)
16+
add_engine_module_paths(Rails.application, opts)
1417

15-
Rails.application.railties.engines.each do |engine|
16-
add_engine_module_paths(engine, opts)
17-
end
18+
Rails.application.railties.engines.each do |engine|
19+
add_engine_module_paths(engine, opts)
20+
end
1821

19-
# Initialize the user module search path
20-
if (Msf::Config.user_module_directory)
21-
self.modules.add_module_path(Msf::Config.user_module_directory, opts)
22-
end
22+
# Initialize the user module search path
23+
if (Msf::Config.user_module_directory)
24+
self.modules.add_module_path(Msf::Config.user_module_directory, opts)
25+
end
26+
27+
# If additional module paths have been defined globally, then load them.
28+
# They should be separated by semi-colons.
29+
if self.datastore['MsfModulePaths']
30+
self.datastore['MsfModulePaths'].split(";").each { |path|
31+
self.modules.add_module_path(path, opts)
32+
}
33+
end
2334

24-
# If additional module paths have been defined globally, then load them.
25-
# They should be separated by semi-colons.
26-
if self.datastore['MsfModulePaths']
27-
self.datastore['MsfModulePaths'].split(";").each { |path|
28-
self.modules.add_module_path(path, opts)
29-
}
35+
@module_paths_inited = true
3036
end
3137
end
3238

lib/msf/ui/console/driver.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
5959
histfile = opts['HistFile'] || Msf::Config.history_file
6060

6161
# Initialize attributes
62-
self.framework = opts['Framework'] || Msf::Simple::Framework.create(opts)
62+
63+
# Defer loading of modules until paths from opts can be added below
64+
framework_create_options = {'DeferModuleLoads' => true}.merge(opts)
65+
self.framework = opts['Framework'] || Msf::Simple::Framework.create(framework_create_options)
6366

6467
if self.framework.datastore['Prompt']
6568
prompt = self.framework.datastore['Prompt']

0 commit comments

Comments
 (0)