CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/core/module/options.rb
Views: 1904
1
# Register, deregister, and validate {#options}.
2
module Msf::Module::Options
3
#
4
# Attributes
5
#
6
7
# @attribute [r] options
8
# The module-specific options.
9
attr_reader :options
10
11
#
12
# Instance Methods
13
#
14
15
#
16
# This method ensures that the options associated with this module all
17
# have valid values according to each required option in the option
18
# container.
19
#
20
def validate
21
self.options.validate(self.datastore)
22
end
23
24
protected
25
26
#
27
# Removes the supplied options from the module's option container
28
# and data store.
29
#
30
def deregister_options(*names)
31
names.each { |name|
32
real_name = self.datastore.find_key_case(name)
33
if self.datastore.is_a?(Msf::DataStoreWithFallbacks)
34
self.datastore.remove_option(name)
35
else
36
self.datastore.delete(name)
37
end
38
self.options.remove_option(name)
39
if real_name != name
40
self.options.remove_option(real_name)
41
end
42
}
43
end
44
45
attr_writer :options
46
47
#
48
# Register advanced options with a specific owning class.
49
#
50
def register_advanced_options(options, owner = self.class)
51
self.options.add_advanced_options(options, owner)
52
import_defaults(false)
53
end
54
55
#
56
# Register evasion options with a specific owning class.
57
#
58
def register_evasion_options(options, owner = self.class)
59
self.options.add_evasion_options(options, owner)
60
import_defaults(false)
61
end
62
63
#
64
# Register options with a specific owning class.
65
#
66
def register_options(options, owner = self.class)
67
self.options.add_options(options, owner)
68
import_defaults(false)
69
end
70
71
# Registers a new option group, merging options by default
72
#
73
# @param name [String] Name for the group
74
# @param description [String] Description of the group
75
# @param option_names [Array<String>] List of datastore option names
76
# @param required_options [Array<String>] List of required datastore option names
77
# @param merge [Boolean] whether to merge or overwrite the groups option names
78
def register_option_group(name:, description:, option_names: [], required_options: [], merge: true)
79
existing_group = options.groups[name]
80
if merge && existing_group
81
existing_group.description = description
82
existing_group.add_options(option_names)
83
else
84
option_group = Msf::OptionGroup.new(name: name,
85
description: description,
86
option_names: option_names,
87
required_options: required_options)
88
options.add_group(option_group)
89
end
90
end
91
92
# De-registers an option group by name
93
#
94
# @param name [String] Name for the group
95
def deregister_option_group(name:)
96
options.remove_group(name)
97
end
98
end
99
100