Class: Rex::Post::Meterpreter::ExtensionMapper
- Inherits:
-
Object
- Object
- Rex::Post::Meterpreter::ExtensionMapper
- Defined in:
- lib/rex/post/meterpreter/extension_mapper.rb
Constant Summary collapse
- @@klasses =
{}
Class Method Summary collapse
- .dump_extensions ⇒ Object
-
.get_extension_id(name) ⇒ Integer?
Get the numeric ID for the specified extension name.
-
.get_extension_klass(name) ⇒ Class
Get the class for the specified extension name.
- .get_extension_klasses ⇒ Object
-
.get_extension_module(name) ⇒ Module
Get the module for the specified extension name.
-
.get_extension_name(id) ⇒ String?
Get the string extension name for the specified extension ID.
-
.get_extension_names ⇒ Array<String>
Get the names of all of the extensions.
Class Method Details
.dump_extensions ⇒ Object
96 97 98 99 100 |
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 96 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) ⇒ Integer?
Get the numeric ID for the specified extension name.
26 27 28 29 30 31 32 33 34 |
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 26 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) ⇒ Class
Get the class for the specified extension name.
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 81 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_klasses ⇒ Object
92 93 94 |
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 92 def self.get_extension_klasses self.get_extension_names.map { |name| self.get_extension_module(name) } end |
.get_extension_module(name) ⇒ Module
Get the module for the specified extension name.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 61 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) ⇒ String?
Get the string extension name for the specified extension ID.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 40 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_names ⇒ Array<String>
Get the names of all of the extensions.
14 15 16 17 18 19 |
# File 'lib/rex/post/meterpreter/extension_mapper.rb', line 14 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 |