Skip to content

Commit f779f0f

Browse files
committed
consolidate the config directory lookups
The user configuration directory can be overridden via environment variables or configuration files. In the current implementation `Msf::Config.config_directory` should be utilized for consistent location reporting. `Msf::Config.get_config_root` is reserved to generation of a default location and should be considered `private` as it ignores some injected configuration options. Currently autoloading does not allow application of the `private` keyword to this method, requiring guidance during development that module writers should access the full configured `user` value of `Msf::Config.config_directory`.
1 parent a97f884 commit f779f0f

File tree

14 files changed

+21
-21
lines changed

14 files changed

+21
-21
lines changed

lib/metasploit/framework/database.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def self.project_configurations_pathname
9393
# @return [Pathname] if the user has a `database.yml` in their config directory (`~/.msf4` by default).
9494
# @return [nil] if the user does not have a `database.yml` in their config directory.
9595
def self.user_configurations_pathname
96-
Pathname.new(Msf::Config.get_config_root).join('database.yml')
96+
Pathname.new(Msf::Config.config_directory).join('database.yml')
9797
end
9898
end
9999
end

lib/msf/base/config.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Config < Hash
2222
# The installation's root directory for the distribution
2323
InstallRoot = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..'))
2424

25-
# Determines the base configuration directory.
25+
# Determines the base configuration directory. This method should be considered `private`.
2626
#
2727
# @return [String] the base configuration directory
2828
def self.get_config_root

lib/msf/core/db_connector.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def self.db_disconnect(framework)
130130
# Connect to a database via the supplied yaml file
131131
#
132132
def self.db_connect_yaml(framework, opts)
133-
file = opts[:yaml_file] || ::File.join(Msf::Config.get_config_root, 'database.yml')
133+
file = opts[:yaml_file] || ::File.join(Msf::Config.config_directory, 'database.yml')
134134
file = ::File.expand_path(file)
135135
unless ::File.exist?(file)
136136
return { error: 'File not found' }

modules/auxiliary/gather/ldap_query.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def initialize(info = {})
6767
end
6868

6969
def initialize_actions
70-
user_config_file_path = File.join(::Msf::Config.get_config_root, 'ldap_queries.yaml')
70+
user_config_file_path = File.join(::Msf::Config.config_directory, 'ldap_queries.yaml')
7171
default_config_file_path = File.join(::Msf::Config.data_directory, 'auxiliary', 'gather', 'ldap_query', 'ldap_queries_default.yaml')
7272

7373
@loaded_queries = safe_load_queries(default_config_file_path) || []

modules/auxiliary/scanner/telephony/wardial.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ def run
9595
raise RuntimeError, "Telephony not available"
9696
end
9797

98-
@confdir = File.join(Msf::Config.get_config_root, 'wardial')
99-
@datadir = File.join(Msf::Config.get_config_root, 'logs', 'wardial')
98+
@confdir = File.join(Msf::Config.config_directory, 'wardial')
99+
@datadir = File.join(Msf::Config.config_directory, 'logs', 'wardial')
100100

101101
# make sure working dirs exist
102102
FileUtils.mkdir_p(@confdir)

modules/post/windows/gather/screen_spy.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def record?
6262

6363
def run
6464
host = session.session_host
65-
screenshot = Msf::Config.get_config_root + '/logs/' + host + '.jpg'
65+
screenshot = Msf::Config.config_directory + '/logs/' + host + '.jpg'
6666

6767
# If no PID is specified, don't migrate.
6868
if datastore['PID'] != ''

msfdb

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ require 'msfenv'
3434
@script_name = File.basename(__FILE__)
3535
@framework = File.expand_path(File.dirname(__FILE__))
3636

37-
@localconf = Msf::Config.get_config_root
37+
@localconf = Msf::Config.config_directory
3838
@db = "#{@localconf}/db"
3939
@db_conf = "#{@localconf}/database.yml"
4040
@pg_cluster_conf_root = "#{@localconf}/.local/etc/postgresql"

msfrpcd

+4-4
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ if $PROGRAM_NAME == __FILE__
122122

123123
require 'rex/parser/arguments'
124124

125-
ws_ssl_key_default = File.join(Msf::Config.get_config_root, "#{WS_TAG}-key.pem")
126-
ws_ssl_cert_default = File.join(Msf::Config.get_config_root, "#{WS_TAG}-cert.pem")
127-
ws_log = File.join(Msf::Config.get_config_root, 'logs', "#{WS_RPC_TAG}.log")
128-
ws_rpc_pid = File.join(Msf::Config.get_config_root, "#{WS_RPC_TAG}.pid")
125+
ws_ssl_key_default = File.join(Msf::Config.config_directory, "#{WS_TAG}-key.pem")
126+
ws_ssl_cert_default = File.join(Msf::Config.config_directory, "#{WS_TAG}-cert.pem")
127+
ws_log = File.join(Msf::Config.config_directory, 'logs', "#{WS_RPC_TAG}.log")
128+
ws_rpc_pid = File.join(Msf::Config.config_directory, "#{WS_RPC_TAG}.pid")
129129
ws_ssl_key = ws_ssl_key_default
130130
ws_ssl_cert = ws_ssl_cert_default
131131
ssl_enable_verify = false

plugins/aggregator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88

99
module Msf
10-
Aggregator_yaml = "#{Msf::Config.get_config_root}/aggregator.yaml" # location of the aggregator.yml containing saved aggregator creds
10+
Aggregator_yaml = "#{Msf::Config.config_directory}/aggregator.yaml" # location of the aggregator.yml containing saved aggregator creds
1111

1212
class Plugin::Aggregator < Msf::Plugin
1313
class AggregatorCommandDispatcher

plugins/beholder.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class BeholderCommandDispatcher
226226
webcam: false,
227227
keystrokes: true,
228228
automigrate: true,
229-
base: ::File.join(Msf::Config.get_config_root, "beholder", Time.now.strftime("%Y-%m-%d.%s")),
229+
base: ::File.join(Msf::Config.config_directory, "beholder", Time.now.strftime("%Y-%m-%d.%s")),
230230
freq: 30,
231231
# TODO: Only capture when the idle threshold has been reached
232232
idle: 0,

plugins/capture.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def parse_stop_args(args)
463463
end
464464

465465
def parse_start_args(args)
466-
config_file = File.join(Msf::Config.get_config_root, 'capture_config.yaml')
466+
config_file = File.join(Msf::Config.config_directory, 'capture_config.yaml')
467467
# See if there was a config file set
468468
@start_opt_parser.parse(args) do |opt, _idx, val|
469469
case opt
@@ -623,7 +623,7 @@ def initialize(framework, opts)
623623
super
624624
add_console_dispatcher(ConsoleCommandDispatcher)
625625
filename = 'capture_config.yaml'
626-
user_config_file = File.join(Msf::Config.get_config_root, filename)
626+
user_config_file = File.join(Msf::Config.config_directory, filename)
627627
unless File.exist?(user_config_file)
628628
# Initialise user config file with the installed one
629629
base_config_file = File.join(Msf::Config.data_directory, filename)

plugins/nessus.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def name
2424
end
2525

2626
def xindex
27-
"#{Msf::Config.get_config_root}/nessus_index"
27+
"#{Msf::Config.config_directory}/nessus_index"
2828
end
2929

3030
def nessus_yaml
31-
"#{Msf::Config.get_config_root}/nessus.yaml"
31+
"#{Msf::Config.config_directory}/nessus.yaml"
3232
end
3333

3434
def msf_local
@@ -102,7 +102,7 @@ def create_xindex
102102
start = Time.now
103103
print_status("Creating Exploit Search Index - (#{xindex}) - this won't take long.")
104104
count = 0
105-
#Use Msf::Config.get_config_root as the location.
105+
#Use Msf::Config.config_directory as the location.
106106
File.open("#{xindex}", "w+") do |f|
107107
#need to add version line.
108108
f.puts(Msf::Framework::Version)

plugins/nexpose.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
require 'nexpose'
99

1010
module Msf
11-
Nexpose_yaml = "#{Msf::Config.get_config_root}/nexpose.yaml" #location of the nexpose.yml containing saved nexpose creds
11+
Nexpose_yaml = "#{Msf::Config.config_directory}/nexpose.yaml" #location of the nexpose.yml containing saved nexpose creds
1212

1313
class Plugin::Nexpose < Msf::Plugin
1414
class NexposeCommandDispatcher

spec/lib/metasploit/framework/database_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@
664664
end
665665

666666
before(:example) do
667-
allow(Msf::Config).to receive(:get_config_root).and_return(config_root)
667+
allow(Msf::Config).to receive(:config_directory).and_return(config_root)
668668
end
669669

670670
it 'is database.yml under the user config root' do

0 commit comments

Comments
 (0)