added ambiguous module name detection

git-svn-id: file:///home/svn/incoming/trunk@2754 4d416f70-5f16-0410-b530-b9f4589650da
unstable
Matt Miller 2005-07-14 20:05:41 +00:00
parent fd02a5de71
commit aa778d7a99
8 changed files with 70 additions and 5 deletions

View File

@ -60,7 +60,11 @@ class Encoder < Module
# Encoder information accessors that can be overriden
# by derived classes
#
def self.type
return MODULE_ENCODER
end
def type
return MODULE_ENCODER
end

View File

@ -225,6 +225,10 @@ class Exploit < Msf::Module
#
# The module's type
#
def self.type
MODULE_EXPLOIT
end
def type
MODULE_EXPLOIT
end

View File

@ -21,6 +21,13 @@ class Module
class <<self
include Framework::Offspring
#
# Class method to figure out what type of module this is
#
def type
raise NotImplementedError
end
#
# The module's name that is assigned it it by the framework
# or derived from the path that the module is loaded from.

View File

@ -26,12 +26,18 @@ class ModuleSet < Hash
self.mod_sorted = nil
self.mod_ranked = nil
self.mod_extensions = []
self.mod_ambiguous = {}
end
#
# Create an instance of the supplied module by its name
#
def create(name)
if (mod_ambiguous[name])
raise Rex::AmbiguousArgumentError.new(name),
"The module name #{name} is ambiguous.", caller
end
klass = self[name]
instance = nil
@ -145,7 +151,13 @@ protected
dup.framework = framework
dup.refname = name
self[name] = dup
if (self[name])
mod_ambiguous[name] = true
wlog("The module #{dup.name} is ambiguous with #{self[name].name}.")
else
self[name] = dup
end
# Notify the framework that a module was loaded
framework.events.on_module_load(name, dup)
@ -165,7 +177,7 @@ protected
attr_writer :module_type
attr_accessor :mod_arch_hash, :mod_platform_hash
attr_accessor :mod_sorted, :mod_ranked
attr_accessor :mod_extensions
attr_accessor :mod_extensions, :mod_ambiguous
end
@ -215,6 +227,20 @@ class ModuleManager < ModuleSet
super
end
#
# Creates a module using the supplied name
#
def create(name)
# Check to see if it has a module type prefix. If it does,
# try to load it from the specific module set for that type.
if (md = name.match(/^(#{MODULE_TYPES.join('|')})\/(.*)$/))
module_sets[md[1]].create(md[2])
# Otherwise, just try to load it by name.
else
super
end
end
#
# Accessors by module type
#

View File

@ -13,6 +13,10 @@ module Msf
class Nop < Msf::Module
# NOP module, bitch!
def self.type
return MODULE_NOP
end
def type
return MODULE_NOP
end

View File

@ -42,6 +42,10 @@ class Payload < Msf::Module
#
# This module is a payload.
#
def self.type
return MODULE_PAYLOAD
end
def type
return MODULE_PAYLOAD
end

View File

@ -349,11 +349,14 @@ class Core
print_error("Failed to load module: #{mod_name}")
return false
end
rescue Rex::AmbiguousArgumentError => info
print_error(info.to_s)
rescue NameError => info
log_error("The supplied module name is ambiguous: #{$!}.")
return false
end
return false if (mod == nil)
# Enstack the command dispatcher for this module type
dispatcher = nil
@ -384,7 +387,7 @@ class Core
self.active_module = mod
# Update the command prompt
driver.update_prompt("#{mod.type}(#{mod_name}) ")
driver.update_prompt("#{mod.type}(#{mod.refname}) ")
end
#
@ -408,6 +411,7 @@ protected
framework.modules.each_module { |refname, mod|
self.tab_complete_items << refname
self.tab_complete_items << mod.type + '/' + refname
}
end

View File

@ -56,6 +56,18 @@ class ArgumentParseError < ::ArgumentError
end
end
class AmbiguousArgumentError < ::RuntimeError
include Exception
def initialize(name)
@name = name
end
def to_s
"The name #{@name} is ambiguous."
end
end
#####
#####
##