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 115 116 117 118 119 120 121 |
# 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?(Hash)) raise TypeError, 'can only merge a hash into a hash' unless val.kind_of?(Hash) val.each_pair do |val_key, val_val| merge_check_key(info[name], val_key, val_val) end return elsif (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.
127 128 129 130 131 132 133 |
# File 'lib/msf/core/module/module_info.rb', line 127 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.
138 139 140 |
# File 'lib/msf/core/module/module_info.rb', line 138 def (info, val) (info, val, true, false) end |
#merge_info_alias(info, val) ⇒ Object (protected)
Merge aliases with an underscore delimiter.
145 146 147 |
# File 'lib/msf/core/module/module_info.rb', line 145 def merge_info_alias(info, val) merge_info_string(info, 'Alias', val, '_') end |
#merge_info_description(info, val) ⇒ Object (protected)
Merges the module description.
152 153 154 |
# File 'lib/msf/core/module/module_info.rb', line 152 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.
159 160 161 |
# File 'lib/msf/core/module/module_info.rb', line 159 def (info, val) (info, val, false, true) end |
#merge_info_name(info, val) ⇒ Object (protected)
Merges the module name.
166 167 168 |
# File 'lib/msf/core/module/module_info.rb', line 166 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.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/msf/core/module/module_info.rb', line 173 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.
193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/msf/core/module/module_info.rb', line 193 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.
208 209 210 |
# File 'lib/msf/core/module/module_info.rb', line 208 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.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/msf/core/module/module_info.rb', line 218 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 |