Module: Msf::Modules::Namespace

Defined in:
lib/msf/core/modules/namespace.rb

Overview

Concern for behavior that all namespace modules that wrap Msf::Modules must support like version checking and grabbing the version specific-Metasploit* class.

Instance Method Summary collapse

Instance Method Details

#metasploit_classMsf::Module?

Note:

The module content must be module_evalled into this namespace module before the return of #metasploit_class is valid.

Returns the Metasploit(3|2|1) class from the module_evalled content.


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/msf/core/modules/namespace.rb', line 11

def metasploit_class
  metasploit_class = nil

  ::Msf::Framework::Major.downto(1) do |major|
    # Since we really only care about the deepest namespace, we don't
    # need to look for parents' constants. However, the "inherit"
    # parameter for const_defined? only exists after 1.9. If we ever
    # drop 1.8 support, we can save a few cycles here by passing false
    # here.
    if const_defined?("Metasploit#{major}")
      metasploit_class = const_get("Metasploit#{major}")

      break
    end
  end

  metasploit_class
end

#metasploit_class!(module_path, module_reference_name) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/msf/core/modules/namespace.rb', line 30

def metasploit_class!(module_path, module_reference_name)
  metasploit_class = self.metasploit_class

  unless metasploit_class
    raise Msf::Modules::MetasploitClassCompatibilityError.new(
              :module_path => module_path,
              :module_reference_name => module_reference_name
          )
  end

  metasploit_class
end

#version_compatible!(module_path, module_reference_name) ⇒ void

Note:

The module content must be module_evalled into this namespace module using module_eval_with_lexical_scope before calling #version_compatible! is valid.

This method returns an undefined value.

Raises an error unless Framework::VersionCore and Framework::VersionAPI meet the minimum required versions defined in RequiredVersions in the module content.

Raises:


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/msf/core/modules/namespace.rb', line 54

def version_compatible!(module_path, module_reference_name)
  if const_defined?(:RequiredVersions)
    required_versions = const_get(:RequiredVersions)
    minimum_core_version = required_versions[0]
    minimum_api_version = required_versions[1]

    if (minimum_core_version > ::Msf::Framework::VersionCore or
        minimum_api_version > ::Msf::Framework::VersionAPI)
      raise Msf::Modules::VersionCompatibilityError.new(
                :module_path => module_path,
                :module_reference_name => module_reference_name,
                :minimum_api_version => minimum_api_version,
                :minimum_core_version => minimum_core_version
            )
    end
  end
end