diff --git a/lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb b/lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb index a679dba84b..8988b97f77 100644 --- a/lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb +++ b/lib/metasploit/framework/data_service/proxy/workspace_data_proxy.rb @@ -21,9 +21,9 @@ module WorkspaceDataProxy def default_workspace begin - ws = find_workspace('default') + ws = find_workspace(Msf::DBManager::Workspace::DEFAULT_WORKSPACE_NAME) if ws.nil? - ws = add_workspace('default') + ws = add_workspace(Msf::DBManager::Workspace::DEFAULT_WORKSPACE_NAME) end ws rescue Exception => e diff --git a/lib/metasploit/framework/data_service/remote/http/remote_workspace_data_service.rb b/lib/metasploit/framework/data_service/remote/http/remote_workspace_data_service.rb index fef36096f2..e28f1c6e87 100644 --- a/lib/metasploit/framework/data_service/remote/http/remote_workspace_data_service.rb +++ b/lib/metasploit/framework/data_service/remote/http/remote_workspace_data_service.rb @@ -5,7 +5,6 @@ module RemoteWorkspaceDataService WORKSPACE_API_PATH = '/api/v1/workspaces' WORKSPACE_MDM_CLASS = 'Mdm::Workspace' - DEFAULT_WORKSPACE_NAME = 'default' def add_workspace(workspace_name) response = self.post_data(WORKSPACE_API_PATH, {:workspace_name => workspace_name}) @@ -13,7 +12,7 @@ module RemoteWorkspaceDataService end def default_workspace - json_to_mdm_object(self.get_data(WORKSPACE_API_PATH, nil, {:name => default}, false), WORKSPACE_MDM_CLASS, []) + json_to_mdm_object(self.get_data(WORKSPACE_API_PATH, nil, {:name => Msf::DBManager::Workspace::DEFAULT_WORKSPACE_NAME}, false), WORKSPACE_MDM_CLASS, []) end def workspace diff --git a/lib/msf/core/db_manager/vuln_attempt.rb b/lib/msf/core/db_manager/vuln_attempt.rb index e85292c00b..06235f7f6c 100644 --- a/lib/msf/core/db_manager/vuln_attempt.rb +++ b/lib/msf/core/db_manager/vuln_attempt.rb @@ -22,20 +22,17 @@ module Msf::DBManager::VulnAttempt # This methods returns a list of all vulnerability attempts in the database # def vuln_attempts(opts) - wspace = opts.delete(:workspace) || opts.delete(:wspace) || workspace - if wspace.kind_of? String - wspace = find_workspace(wspace) + ::ActiveRecord::Base.connection_pool.with_connection { + # 'workspace' is not a valid attribute for Mdm::VulnAttempt. Remove it. + Msf::Util::DBManager.process_opts_workspace(opts, framework) + + search_term = opts.delete(:search_term) + if search_term && !search_term.empty? + column_search_conditions = Msf::Util::DBManager.create_all_column_search_conditions(Mdm::VulnAttempt, search_term) + Mdm::VulnAttempt.where(opts).where(column_search_conditions) + else + Mdm::VulnAttempt.where(opts) end - - ::ActiveRecord::Base.connection_pool.with_connection { - - search_term = opts.delete(:search_term) - if search_term && !search_term.empty? - column_search_conditions = Msf::Util::DBManager.create_all_column_search_conditions(Mdm::VulnAttempt, search_term) - Mdm::VulnAttempt.where(opts).where(column_search_conditions) - else - Mdm::VulnAttempt.where(opts) - end - } + } end end \ No newline at end of file diff --git a/lib/msf/core/db_manager/workspace.rb b/lib/msf/core/db_manager/workspace.rb index 8d27542ee4..af146ee085 100644 --- a/lib/msf/core/db_manager/workspace.rb +++ b/lib/msf/core/db_manager/workspace.rb @@ -1,4 +1,6 @@ module Msf::DBManager::Workspace + + DEFAULT_WORKSPACE_NAME = 'default' # # Creates a new workspace in the database # @@ -75,7 +77,7 @@ module Msf::DBManager::Workspace end begin deleted << ws.destroy - framework.db.workspace = framework.db.add_workspace('default') if default_deleted + framework.db.workspace = framework.db.add_workspace(DEFAULT_WORKSPACE_NAME) if default_deleted rescue elog("Forcibly deleting #{workspace}") deleted << ws.delete diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index 38a962c2b7..0005fef8e3 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -235,7 +235,7 @@ class Db def print_deleted_workspaces(deleted_workspaces, starting_ws) deleted_workspaces.each do |ws| - if ws.name == 'default' + if ws.name == Msf::DBManager::Workspace::DEFAULT_WORKSPACE_NAME print_status 'Deleted and recreated the default workspace' elsif ws == starting_ws print_status "Switched workspace: #{framework.db.workspace.name}" diff --git a/lib/msf/util/db_manager.rb b/lib/msf/util/db_manager.rb index ec912df462..73c36c1cea 100644 --- a/lib/msf/util/db_manager.rb +++ b/lib/msf/util/db_manager.rb @@ -16,7 +16,7 @@ module DBManager end def self.process_opts_workspace(opts, framework) - wspace = opts.delete(:wspace) || opts.delete(:workspace) + wspace = opts.delete(:workspace) || opts.delete(:wspace) raise ArgumentError.new("opts must include a valid :workspace.") if wspace.nil? || ((wspace.kind_of? String) && wspace.empty?) if wspace.kind_of? String