Module: Metasploit::Model::Platform

Extended by:
ActiveModel::Naming, ActiveSupport::Concern
Includes:
Translation
Defined in:
lib/metasploit/model/platform.rb

Overview

Code shared between Mdm::Platform and Metasploit::Framework::Platform.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

SEED_RELATIVE_NAME_TREE =

Platforms are seeded in a hierarchy with deeper levels refining higher levels, so 'Windows 98 SE' is a refinement of 'Windows 98', which is a refinement of 'Windows'.

{
    'AIX' => nil,
    'Android' => nil,
    'BSD' => nil,
    'BSDi' => nil,
    'Cisco' => nil,
    'Firefox' => nil,
    'FreeBSD' => nil,
    'HPUX' => nil,
    'IRIX' => nil,
    'Java' => nil,
    'Javascript' => nil,
    'Linux' => nil,
    'NetBSD' => nil,
    'Netware' => nil,
    'NodeJS' => nil,
    'OpenBSD' => nil,
    'OSX' => nil,
    'PHP' => nil,
    'Python' => nil,
    'Ruby' => nil,
    'Solaris' => {
        '4' => nil,
        '5' => nil,
        '6' => nil,
        '7' => nil,
        '8' => nil,
        '9' => nil,
        '10' => nil
    },
    'Windows' => {
        '95' => nil,
        '98' => {
            'FE' => nil,
            'SE' => nil
        },
        'ME' => nil,
        'NT' => {
            'SP0' => nil,
            'SP1' => nil,
            'SP2' => nil,
            'SP3' => nil,
            'SP4' => nil,
            'SP5' => nil,
            'SP6' => nil,
            'SP6a' => nil
        },
        '2000' => {
           'SP0' => nil,
           'SP1' => nil,
           'SP2' => nil,
           'SP3' => nil,
           'SP4' => nil
        },
        'XP' => {
            'SP0' => nil,
            'SP1' => nil,
            'SP2' => nil,
            'SP3' => nil
        },
        '2003' => {
            'SP0' => nil,
            'SP1' => nil
        },
        'Vista' => {
            'SP0' => nil,
            'SP1' => nil
        },
        '7' => nil
    },
    'UNIX' => nil
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fully_qualified_nameString

The fully qualified name of this platform, as would be used in the platform list in a metasploit-framework module.

Returns:

  • (String)


# File 'lib/metasploit/model/platform.rb', line 142

#parentnil, Metasploit::Model::Platform

The parent platform of this platform. For example, Windows is parent of Windows 98, which is the parent of Windows 98 FE.

Returns:



# File 'lib/metasploit/model/platform.rb', line 148

#relative_nameString

The name of this platform relative to the #fully_qualified_name of #parent.

Returns:

  • (String)


# File 'lib/metasploit/model/platform.rb', line 155

Class Method Details

.each_seed_attributes(options = {}) {|attributes| ... } ⇒ void

Note:

Not defined in ClassMethods because consumers should always refer back to Metasploit::Model::Platform when seeding.

This method returns an undefined value.

Parameters:

  • options (Hash{Symbol => Object, Hash}) (defaults to: {})

Options Hash (options):

  • :parent (Object) — default: nil

    The parent object to which to attach the children.

  • :grandchildren_by_child_relative_name (Hash{String => nil,Hash}) — default: {SEED_RELATIVE_NAME_TREE}

    Maps #relative_name of children under :parent to their children (grandchildren of parent). Grandchildren can be nil or another recursive Hash of names and their descendants.

Yields:

  • (attributes)

    Block should construct child object using attributes.

Yield Parameters:

  • attributes (Hash{Symbol => Object,String})

    Hash containing attributes for child object, include :parent for #parent and :relative_name for #relative_name.

Yield Returns:

  • (Object)

    child derived from :parent and :relative_name to be used as the parent for grandchildren.



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/metasploit/model/platform.rb', line 194

def self.each_seed_attributes(options={}, &block)
  options.assert_valid_keys(:parent, :grandchildren_by_child_relative_name)

  parent = options[:parent]
  grandchildren_by_child_relative_name = options.fetch(
      :grandchildren_by_child_relative_name,
      SEED_RELATIVE_NAME_TREE
  )

  grandchildren_by_child_relative_name.each do |child_relative_name, great_grandchildren_by_grandchild_relative_name|
    attributes = {
        parent: parent,
        relative_name: child_relative_name
    }
    child = block.call(attributes)

    if great_grandchildren_by_grandchild_relative_name
      each_seed_attributes(
          grandchildren_by_child_relative_name: great_grandchildren_by_grandchild_relative_name,
          parent: child,
          &block
      )
    end
  end
end

.fully_qualified_name_setArray<String>

List of valid #fully_qualified_name derived from SEED_RELATIVE_NAME_TREE.

Returns:

  • (Array<String>)


223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/metasploit/model/platform.rb', line 223

def self.fully_qualified_name_set
  unless instance_variable_defined? :@fully_qualified_name_set
    @fully_qualified_name_set = Set.new

    each_seed_attributes do |attributes|
      parent = attributes.fetch(:parent)
      relative_name = attributes.fetch(:relative_name)

      if parent
        fully_qualified_name = "#{parent} #{relative_name}"
      else
        fully_qualified_name = relative_name
      end

      @fully_qualified_name_set.add fully_qualified_name

      # yieldreturn
      fully_qualified_name
    end

    @fully_qualified_name_set.freeze
  end

  @fully_qualified_name_set
end

Instance Method Details

#derived_fully_qualified_namenil, String

Returns:



169
170
171
172
173
174
175
176
177
# File 'lib/metasploit/model/platform.rb', line 169

def derived_fully_qualified_name
  if relative_name.present?
    if parent
      "#{parent.fully_qualified_name} #{relative_name}"
    else
      relative_name
    end
  end
end