Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/msf/core/feature_manager.rb
Views: 11623
# -*- coding: binary -*-1# frozen_string_literal: true23require 'rex/text'45module Msf6###7#8# The feature manager is responsible for managing feature flags that can change characteristics of framework.9# Each feature will have a default value. The user can choose to override this default value if they wish.10###11class FeatureManager1213include Singleton1415CONFIG_KEY = 'framework/features'16WRAPPED_TABLES = 'wrapped_tables'17DATASTORE_FALLBACKS = 'datastore_fallbacks'18FULLY_INTERACTIVE_SHELLS = 'fully_interactive_shells'19MANAGER_COMMANDS = 'manager_commands'20METASPLOIT_PAYLOAD_WARNINGS = 'metasploit_payload_warnings'21DEFER_MODULE_LOADS = 'defer_module_loads'22DNS = 'dns'23HIERARCHICAL_SEARCH_TABLE = 'hierarchical_search_table'24SMB_SESSION_TYPE = 'smb_session_type'25POSTGRESQL_SESSION_TYPE = 'postgresql_session_type'26MYSQL_SESSION_TYPE = 'mysql_session_type'27MSSQL_SESSION_TYPE = 'mssql_session_type'28LDAP_SESSION_TYPE = 'ldap_session_type'29SHOW_SUCCESSFUL_LOGINS = 'show_successful_logins'3031DEFAULTS = [32{33name: WRAPPED_TABLES,34description: 'When enabled Metasploit will wordwrap all tables to fit into the available terminal width',35default_value: true,36developer_notes: 'This functionality is enabled by default now, and the feature flag can be removed now'37}.freeze,38{39name: FULLY_INTERACTIVE_SHELLS,40description: 'When enabled you will have the option to drop into a fully interactive shell from within meterpreter',41default_value: false,42developer_notes: 'Development paused as the interaction time feels clunky, especially for slow transport layers like HTTP on Mettle. Would require changes to the transport sleep/priority logic'43}.freeze,44{45name: MANAGER_COMMANDS,46description: 'When enabled you will have access to manager commands such as _servicemanager and _historymanager',47default_value: false,48developer_notes: 'Useful for developers, likely not to ever be useful for an average user'49}.freeze,50{51name: DATASTORE_FALLBACKS,52description: 'When enabled you can consistently set username across modules, instead of setting SMBUser/FTPUser/BIND_DN/etc',53requires_restart: true,54default_value: true,55developer_notes: 'This functionality is enabled by default now, and the feature flag can be removed now'56}.freeze,57{58name: METASPLOIT_PAYLOAD_WARNINGS,59description: 'When enabled Metasploit will output warnings about missing Metasploit payloads, for instance if they were removed by antivirus etc',60requires_restart: true,61default_value: true,62developer_notes: 'Enabled in Metasploit 6.4.x'63}.freeze,64{65name: DEFER_MODULE_LOADS,66description: 'When enabled will not eagerly load all modules',67requires_restart: true,68default_value: false,69developer_notes: 'Needs a final round of testing. Can be enabled after 6.4.0 is released.'70}.freeze,71{72name: SMB_SESSION_TYPE,73description: 'When enabled will allow for the creation/use of smb sessions',74requires_restart: true,75default_value: true,76developer_notes: 'Enabled in Metasploit 6.4.x'77}.freeze,78{79name: POSTGRESQL_SESSION_TYPE,80description: 'When enabled will allow for the creation/use of PostgreSQL sessions',81requires_restart: true,82default_value: true,83developer_notes: 'Enabled in Metasploit 6.4.x'84}.freeze,85{86name: MYSQL_SESSION_TYPE,87description: 'When enabled will allow for the creation/use of MySQL sessions',88requires_restart: true,89default_value: true,90developer_notes: 'Enabled in Metasploit 6.4.x'91}.freeze,92{93name: MSSQL_SESSION_TYPE,94description: 'When enabled will allow for the creation/use of mssql sessions',95requires_restart: true,96default_value: true,97developer_notes: 'Enabled in Metasploit 6.4.x'98}.freeze,99{100name: LDAP_SESSION_TYPE,101description: 'When enabled will allow for the creation/use of LDAP sessions',102requires_restart: true,103default_value: false,104developer_notes: 'To be enabled by default after appropriate testing'105}.freeze,106{107name: SHOW_SUCCESSFUL_LOGINS,108description: 'When enabled scanners/login modules will return a table off successful logins once the module completes',109requires_restart: false,110default_value: false,111developer_notes: 'To be enabled after appropriate testing'112}.freeze,113{114name: DNS,115description: 'When enabled allows configuration of DNS resolution behaviour in Metasploit',116requires_restart: true,117default_value: true,118developer_notes: 'Enabled in Metasploit 6.4.x'119}.freeze,120{121name: HIERARCHICAL_SEARCH_TABLE,122description: 'When enabled the search table is enhanced to show details on module actions and targets',123requires_restart: false,124default_value: true,125developer_notes: 'Enabled in Metasploit 6.4.x'126}.freeze127].freeze128129#130# Initializes the feature manager.131#132def initialize133@flag_lookup = DEFAULTS.each_with_object({}) do |feature, acc|134if feature[:name] == WRAPPED_TABLES135if feature[:default_value] == true136Rex::Text::Table.wrap_tables!137else138Rex::Text::Table.unwrap_tables!139end140end141142key = feature[:name]143acc[key] = feature.dup144end145end146147def all148@flag_lookup.values.map do |feature|149feature.slice(:name, :description).merge(enabled: enabled?(feature[:name]))150end151end152153# @param [String] name The feature name154# @return [TrueClass,FalseClass] True if the flag is be enabled, false otherwise155def enabled?(name)156return false unless @flag_lookup[name]157158feature = @flag_lookup[name]159feature.key?(:user_preference) ? feature[:user_preference] : feature[:default_value]160end161162# @param [String] name The feature name163# @return [TrueClass,FalseClass] True if the flag requires a console restart to work effectively164def requires_restart?(name)165return false unless @flag_lookup[name]166167@flag_lookup[name][:requires_restart] == true168end169170def exists?(name)171@flag_lookup.key?(name)172end173174def names175all.map { |feature| feature[:name] }176end177178def set(name, value)179return false unless @flag_lookup[name]180181@flag_lookup[name][:user_preference] = value182183if name == WRAPPED_TABLES184if value185Rex::Text::Table.wrap_tables!186else187Rex::Text::Table.unwrap_tables!188end189end190end191192def load_config193conf = Msf::Config.load194conf.fetch(CONFIG_KEY, {}).each do |name, value|195set(name, value == 'true')196end197end198199def save_config200# Note, we intentionally omit features that have not explicitly been set by the user.201config = Msf::Config.load202old_config = config.fetch(CONFIG_KEY, {})203new_config = @flag_lookup.values.each_with_object(old_config) do |feature, config|204next unless feature.key?(:user_preference)205206config.merge!(feature[:name] => feature[:user_preference].to_s)207end208209Msf::Config.save(CONFIG_KEY => new_config)210end211end212end213214215