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 don’t support merging in an information hash.

[ "Name", "Description", "Alias", "PayloadCompat" , "Stance"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#module_infoObject (protected)



57
58
59
# File 'lib/msf/core/module/module_info.rb', line 57

def module_info
  @module_info
end

Instance Method Details

#aliasObject

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

#descriptionObject

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_dateObject

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_fixupsObject (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))
    self.send("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 merge_info_advanced_options(info, val)
  merge_info_options(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
155
156
157
158
159
160
161
162
# File 'lib/msf/core/module/module_info.rb', line 152

def merge_info_description(info, val)
  key = 'Description'
  unless info[key]
    info[key] = val
    return
  end

  current_value = Msf::Serializer::ReadableText.word_wrap_description(info[key])
  new_value = Msf::Serializer::ReadableText.word_wrap_description(val)
  info[key] = current_value.end_with?('.') ? "#{current_value}\n#{val}" : "#{current_value}.\n\n#{new_value}"
end

#merge_info_evasion_options(info, val) ⇒ Object (protected)

Merges advanced options.



167
168
169
# File 'lib/msf/core/module/module_info.rb', line 167

def merge_info_evasion_options(info, val)
  merge_info_options(info, val, false, true)
end

#merge_info_name(info, val) ⇒ Object (protected)

Merges the module name.



174
175
176
# File 'lib/msf/core/module/module_info.rb', line 174

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.



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/msf/core/module/module_info.rb', line 181

def merge_info_options(info, val, advanced = false, evasion = false)

  key_name = ((advanced) ? 'Advanced' : (evasion) ? 'Evasion' : '') + 'Options'

  new_cont = Msf::OptionContainer.new
  new_cont.add_options(val, advanced, evasion)
  cur_cont = Msf::OptionContainer.new
  cur_cont.add_options(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.



201
202
203
204
205
206
207
208
209
210
211
# File 'lib/msf/core/module/module_info.rb', line 201

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.



216
217
218
# File 'lib/msf/core/module/module_info.rb', line 216

def merge_info_version(info, val)
  merge_info_string(info, 'Version', val)
end

#nameObject

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

#notesObject

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.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# File 'lib/msf/core/module/module_info.rb', line 226

def update_info(info, opts)
  opts.each_pair do |name, val|
    # If the supplied option name is one of the ones that we should
    # override by default
    if UpdateableOptions.include?(name)
      # 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
  end

  info
end