From 66b453edd6d292fb00ce0b7ce24be15ae7210c6a Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Tue, 22 Sep 2015 12:56:26 -0500 Subject: [PATCH] ensure the database cache is always updated, present accurate reporting on search --- lib/msf/core/module_manager/cache.rb | 7 +------ lib/msf/ui/console/command_dispatcher/core.rb | 14 +++++++++----- lib/msf/ui/console/driver.rb | 7 ++----- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/msf/core/module_manager/cache.rb b/lib/msf/core/module_manager/cache.rb index a0c7f34856..e315a33726 100644 --- a/lib/msf/core/module_manager/cache.rb +++ b/lib/msf/core/module_manager/cache.rb @@ -112,7 +112,6 @@ module Msf::ModuleManager::Cache else framework.db.update_all_module_details end - refresh_cache_from_database(self.module_paths) end end @@ -131,11 +130,7 @@ module Msf::ModuleManager::Cache # @return [true] if migrations have been run # @return [false] otherwise def framework_migrated? - if framework.db and framework.db.migrated - true - else - false - end + framework.db && framework.db.migrated end # @!attribute [rw] module_info_by_path diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 66dbb0af92..c5fbcbbabc 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -1543,13 +1543,17 @@ class Core end } - if framework.db and framework.db.migrated and framework.db.modules_cached - search_modules_sql(match) - return + if framework.db + if framework.db.migrated && framework.db.modules_cached + search_modules_sql(match) + return + else + print_warning("Module database cache not built yet, using slow search") + end + else + print_warning("Database not connected, using slow search") end - print_warning("Database not connected or cache not built, using slow search") - tbl = generate_module_table("Matching Modules") [ framework.exploits, diff --git a/lib/msf/ui/console/driver.rb b/lib/msf/ui/console/driver.rb index 914e0a787e..d2292ba6a9 100644 --- a/lib/msf/ui/console/driver.rb +++ b/lib/msf/ui/console/driver.rb @@ -213,11 +213,8 @@ class Driver < Msf::Ui::Driver end if framework.db.active && !opts['DeferModuleLoads'] - if self.framework.modules.cache_empty? - self.framework.threads.spawn("ModuleCacheRebuild", true) do - self.framework.modules.refresh_cache_from_module_files - end - print_status("The initial module cache will be built in the background, this can take 2-5 minutes...") + framework.threads.spawn("ModuleCacheRebuild", true) do + framework.modules.refresh_cache_from_module_files end end