From 558b6300b1c770938050a3407808d23acb3b7405 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Sat, 9 Jul 2005 23:48:41 +0000 Subject: [PATCH] fixed the module loader a bit, still needs more work git-svn-id: file:///home/svn/incoming/trunk@2698 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/module_manager.rb | 49 ++++++------------- modules/encoders/x86/jmp_call_additive.rb | 2 +- modules/nops/x86/single_byte.rb | 2 +- .../payloads/stagers/windows/reverse_tcp.rb | 5 +- modules/payloads/stages/windows/shell.rb | 5 +- 5 files changed, 22 insertions(+), 41 deletions(-) diff --git a/lib/msf/core/module_manager.rb b/lib/msf/core/module_manager.rb index c123492bde..abd126a6d0 100644 --- a/lib/msf/core/module_manager.rb +++ b/lib/msf/core/module_manager.rb @@ -183,30 +183,18 @@ protected # Substitute the base path path_base = file.sub(path + File::SEPARATOR, '') - # Extract the type of module - md = path_base.match(/^(.*?)#{File::SEPARATOR}/) + # Chop off the file name + path_base.sub!(/(.+)(#{File::SEPARATOR}.+\.rb)$/, '\1') - next if (!md) + # Extract the module's namespace from its path + mod = mod_from_name(path_base) + type = path_base.match(/^(.+?)#{File::SEPARATOR}+?/)[1].sub(/s$/, '') - # Use the de-pluralized version of the type as necessary - type = md[1].sub(/s$/, '').downcase - - md = path_base.match(/^(.*)#{File::SEPARATOR}(.*?)$/) - - next if (!md) - - # Prefix Msf to the namespace - namespace = 'Msf::' + md[1].gsub(File::SEPARATOR, "::") - - dlog("Loading #{type} module from #{path_base}...", 'core', LEV_1) + # Let's rock the house now... + dlog("Loading module from #{path_base}...", 'core', LEV_1) # Get the module and grab the current number of constants - old_constants = [] - mod = mod_from_name(namespace) - - if (mod) - old_constants = mod.constants - end + old_constants = mod.constants # Load the file begin @@ -219,14 +207,6 @@ protected next end - # Incase we hadn't gotten the module yet... - mod = mod_from_name(namespace) - - if (!mod) - elog("Load did not create expected namespace #{namespace}.") - next - end - added = mod.constants - old_constants if (added.length > 1) @@ -286,14 +266,17 @@ protected # Returns the module object that is associated with the supplied module # name def mod_from_name(name) - obj = Object + obj = Msf + + name.split(File::SEPARATOR).each { |m| + # Up-case the first letter and any prefixed by _ + m.gsub!(/^[a-z]/) { |s| s.upcase } + m.gsub!(/(_[a-z])/) { |s| s[1..1].upcase } - name.split('::').each { |m| begin obj = obj.const_get(m) rescue NameError - obj = nil - break + obj = obj.const_set(m, ::Module.new) end } @@ -304,7 +287,7 @@ protected # categorized accordingly def on_module_load(type, mod) # Extract the module name information - mod_full_name = mod.to_s.gsub('::', '_') + mod_full_name = mod.to_s.gsub('::', '/') mod_full_name.sub!(/^Msf_/, '') mod_short_name = mod_full_name diff --git a/modules/encoders/x86/jmp_call_additive.rb b/modules/encoders/x86/jmp_call_additive.rb index 4c6409e713..d9edbf53b2 100644 --- a/modules/encoders/x86/jmp_call_additive.rb +++ b/modules/encoders/x86/jmp_call_additive.rb @@ -2,7 +2,7 @@ require 'msf/core' module Msf module Encoders -module IA32 +module Ia32 class JmpCallAdditive < Msf::Encoder::XorAdditiveFeedback diff --git a/modules/nops/x86/single_byte.rb b/modules/nops/x86/single_byte.rb index e6bf6f394a..c5364b00c0 100644 --- a/modules/nops/x86/single_byte.rb +++ b/modules/nops/x86/single_byte.rb @@ -2,7 +2,7 @@ require 'msf/core' module Msf module Nops -module IA32 +module Ia32 ### # diff --git a/modules/payloads/stagers/windows/reverse_tcp.rb b/modules/payloads/stagers/windows/reverse_tcp.rb index 7b8b65bbad..0ff18211df 100644 --- a/modules/payloads/stagers/windows/reverse_tcp.rb +++ b/modules/payloads/stagers/windows/reverse_tcp.rb @@ -2,9 +2,8 @@ require 'msf/core' module Msf module Payloads +module Stagers module Windows -module IA32 -module Stager module ReverseTcp @@ -52,4 +51,4 @@ module ReverseTcp end -end end end end end +end end end end diff --git a/modules/payloads/stages/windows/shell.rb b/modules/payloads/stages/windows/shell.rb index 76907ec029..1fc749d9a7 100644 --- a/modules/payloads/stages/windows/shell.rb +++ b/modules/payloads/stages/windows/shell.rb @@ -2,9 +2,8 @@ require 'msf/core' module Msf module Payloads +module Stages module Windows -module IA32 -module Stage module Shell @@ -42,4 +41,4 @@ module Shell end -end end end end end +end end end end