Enable deletion of saved data services

GSoC/Meterpreter_Web_Console
James Barnett 2018-08-27 11:32:19 -05:00
parent bb0ec0472b
commit 24cf99f59c
No known key found for this signature in database
GPG Key ID: 647983861A4EC5EA
2 changed files with 42 additions and 4 deletions

View File

@ -236,6 +236,14 @@ class Config < Hash
self.new.save(opts)
end
# Deletes the specified config group from the ini file
#
# @param group [String] The name of the group to remove
# @return [void]
def self.delete_group(group)
self.new.delete_group(group)
end
# Updates the config class' self with the default hash.
#
# @return [Hash] the updated Hash.
@ -410,6 +418,17 @@ class Config < Hash
ini.to_file
end
# Deletes the specified config group from the ini file
#
# @param group [String] The name of the group to remove
# @return [void]
def delete_group(group)
ini = Rex::Parser::Ini.new(config_file)
ini.delete(group)
ini.to_file
end
end
end

View File

@ -1764,6 +1764,7 @@ class Db
opts[:url] = arg
else
cmd_db_connect_help
return
end
end
end
@ -1862,6 +1863,7 @@ class Db
print_line(" OPTIONS:")
print_line(" -d,--default Set this data service as the default connection.")
print_line(" -c,--clear-default Clear the currently set default data service.")
print_line(" --delete Delete the specified data service.")
end
def cmd_db_save(*args)
@ -1873,9 +1875,10 @@ class Db
when '-d', '--default'
default = true
when '-c','--clear-default'
Msf::Config.save(DB_CONFIG_PATH => { })
print_line "Cleared the default database."
clear_default_db
return
when '--delete'
mode = :delete
else
name = arg
end
@ -1886,9 +1889,17 @@ class Db
return
end
if mode && mode == :delete
conf = Msf::Config.load
clear_default_db if conf[DB_CONFIG_PATH]['default_db'] && conf[DB_CONFIG_PATH]['default_db'] == name
Msf::Config.delete_group("#{DB_CONFIG_PATH}/#{name}")
print_line "Successfully deleted data service: #{name}"
else
save_db_to_config(framework.db, name)
Msf::Config.save(DB_CONFIG_PATH => { 'default_db' => name }) if default
print_line "Successfully saved data service: #{name}"
end
end
def save_db_to_config(database, database_name)
@ -1921,6 +1932,14 @@ class Db
end
end
def clear_default_db
conf = Msf::Config.load
updated_opts = conf[DB_CONFIG_PATH]
updated_opts.delete('default_db')
Msf::Config.save(DB_CONFIG_PATH => updated_opts)
print_line "Cleared the default database."
end
def db_find_tools(tools)
missed = []
tools.each do |name|