Class: Msf::FeatureManager
- Inherits:
-
Object
- Object
- Msf::FeatureManager
- Includes:
- Singleton
- Defined in:
- lib/msf/core/feature_manager.rb
Overview
The feature manager is responsible for managing feature flags that can change characteristics of framework. Each feature will have a default value. The user can choose to override this default value if they wish.
Constant Summary collapse
- CONFIG_KEY =
'framework/features'
- WRAPPED_TABLES =
'wrapped_tables'
- DATASTORE_FALLBACKS =
'datastore_fallbacks'
- FULLY_INTERACTIVE_SHELLS =
'fully_interactive_shells'
- MANAGER_COMMANDS =
'manager_commands'
- DEFAULTS =
[ { name: WRAPPED_TABLES, description: 'When enabled Metasploit will wordwrap all tables to fit into the available terminal width', default_value: true }.freeze, { name: FULLY_INTERACTIVE_SHELLS, description: 'When enabled you will have the option to drop into a fully interactive shell from within meterpreter', default_value: false }.freeze, { name: MANAGER_COMMANDS, description: 'When enabled you will have access to manager commands such as _servicemanager and _historymanager', default_value: false }.freeze, { name: DATASTORE_FALLBACKS, description: 'When enabled you can consistently set username across modules, instead of setting SMBUser/FTPUser/BIND_DN/etc', requires_restart: true, default_value: true }.freeze ].freeze
Instance Method Summary collapse
- #all ⇒ Object
-
#enabled?(name) ⇒ TrueClass, FalseClass
True if the flag is be enabled, false otherwise.
- #exists?(name) ⇒ Boolean
-
#initialize ⇒ FeatureManager
constructor
Initializes the feature manager.
- #load_config ⇒ Object
- #names ⇒ Object
-
#requires_restart?(name) ⇒ TrueClass, FalseClass
True if the flag requires a console restart to work effectively.
- #save_config ⇒ Object
- #set(name, value) ⇒ Object
Constructor Details
#initialize ⇒ FeatureManager
Initializes the feature manager.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/msf/core/feature_manager.rb', line 48 def initialize @flag_lookup = DEFAULTS.each_with_object({}) do |feature, acc| if feature[:name] == WRAPPED_TABLES if feature[:default_value] == true Rex::Text::Table.wrap_tables! else Rex::Text::Table.unwrap_tables! end end key = feature[:name] acc[key] = feature.dup end end |
Instance Method Details
#all ⇒ Object
63 64 65 66 67 |
# File 'lib/msf/core/feature_manager.rb', line 63 def all @flag_lookup.values.map do |feature| feature.slice(:name, :description).merge(enabled: enabled?(feature[:name])) end end |
#enabled?(name) ⇒ TrueClass, FalseClass
Returns True if the flag is be enabled, false otherwise.
71 72 73 74 75 76 |
# File 'lib/msf/core/feature_manager.rb', line 71 def enabled?(name) return false unless @flag_lookup[name] feature = @flag_lookup[name] feature.key?(:user_preference) ? feature[:user_preference] : feature[:default_value] end |
#exists?(name) ⇒ Boolean
86 87 88 |
# File 'lib/msf/core/feature_manager.rb', line 86 def exists?(name) @flag_lookup.key?(name) end |
#load_config ⇒ Object
108 109 110 111 112 113 |
# File 'lib/msf/core/feature_manager.rb', line 108 def load_config conf = Msf::Config.load conf.fetch(CONFIG_KEY, {}).each do |name, value| set(name, value == 'true') end end |
#names ⇒ Object
90 91 92 |
# File 'lib/msf/core/feature_manager.rb', line 90 def names all.map { |feature| feature[:name] } end |
#requires_restart?(name) ⇒ TrueClass, FalseClass
Returns True if the flag requires a console restart to work effectively.
80 81 82 83 84 |
# File 'lib/msf/core/feature_manager.rb', line 80 def requires_restart?(name) return false unless @flag_lookup[name] @flag_lookup[name][:requires_restart] == true end |
#save_config ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/msf/core/feature_manager.rb', line 115 def save_config # Note, we intentionally omit features that have not explicitly been set by the user. config = Msf::Config.load old_config = config.fetch(CONFIG_KEY, {}) new_config = @flag_lookup.values.each_with_object(old_config) do |feature, config| next unless feature.key?(:user_preference) config.merge!(feature[:name] => feature[:user_preference].to_s) end Msf::Config.save(CONFIG_KEY => new_config) end |
#set(name, value) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/msf/core/feature_manager.rb', line 94 def set(name, value) return false unless @flag_lookup[name] @flag_lookup[name][:user_preference] = value if name == WRAPPED_TABLES if value Rex::Text::Table.wrap_tables! else Rex::Text::Table.unwrap_tables! end end end |