diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index a40b032c55..2535310e3e 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -32,11 +32,12 @@ class Db # def commands base = { - "db_connect" => "Connect to an existing data service", - "db_disconnect" => "Disconnect from the current data service", - "db_status" => "Show the current data service status", - "db_save" => "Save the current data service connection as the default to reconnect on startup", - "db_remove" => "Remove the saved data service entry" + "db_connect" => "Connect to an existing data service", + "db_disconnect" => "Disconnect from the current data service", + "db_status" => "Show the current data service status", + "db_save" => "Save the current data service connection as the default to reconnect on startup", + "db_remove" => "Remove the saved data service entry", + "db_clear_default" => "Clears the default data service connection used on startup" } more = { @@ -1890,6 +1891,27 @@ class Db end end + def cmd_db_clear_default_help(*args) + print_line "Usage: db_clear_default" + print_line + print_line "Clears the default data service connection used on startup." + print_line + end + + + def cmd_db_clear_default(*args) + while (arg = args.shift) + case arg + when '-h', '--help' + cmd_db_clear_default_help + return + end + end + + clear_default_db + end + + def save_db_to_config(database, database_name) if database_name =~ /\/|\[|\]/ raise ArgumentError, 'Data service name contains an invalid character.' diff --git a/msfdb b/msfdb index 6b0f01af04..8320d46c1b 100755 --- a/msfdb +++ b/msfdb @@ -640,6 +640,17 @@ def persist_data_service end end +def clear_default_data_service + # execute msfconsole commands to add and persist the data service connection + cmd = "./msfconsole -qx db_clear_default; exit\"" + if @db_driver.run_cmd(cmd) != 0 + # attempt to execute msfconsole in the current working directory + if @db_driver.run_cmd(cmd, env: {'PATH' => ".:#{ENV["PATH"]}"}) != 0 + puts 'Failed to run msfconsole and clear the default data service connection' + end + end +end + def get_db_connect_command data_service_name = "local-#{@options[:ssl] ? 'https' : 'http'}-data-service" if !@options[:data_service_name].nil? @@ -1001,11 +1012,15 @@ if $PROGRAM_NAME == __FILE__ parse_args(ARGV) unless @component_provided - if ask_yn_default('Would you also like to start up the webservice?', false) + if ask_yn_default('Would you also like this operation to affect the webservice?', false) @options[:component] = :all end end + if @options[:database] + clear_default_data_service + end + update_db_port if @connection_string