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


66
67
68
69
70
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 66

def self.dump_extensions
  self.get_extension_names.each { |n|
    STDERR.puts("EXTENSION_ID_#{n.upcase} = #{self.get_extension_id(n)}\n")
  }
end

.get_extension_id(name) ⇒ Object


18
19
20
21
22
23
24
25
26
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 18

def self.get_extension_id(name)
  begin
    k = self.get_extension_klass(name)
  rescue RuntimeError
    return nil
  end

  k.extension_id
end

.get_extension_klass(name) ⇒ Object


55
56
57
58
59
60
61
62
63
64
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 55

def self.get_extension_klass(name)
  name.downcase!

  unless @@klasses[name]
    mod = self.get_extension_module(name)
    @@klasses[name] = mod.const_get(mod.name.split('::').last)
  end

  @@klasses[name]
end

.get_extension_module(name) ⇒ Object


42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 42

def self.get_extension_module(name)
  name.downcase!

  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.find { |c| name == c.to_s.downcase }
  Rex::Post::Meterpreter::Extensions.const_get(s)
end

.get_extension_name(id) ⇒ Object


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 28

def self.get_extension_name(id)
  id = id - (id % COMMAND_ID_RANGE)

  self.get_extension_names.find do |name|
    begin
      klass = self.get_extension_klass(name)
    rescue RuntimeError
      next
    end

    klass.extension_id == id
  end
end

.get_extension_namesObject


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

def self.get_extension_names
  base = ::File.join(File.dirname(__dir__), 'meterpreter/extensions')
  ::Dir.entries(base).select do |e|
    ::File.directory?(::File.join(base, e)) && !['.', '..'].include?(e)
  end
end