Class: Rex::Post::Meterpreter::ExtensionMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rex/post/meterpreter/extension_mapper.rb

Constant Summary collapse

@@klasses =
{}

Class Method Summary collapse

Class Method Details

.dump_extensionsObject


35
36
37
38
39
40
41
42
43
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 35

def self.dump_extensions
  base = ::File.join(File.dirname(__dir__), 'meterpreter/extensions')
  names = ::Dir.entries(base).select { |e|
    ::File.directory?(::File.join(base, e)) && !['.', '..'].include?(e)
  }
  names.each { |n|
    STDERR.puts("EXTENSION_ID_#{n.upcase} = #{self.get_extension_id(n)}\n")
  }
end

.get_extension_id(name) ⇒ Object


11
12
13
14
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 11

def self.get_extension_id(name)
  k = self.get_extension_klass(name)
  k.extension_id
end

.get_extension_klass(name) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 16

def self.get_extension_klass(name)
  name.downcase!

  unless @@klasses[name]
    begin
      require("rex/post/meterpreter/extensions/#{name}/#{name}")
    rescue LoadError
      # the extension doesn't exist on disk
      raise RuntimeError, "Unable to load extension '#{name}' - module does not exist."
    end
    s = Rex::Post::Meterpreter::Extensions.constants.select { |c|
      name == c.to_s.downcase
    }[0]
    @@klasses[name] =  Rex::Post::Meterpreter::Extensions.const_get(s).const_get(s)
  end

  @@klasses[name]
end