Module: Msf::Module::ModuleInfo
- Included in:
- Msf::Module
- Defined in:
- lib/msf/core/module/module_info.rb
Constant Summary collapse
- UpdateableOptions =
The list of options that support merging in an information hash.
[ "Name", "Description", "Alias", "PayloadCompat" ]
Instance Attribute Summary collapse
- #module_info ⇒ Object protected
Instance Method Summary collapse
-
#alias ⇒ Object
Returns the module's alias, if it has one.
-
#description ⇒ Object
Return the module's description.
-
#disclosure_date ⇒ Object
Returns the disclosure date, if known.
-
#info_fixups ⇒ Object
protected
Register options with a specific owning class.
-
#merge_check_key(info, name, val) ⇒ Object
protected
Checks and merges the supplied key/value pair in the supplied hash.
-
#merge_info(info, opts) ⇒ Object
protected
Merges options in the info hash in a sane fashion, as some options require special attention.
-
#merge_info_advanced_options(info, val) ⇒ Object
protected
Merges advanced options.
-
#merge_info_alias(info, val) ⇒ Object
protected
Merge aliases with an underscore delimiter.
-
#merge_info_description(info, val) ⇒ Object
protected
Merges the module description.
-
#merge_info_evasion_options(info, val) ⇒ Object
protected
Merges advanced options.
-
#merge_info_name(info, val) ⇒ Object
protected
Merges the module name.
-
#merge_info_options(info, val, advanced = false, evasion = false) ⇒ Object
protected
Merges options.
-
#merge_info_string(info, key, val, delim = ', ', inverse = false) ⇒ Object
protected
Merges a given key in the info hash with a delimiter.
-
#merge_info_version(info, val) ⇒ Object
protected
Merge the module version.
-
#name ⇒ Object
Return the module's name from the module information hash.
-
#notes ⇒ Object
Return the module's notes (including AKA and NOCVE descriptors).
-
#update_info(info, opts) ⇒ Object
protected
Updates information in the supplied info hash and merges other information.
Instance Attribute Details
#module_info ⇒ Object (protected)
57 58 59 |
# File 'lib/msf/core/module/module_info.rb', line 57 def module_info @module_info end |
Instance Method Details
#alias ⇒ Object
Returns the module's alias, if it has one. Otherwise, the module's name is returned.
17 18 19 |
# File 'lib/msf/core/module/module_info.rb', line 17 def alias module_info['Alias'] end |
#description ⇒ Object
Return the module's description.
24 25 26 |
# File 'lib/msf/core/module/module_info.rb', line 24 def description module_info['Description'] end |
#disclosure_date ⇒ Object
Returns the disclosure date, if known.
31 32 33 |
# File 'lib/msf/core/module/module_info.rb', line 31 def disclosure_date date_str = Date.parse(module_info['DisclosureDate'].to_s) rescue nil end |
#info_fixups ⇒ Object (protected)
Register options with a specific owning class.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/msf/core/module/module_info.rb', line 66 def info_fixups # Each reference should be an array consisting of two elements refs = module_info['References'] if(refs and not refs.empty?) refs.each_index do |i| if !(refs[i].respond_to?('[]') and refs[i].length == 2) refs[i] = nil end end # Purge invalid references refs.delete(nil) end end |
#merge_check_key(info, name, val) ⇒ Object (protected)
Checks and merges the supplied key/value pair in the supplied hash.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/msf/core/module/module_info.rb', line 84 def merge_check_key(info, name, val) if (self.respond_to?("merge_info_#{name.downcase}", true)) eval("merge_info_#{name.downcase}(info, val)") else # If the info hash already has an entry for this name if (info[name]) # If it's not an array, convert it to an array and merge the # two if (info[name].kind_of?(Array) == false) curr = info[name] info[name] = [ curr ] end # If the value being merged is an array, add each one if (val.kind_of?(Array) == true) val.each { |v| if (info[name].include?(v) == false) info[name] << v end } # Otherwise just add the value elsif (info[name].include?(val) == false) info[name] << val end # Otherwise, just set the value equal if no current value # exists else info[name] = val end end end |
#merge_info(info, opts) ⇒ Object (protected)
Merges options in the info hash in a sane fashion, as some options require special attention.
120 121 122 123 124 125 126 |
# File 'lib/msf/core/module/module_info.rb', line 120 def merge_info(info, opts) opts.each_pair { |name, val| merge_check_key(info, name, val) } info end |
#merge_info_advanced_options(info, val) ⇒ Object (protected)
Merges advanced options.
131 132 133 |
# File 'lib/msf/core/module/module_info.rb', line 131 def (info, val) (info, val, true, false) end |
#merge_info_alias(info, val) ⇒ Object (protected)
Merge aliases with an underscore delimiter.
138 139 140 |
# File 'lib/msf/core/module/module_info.rb', line 138 def merge_info_alias(info, val) merge_info_string(info, 'Alias', val, '_') end |
#merge_info_description(info, val) ⇒ Object (protected)
Merges the module description.
145 146 147 |
# File 'lib/msf/core/module/module_info.rb', line 145 def merge_info_description(info, val) merge_info_string(info, 'Description', val, ". ", true) end |
#merge_info_evasion_options(info, val) ⇒ Object (protected)
Merges advanced options.
152 153 154 |
# File 'lib/msf/core/module/module_info.rb', line 152 def (info, val) (info, val, false, true) end |
#merge_info_name(info, val) ⇒ Object (protected)
Merges the module name.
159 160 161 |
# File 'lib/msf/core/module/module_info.rb', line 159 def merge_info_name(info, val) merge_info_string(info, 'Name', val, ', ', true) end |
#merge_info_options(info, val, advanced = false, evasion = false) ⇒ Object (protected)
Merges options.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/msf/core/module/module_info.rb', line 166 def (info, val, advanced = false, evasion = false) key_name = ((advanced) ? 'Advanced' : (evasion) ? 'Evasion' : '') + 'Options' new_cont = Msf::OptionContainer.new new_cont.(val, advanced, evasion) cur_cont = Msf::OptionContainer.new cur_cont.(info[key_name] || [], advanced, evasion) new_cont.each_option { |name, option| next if (cur_cont.get(name)) info[key_name] = [] if (!info[key_name]) info[key_name] << option } end |
#merge_info_string(info, key, val, delim = ', ', inverse = false) ⇒ Object (protected)
Merges a given key in the info hash with a delimiter.
186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/msf/core/module/module_info.rb', line 186 def merge_info_string(info, key, val, delim = ', ', inverse = false) if (info[key]) if (inverse == true) info[key] = info[key] + delim + val else info[key] = val + delim + info[key] end else info[key] = val end end |
#merge_info_version(info, val) ⇒ Object (protected)
Merge the module version.
201 202 203 |
# File 'lib/msf/core/module/module_info.rb', line 201 def merge_info_version(info, val) merge_info_string(info, 'Version', val) end |
#name ⇒ Object
Return the module's name from the module information hash.
38 39 40 |
# File 'lib/msf/core/module/module_info.rb', line 38 def name module_info['Name'] end |
#notes ⇒ Object
Return the module's notes (including AKA and NOCVE descriptors).
46 47 48 |
# File 'lib/msf/core/module/module_info.rb', line 46 def notes module_info['Notes'] end |
#update_info(info, opts) ⇒ Object (protected)
Updates information in the supplied info hash and merges other information. This method is used to override things like Name, Version, and Description without losing the ability to merge architectures, platforms, and options.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/msf/core/module/module_info.rb', line 211 def update_info(info, opts) opts.each_pair { |name, val| # If the supplied option name is one of the ones that we should # override by default if (UpdateableOptions.include?(name) == true) # Only if the entry is currently nil do we use our value if (info[name] == nil) info[name] = val end # Otherwise, perform the merge operation like normal else merge_check_key(info, name, val) end } return info end |