2005-07-09 21:18:49 +00:00
|
|
|
require 'msf/core'
|
2005-05-22 07:14:16 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
#
|
|
|
|
# Define used for a place-holder module that is used to indicate that the
|
2008-10-02 05:23:59 +00:00
|
|
|
# module has not yet been demand-loaded. Soon to go away.
|
2006-02-21 03:10:58 +00:00
|
|
|
#
|
|
|
|
SymbolicModule = "__SYMBOLIC__"
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
|
2005-05-22 07:14:16 +00:00
|
|
|
###
|
|
|
|
#
|
|
|
|
# A module set contains zero or more named module classes of an arbitrary
|
|
|
|
# type.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class ModuleSet < Hash
|
2005-07-13 18:06:12 +00:00
|
|
|
|
|
|
|
include Framework::Offspring
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Initializes a module set that will contain modules of a specific type and
|
|
|
|
# expose the mechanism necessary to create instances of them.
|
|
|
|
#
|
2005-05-22 07:58:02 +00:00
|
|
|
def initialize(type = nil)
|
2005-05-22 07:46:41 +00:00
|
|
|
self.module_type = type
|
|
|
|
|
|
|
|
# Hashes that convey the supported architectures and platforms for a
|
|
|
|
# given module
|
|
|
|
self.mod_arch_hash = {}
|
|
|
|
self.mod_platform_hash = {}
|
2005-07-11 05:15:30 +00:00
|
|
|
self.mod_sorted = nil
|
2005-07-13 18:06:12 +00:00
|
|
|
self.mod_ranked = nil
|
2005-07-14 06:34:58 +00:00
|
|
|
self.mod_extensions = []
|
2005-07-14 20:05:41 +00:00
|
|
|
self.mod_ambiguous = {}
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
#
|
|
|
|
# Wrapper that detects if a symbolic module is in use. If it is, it
|
|
|
|
# creates an instance to demand load the module and then returns the
|
|
|
|
# now-loaded class afterwords.
|
|
|
|
#
|
|
|
|
def [](name)
|
|
|
|
if (get_hash_val(name) == SymbolicModule)
|
|
|
|
create(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
get_hash_val(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the hash value associated with the supplied module name without
|
|
|
|
# throwing an exception.
|
|
|
|
#
|
|
|
|
def get_hash_val(name)
|
2009-06-25 17:59:51 +00:00
|
|
|
fetch(name) if has_key?(name)
|
2006-02-21 03:10:58 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
# Create an instance of the supplied module by its name
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
def create(name)
|
2008-01-06 20:25:09 +00:00
|
|
|
|
|
|
|
# if (mod_ambiguous[name])
|
|
|
|
# raise Rex::AmbiguousArgumentError.new(name),
|
|
|
|
# "The module name #{name} is ambiguous.", caller
|
|
|
|
# end
|
2005-07-14 20:05:41 +00:00
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
klass = get_hash_val(name)
|
2005-07-14 06:34:58 +00:00
|
|
|
instance = nil
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
# If there is no module associated with this class, then try to demand
|
|
|
|
# load it.
|
|
|
|
if (klass.nil? or klass == SymbolicModule)
|
|
|
|
# If we are the root module set, then we need to try each module
|
|
|
|
# type's demand loading until we find one that works for us.
|
|
|
|
if (module_type.nil?)
|
|
|
|
MODULE_TYPES.each { |type|
|
|
|
|
framework.modules.demand_load_module(type + '/' + name)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
framework.modules.demand_load_module(module_type + '/' + name)
|
|
|
|
end
|
|
|
|
|
|
|
|
klass = get_hash_val(name)
|
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
# If the klass is valid for this name, try to create it
|
2006-02-21 03:10:58 +00:00
|
|
|
if (klass and klass != SymbolicModule)
|
2005-07-14 06:34:58 +00:00
|
|
|
instance = klass.new
|
|
|
|
end
|
|
|
|
|
|
|
|
# Notify any general subscribers of the creation event
|
|
|
|
if (instance)
|
|
|
|
self.framework.events.on_module_created(instance)
|
|
|
|
end
|
|
|
|
|
|
|
|
return instance
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-10-01 21:51:45 +00:00
|
|
|
#
|
|
|
|
# Checks to see if the supplied module name is valid.
|
|
|
|
#
|
|
|
|
def valid?(name)
|
2006-02-21 03:10:58 +00:00
|
|
|
# If we're using cache, then we need to pre-create an instance of this.
|
|
|
|
create(name) if (using_cache)
|
|
|
|
|
2005-10-01 21:51:45 +00:00
|
|
|
(self[name]) ? true : false
|
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Enumerates each module class in the set.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:46:41 +00:00
|
|
|
def each_module(opts = {}, &block)
|
2006-02-21 03:10:58 +00:00
|
|
|
demand_load_modules
|
|
|
|
|
2005-07-11 05:15:30 +00:00
|
|
|
mod_sorted = self.sort if (mod_sorted == nil)
|
2005-07-13 18:06:12 +00:00
|
|
|
|
|
|
|
each_module_list(mod_sorted, opts, &block)
|
|
|
|
end
|
|
|
|
|
2005-10-01 21:51:45 +00:00
|
|
|
#
|
|
|
|
# Enumerates each module class in the set based on their relative ranking
|
|
|
|
# to one another. Modules that are ranked higher are shown first.
|
|
|
|
#
|
2005-07-13 18:06:12 +00:00
|
|
|
def each_module_ranked(opts = {}, &block)
|
2006-02-21 03:10:58 +00:00
|
|
|
demand_load_modules
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
mod_ranked = rank_modules if (mod_ranked == nil)
|
|
|
|
|
|
|
|
each_module_list(mod_ranked, opts, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Custom each_module filtering if an advanced set supports doing extended
|
|
|
|
# filtering. Returns true if the entry should be filtered.
|
|
|
|
#
|
|
|
|
def each_module_filter(opts, name, entry)
|
|
|
|
return false
|
|
|
|
end
|
2005-07-11 05:15:30 +00:00
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Dummy placeholder to relcalculate aliases and other fun things.
|
2005-07-13 18:06:12 +00:00
|
|
|
#
|
|
|
|
def recalculate
|
|
|
|
end
|
|
|
|
|
2007-08-11 00:37:50 +00:00
|
|
|
#
|
|
|
|
# Gives the module set an opportunity to handle a module reload event
|
|
|
|
#
|
|
|
|
def on_module_reload(mod)
|
|
|
|
end
|
|
|
|
|
2007-06-16 05:04:03 +00:00
|
|
|
#
|
|
|
|
# Forces all modules in this set to be loaded.
|
|
|
|
#
|
|
|
|
def force_load_set
|
|
|
|
each_module { |name, mod|
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
attr_reader :module_type
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
#
|
|
|
|
# Whether or not recalculations should be postponed. This is used from the
|
|
|
|
# context of the each_module_list handler in order to prevent the demand
|
|
|
|
# loader from calling recalc for each module if it's possible that more
|
|
|
|
# than one module may be loaded. This field is not initialized until used.
|
|
|
|
#
|
|
|
|
attr_accessor :postpone_recalc
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
protected
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
#
|
|
|
|
# Load all modules that are marked as being symbolic.
|
|
|
|
#
|
|
|
|
def demand_load_modules
|
|
|
|
# Pre-scan the module list for any symbolic modules
|
|
|
|
self.each_pair { |name, mod|
|
|
|
|
if (mod == SymbolicModule)
|
|
|
|
self.postpone_recalc = true
|
|
|
|
|
|
|
|
mod = create(name)
|
|
|
|
|
|
|
|
next if (mod.nil?)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# If we found any symbolic modules, then recalculate.
|
|
|
|
if (self.postpone_recalc)
|
|
|
|
self.postpone_recalc = false
|
|
|
|
|
|
|
|
recalculate
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
#
|
|
|
|
# Enumerates the modules in the supplied array with possible limiting
|
|
|
|
# factors.
|
|
|
|
#
|
|
|
|
def each_module_list(ary, opts, &block)
|
|
|
|
ary.each { |entry|
|
2005-07-11 05:15:30 +00:00
|
|
|
name, mod = entry
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
# Skip any lingering symbolic modules.
|
|
|
|
next if (mod == SymbolicModule)
|
|
|
|
|
2005-05-22 07:46:41 +00:00
|
|
|
# Filter out incompatible architectures
|
2005-07-13 18:06:12 +00:00
|
|
|
if (opts['Arch'])
|
2005-05-22 07:46:41 +00:00
|
|
|
if (!mod_arch_hash[mod])
|
|
|
|
mod_arch_hash[mod] = mod.new.arch
|
|
|
|
end
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
next if ((mod_arch_hash[mod] & opts['Arch']).empty? == true)
|
2005-05-22 07:46:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Filter out incompatible platforms
|
2005-07-13 18:06:12 +00:00
|
|
|
if (opts['Platform'])
|
2005-05-22 07:46:41 +00:00
|
|
|
if (!mod_platform_hash[mod])
|
|
|
|
mod_platform_hash[mod] = mod.new.platform
|
|
|
|
end
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
next if ((mod_platform_hash[mod] & opts['Platform']).empty? == true)
|
2005-05-22 07:46:41 +00:00
|
|
|
end
|
|
|
|
|
2005-07-12 05:39:44 +00:00
|
|
|
# Custom filtering
|
|
|
|
next if (each_module_filter(opts, name, entry) == true)
|
|
|
|
|
2005-07-10 00:49:12 +00:00
|
|
|
block.call(name, mod)
|
2005-05-22 07:46:41 +00:00
|
|
|
}
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
2008-10-02 05:23:59 +00:00
|
|
|
|
2005-05-22 07:14:16 +00:00
|
|
|
|
2005-07-12 05:39:44 +00:00
|
|
|
#
|
2005-07-13 18:06:12 +00:00
|
|
|
# Ranks modules based on their constant rank value, if they have one.
|
2005-07-12 05:39:44 +00:00
|
|
|
#
|
2005-07-13 18:06:12 +00:00
|
|
|
def rank_modules
|
|
|
|
mod_ranked = self.sort { |a, b|
|
|
|
|
a_name, a_mod = a
|
|
|
|
b_name, b_mod = b
|
|
|
|
|
|
|
|
# Extract the ranking between the two modules
|
2005-07-13 21:09:07 +00:00
|
|
|
a_rank = a[1].const_defined?('Rank') ? a[1].const_get('Rank') : NormalRanking
|
|
|
|
b_rank = b[1].const_defined?('Rank') ? b[1].const_get('Rank') : NormalRanking
|
2005-07-13 18:06:12 +00:00
|
|
|
|
|
|
|
# Compare their relevant rankings. Since we want highest to lowest,
|
|
|
|
# we compare b_rank to a_rank in terms of higher/lower precedence
|
|
|
|
b_rank <=> a_rank
|
|
|
|
}
|
2005-07-12 05:39:44 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Adds a module with a the supplied name.
|
2005-07-13 18:06:12 +00:00
|
|
|
#
|
2009-05-29 13:46:12 +00:00
|
|
|
def add_module(mod, name, modinfo = nil)
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
|
2005-07-10 19:21:40 +00:00
|
|
|
# Set the module's name so that it can be referenced when
|
|
|
|
# instances are created.
|
2009-05-29 13:46:12 +00:00
|
|
|
mod.framework = framework
|
|
|
|
mod.refname = name
|
|
|
|
mod.file_path = ((modinfo and modinfo['files']) ? modinfo['files'][0] : nil)
|
|
|
|
mod.orig_cls = mod
|
2005-07-10 19:21:40 +00:00
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
if (get_hash_val(name) and get_hash_val(name) != SymbolicModule)
|
2005-07-14 20:05:41 +00:00
|
|
|
mod_ambiguous[name] = true
|
|
|
|
|
2009-05-29 13:46:12 +00:00
|
|
|
wlog("The module #{mod.refname} is ambiguous with #{self[name].refname}.")
|
2005-07-14 20:05:41 +00:00
|
|
|
else
|
2009-05-29 13:46:12 +00:00
|
|
|
self[name] = mod
|
2005-07-14 20:05:41 +00:00
|
|
|
end
|
2006-02-21 03:10:58 +00:00
|
|
|
|
2006-02-24 15:47:10 +00:00
|
|
|
# Check to see if we should update info
|
|
|
|
noup = true if (modinfo and modinfo['noup'])
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
# Add this module to the module cache for this type
|
2009-05-29 13:46:12 +00:00
|
|
|
framework.modules.cache_module(mod) if (noup != true)
|
2005-10-31 15:56:59 +00:00
|
|
|
|
2005-07-11 05:15:30 +00:00
|
|
|
# Invalidate the sorted array
|
2006-02-21 03:10:58 +00:00
|
|
|
invalidate_sorted_cache
|
2005-10-31 15:56:59 +00:00
|
|
|
|
2009-05-29 13:46:12 +00:00
|
|
|
# Return the modlicated instance for use
|
|
|
|
mod
|
2005-07-13 18:06:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Invalidates the sorted and ranked module caches.
|
|
|
|
#
|
2006-02-21 03:10:58 +00:00
|
|
|
def invalidate_sorted_cache
|
2005-07-11 05:15:30 +00:00
|
|
|
mod_sorted = nil
|
2005-07-13 18:06:12 +00:00
|
|
|
mod_ranked = nil
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-07-09 19:35:29 +00:00
|
|
|
attr_writer :module_type
|
2005-05-22 07:46:41 +00:00
|
|
|
attr_accessor :mod_arch_hash, :mod_platform_hash
|
2005-07-13 18:06:12 +00:00
|
|
|
attr_accessor :mod_sorted, :mod_ranked
|
2005-07-14 20:05:41 +00:00
|
|
|
attr_accessor :mod_extensions, :mod_ambiguous
|
2005-05-22 07:14:16 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# Upper management decided to throw in some middle management
|
|
|
|
# because the modules were getting out of hand. This bad boy
|
|
|
|
# takes care of the work of managing the interaction with
|
|
|
|
# modules in terms of loading and instantiation.
|
|
|
|
#
|
2005-05-22 07:23:25 +00:00
|
|
|
# TODO:
|
|
|
|
#
|
|
|
|
# - add unload support
|
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
###
|
2005-05-22 07:58:02 +00:00
|
|
|
class ModuleManager < ModuleSet
|
2005-05-22 07:14:16 +00:00
|
|
|
|
2005-07-09 21:18:49 +00:00
|
|
|
require 'msf/core/payload_set'
|
2005-07-09 00:24:02 +00:00
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
include Framework::Offspring
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Initializes an instance of the overall module manager using the supplied
|
2009-01-02 07:29:56 +00:00
|
|
|
# framework instance. The types parameter can be used to only load specific
|
|
|
|
# module types on initialization
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
2009-01-02 07:29:56 +00:00
|
|
|
def initialize(framework,types=MODULE_TYPES)
|
2005-05-22 07:14:16 +00:00
|
|
|
self.module_paths = []
|
|
|
|
self.module_history = {}
|
|
|
|
self.module_history_mtime = {}
|
2005-05-22 07:58:02 +00:00
|
|
|
self.module_sets = {}
|
2006-09-16 06:27:14 +00:00
|
|
|
self.module_failed = {}
|
2009-01-02 07:29:56 +00:00
|
|
|
self.enabled_types = {}
|
2005-07-14 06:34:58 +00:00
|
|
|
self.framework = framework
|
2005-05-22 07:14:16 +00:00
|
|
|
|
2009-01-02 07:29:56 +00:00
|
|
|
types.each { |type|
|
|
|
|
self.enabled_types[type] = true
|
2005-07-09 00:24:02 +00:00
|
|
|
case type
|
|
|
|
when MODULE_PAYLOAD
|
|
|
|
instance = PayloadSet.new(self)
|
|
|
|
else
|
|
|
|
instance = ModuleSet.new(type)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.module_sets[type] = instance
|
2005-07-13 18:06:12 +00:00
|
|
|
|
|
|
|
# Set the module set's framework reference
|
2005-07-14 06:34:58 +00:00
|
|
|
instance.framework = framework
|
2005-05-22 07:14:16 +00:00
|
|
|
}
|
2005-05-22 07:58:02 +00:00
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
super(nil)
|
2006-07-19 07:24:47 +00:00
|
|
|
|
|
|
|
@modcache_invalidated = false
|
|
|
|
@cached_counts = false
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 20:05:41 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Creates a module using the supplied name.
|
2005-07-14 20:05:41 +00:00
|
|
|
#
|
|
|
|
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
|
|
|
|
|
2005-05-22 07:23:25 +00:00
|
|
|
#
|
|
|
|
# Accessors by module type
|
|
|
|
#
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Returns the set of loaded encoder module classes.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
def encoders
|
2005-05-22 07:58:02 +00:00
|
|
|
return module_sets[MODULE_ENCODER]
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Returns the set of loaded exploit module classes.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
def exploits
|
2005-05-22 07:58:02 +00:00
|
|
|
return module_sets[MODULE_EXPLOIT]
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Returns the set of loaded nop module classes.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:25:15 +00:00
|
|
|
def nops
|
2005-05-22 20:28:21 +00:00
|
|
|
return module_sets[MODULE_NOP]
|
2005-05-22 07:25:15 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Returns the set of loaded payload module classes.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:23:25 +00:00
|
|
|
def payloads
|
2005-05-22 07:58:02 +00:00
|
|
|
return module_sets[MODULE_PAYLOAD]
|
2005-05-22 07:23:25 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2006-01-24 03:59:44 +00:00
|
|
|
# Returns the set of loaded auxiliary module classes.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2006-01-24 03:59:44 +00:00
|
|
|
def auxiliary
|
|
|
|
return module_sets[MODULE_AUX]
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2006-09-16 06:27:14 +00:00
|
|
|
#
|
|
|
|
# Returns the set of modules that failed to load.
|
|
|
|
#
|
|
|
|
def failed
|
|
|
|
return module_failed
|
|
|
|
end
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
##
|
|
|
|
#
|
|
|
|
# Module cache management to support demand loaded modules.
|
|
|
|
#
|
|
|
|
##
|
|
|
|
|
|
|
|
#
|
|
|
|
# Sets the path that the module cache information is loaded from and
|
|
|
|
# synchronized with. This method should be called prior to loading any
|
|
|
|
# modules in order to take advantage of caching information.
|
|
|
|
#
|
|
|
|
def set_module_cache_file(file_path)
|
|
|
|
@modcache_file = file_path
|
|
|
|
@modcache = Rex::Parser::Ini.new
|
|
|
|
|
|
|
|
begin
|
|
|
|
@modcache.from_file(@modcache_file)
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
@modcache_invalidated = true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Initialize the standard groups
|
|
|
|
@modcache.add_group('FileModificationTimes', false)
|
|
|
|
@modcache.add_group('ModuleTypeCounts', false)
|
|
|
|
|
|
|
|
MODULE_TYPES.each { |type|
|
|
|
|
@modcache.add_group(type, false)
|
|
|
|
|
|
|
|
@modcache[type].each_key { |name|
|
2009-01-02 07:29:56 +00:00
|
|
|
next if not @modcache[type]
|
|
|
|
next if not module_sets[type]
|
|
|
|
|
2006-02-21 17:17:25 +00:00
|
|
|
fullname = type + '/' + name
|
|
|
|
|
|
|
|
# Make sure the files associated with this module exist. If it
|
|
|
|
# doesn't, then we don't create a symbolic module for it. This is
|
|
|
|
# to ensure that module counts are accurately reflected after a
|
|
|
|
# module is removed or moved.
|
|
|
|
next if (@modcache.group?(fullname) == false)
|
|
|
|
next if (@modcache[fullname]['FileNames'].nil?)
|
|
|
|
|
|
|
|
begin
|
|
|
|
@modcache[fullname]['FileNames'].split(',').each { |f|
|
|
|
|
File::Stat.new(f)
|
|
|
|
}
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
dlog("File requirement does not exist for #{fullname}", 'core',
|
|
|
|
LEV_1);
|
|
|
|
next
|
|
|
|
end
|
2006-02-21 03:10:58 +00:00
|
|
|
module_sets[type][name] = SymbolicModule
|
|
|
|
}
|
|
|
|
}
|
2008-11-16 19:26:59 +00:00
|
|
|
|
|
|
|
if(not (@modcache['ModuleTypeCounts'] and @modcache['ModuleTypeCounts'].keys.length > 0))
|
|
|
|
@modcache_invalidated = true
|
|
|
|
end
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns true if the module cache is currently being used.
|
|
|
|
#
|
|
|
|
def using_cache
|
|
|
|
(@modcache_invalidated != true)
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the cached module counts by type if the cache is being used.
|
|
|
|
#
|
|
|
|
def cached_counts
|
|
|
|
if (using_cache and @modcache.group?('ModuleTypeCounts'))
|
2006-07-19 07:24:47 +00:00
|
|
|
if (! @cached_counts)
|
2006-02-21 03:10:58 +00:00
|
|
|
@cached_counts = {}
|
|
|
|
|
|
|
|
@modcache['ModuleTypeCounts'].each_pair { |type, count|
|
|
|
|
@cached_counts[type] = count.to_i
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
return @cached_counts
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Persists the current contents of the module cache to disk.
|
|
|
|
#
|
|
|
|
def save_module_cache
|
|
|
|
if (@modcache)
|
|
|
|
if (@modcache.group?('ModuleTypeCounts'))
|
|
|
|
@modcache['ModuleTypeCounts'].clear
|
|
|
|
|
|
|
|
MODULE_TYPES.each { |type|
|
2009-01-02 07:29:56 +00:00
|
|
|
next if not @modcache['ModuleTypeCounts'][type]
|
2006-02-21 03:10:58 +00:00
|
|
|
@modcache['ModuleTypeCounts'][type] = module_sets[type].length.to_s
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
@modcache.to_file(@modcache_file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Checks to make sure the cache state is okay. If it's not, the cache is
|
|
|
|
# cleared and all modules are forced to be loaded. If the cached mtime for
|
|
|
|
# the file is the same as the current mtime, then we don't load it until
|
|
|
|
# it's needed on demand.
|
|
|
|
#
|
|
|
|
def check_cache(file)
|
|
|
|
# If the module cache has been invalidated, then we return false to
|
|
|
|
# indicate that we should go ahead and load the file now.
|
|
|
|
return false if (@modcache_invalidated)
|
|
|
|
|
|
|
|
if (@modcache and @modcache.group?('FileModificationTimes'))
|
2006-02-21 16:36:58 +00:00
|
|
|
no_exist = false
|
2006-02-21 03:10:58 +00:00
|
|
|
|
2006-02-21 16:36:58 +00:00
|
|
|
begin
|
|
|
|
curr_mtime = File::Stat.new(file).mtime
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
no_exist = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if (no_exist or
|
|
|
|
@modcache['FileModificationTimes'][file].nil? or
|
2006-02-21 03:10:58 +00:00
|
|
|
@modcache['FileModificationTimes'][file].to_s != curr_mtime.to_i.to_s)
|
|
|
|
raise ModuleCacheInvalidated, "File #{file} has a new mtime or did not exist"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Invalidates the current cache.
|
|
|
|
#
|
|
|
|
def invalidate_cache
|
|
|
|
@modcache_invalidated = true
|
|
|
|
|
|
|
|
# Clear the module cache.
|
|
|
|
if (@modcache)
|
|
|
|
@modcache['FileModificationTimes'].clear
|
|
|
|
@modcache['ModuleTypeCounts'].clear
|
|
|
|
|
|
|
|
MODULE_TYPES.each { |type|
|
|
|
|
@modcache[type].clear
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Synchronizes the module cache information
|
|
|
|
#
|
2008-10-02 05:23:59 +00:00
|
|
|
def update_module_cache_info(fullname, mod, modinfo)
|
2006-03-07 07:05:41 +00:00
|
|
|
return if (modinfo and modinfo['noup'] == true)
|
2008-10-02 05:23:59 +00:00
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
if (@modcache)
|
|
|
|
if (fullname)
|
|
|
|
@modcache.add_group(fullname)
|
|
|
|
@modcache[fullname].clear
|
|
|
|
@modcache[fullname]['FileNames'] = modinfo['files'].join(',')
|
|
|
|
@modcache[fullname]['FilePaths'] = modinfo['paths'].join(',')
|
|
|
|
@modcache[fullname]['Type'] = modinfo['type']
|
2008-10-02 05:23:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Deep cache classes (ignore payloads)
|
|
|
|
# if(mod.class == ::Class and mod.cached?)
|
|
|
|
# @modcache[fullname]['CacheData'] = [Marshal.dump(mod.infos)].pack("m").gsub(/\s+/, '')
|
|
|
|
# end
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
end
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
modinfo['files'].each do |f|
|
2006-02-21 17:17:25 +00:00
|
|
|
begin
|
2008-10-02 05:23:59 +00:00
|
|
|
@modcache['FileModificationTimes'][f] = File::Stat.new(f).mtime.to_i.to_s
|
2006-02-21 17:17:25 +00:00
|
|
|
rescue Errno::ENOENT
|
|
|
|
end
|
2008-10-02 05:23:59 +00:00
|
|
|
end
|
2006-02-21 03:10:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Caches this module under a specific module type and name
|
|
|
|
#
|
|
|
|
def cache_module(mod)
|
|
|
|
@modcache[mod.type][mod.refname] = 1
|
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
##
|
2005-05-22 07:14:16 +00:00
|
|
|
#
|
|
|
|
# Module path management
|
|
|
|
#
|
2005-07-14 06:34:58 +00:00
|
|
|
##
|
2005-05-22 07:14:16 +00:00
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2007-02-24 03:32:32 +00:00
|
|
|
# Adds a path to be searched for new modules. If check_cache is false,
|
|
|
|
# all modules in the specified path will be demand loaded. Furthermore,
|
|
|
|
# their loading will not impact the module path.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2007-02-24 03:32:32 +00:00
|
|
|
def add_module_path(path, check_cache = true)
|
2005-06-04 08:23:16 +00:00
|
|
|
path.sub!(/#{File::SEPARATOR}$/, '')
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
# Make sure the path is a valid directory before we try to rock the
|
|
|
|
# house
|
|
|
|
if (File.directory?(path) == false)
|
2006-04-15 20:26:41 +00:00
|
|
|
raise RuntimeError, "The path supplied is not a valid directory.",
|
2005-07-14 06:34:58 +00:00
|
|
|
caller
|
|
|
|
end
|
|
|
|
|
2005-05-22 07:14:16 +00:00
|
|
|
module_paths << path
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
begin
|
2007-02-24 03:32:32 +00:00
|
|
|
counts = load_modules(path, !check_cache)
|
2006-02-21 03:10:58 +00:00
|
|
|
rescue ModuleCacheInvalidated
|
|
|
|
invalidate_cache
|
|
|
|
|
|
|
|
# Re-load all the modules now that the cache has been invalidated
|
|
|
|
module_paths.each { |p|
|
2006-02-21 17:58:21 +00:00
|
|
|
counts = load_modules(p, true)
|
2006-02-21 03:10:58 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Synchronize the module cache if the module cache is not being used.
|
2007-02-24 03:32:32 +00:00
|
|
|
# We only do this if the caller wanted us to check the cache in the
|
|
|
|
# first place. By default, check_cache will be true. One scenario
|
|
|
|
# where it will be false is from the loadpath command in msfconsole.
|
2007-02-24 05:29:05 +00:00
|
|
|
if !using_cache and check_cache
|
|
|
|
save_module_cache
|
|
|
|
# If we're by default using the cache and we were told not to
|
|
|
|
# invalidate/use it, then we should update the cached counts to include
|
|
|
|
# what we've just added so that the banner will reflect the changes
|
|
|
|
# correctly.
|
|
|
|
elsif using_cache and !check_cache
|
|
|
|
cached_counts.each_key { |k|
|
|
|
|
cached_counts[k] += counts[k] if counts[k]
|
|
|
|
}
|
|
|
|
end
|
2006-02-21 03:10:58 +00:00
|
|
|
|
|
|
|
return counts
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Removes a path from which to search for modules.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
def remove_module_path(path)
|
|
|
|
module_paths.delete(path)
|
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
def register_type_extension(type, ext)
|
|
|
|
end
|
|
|
|
|
2005-10-10 00:30:14 +00:00
|
|
|
#
|
|
|
|
# Reloads the module specified in mod. This can either be an instance of a
|
|
|
|
# module or a module class.
|
|
|
|
#
|
|
|
|
def reload_module(mod)
|
|
|
|
refname = mod.refname
|
|
|
|
ds = mod.datastore.dup
|
|
|
|
|
|
|
|
dlog("Reloading module #{refname}...", 'core')
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
|
|
|
|
# Set the target file
|
|
|
|
file = mod.file_path
|
|
|
|
|
|
|
|
# Load the module into a new Module wrapper
|
|
|
|
begin
|
|
|
|
wrap = ::Module.new
|
|
|
|
wrap.module_eval(File.read(file, File.size(file)))
|
|
|
|
|
|
|
|
rescue ::Exception => e
|
|
|
|
elog("Failed to reload module from #{file}: #{e.class} #{e}")
|
|
|
|
self.module_failed[mod.file_path] = "Failed to reload the module"
|
|
|
|
return nil
|
2005-10-10 00:30:14 +00:00
|
|
|
end
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
if(not wrap.const_defined?('Metasploit3'))
|
|
|
|
elog("Reloaded file did not contain a valid module (#{file}).")
|
|
|
|
self.module_failed[mod.file_path] = "Failed to reload the module"
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
added = wrap.const_get('Metasploit3')
|
|
|
|
|
|
|
|
|
|
|
|
self.module_failed.delete(mod.file_path)
|
|
|
|
|
|
|
|
|
2005-10-10 00:30:14 +00:00
|
|
|
# Remove the original reference to this module
|
|
|
|
self.delete(mod.refname)
|
|
|
|
|
|
|
|
# Indicate that the module is being loaded again so that any necessary
|
|
|
|
# steps can be taken to extend it properly.
|
2008-10-02 05:23:59 +00:00
|
|
|
on_module_load(added, mod.type, refname, {
|
2006-02-24 15:47:10 +00:00
|
|
|
'files' => [ mod.file_path ],
|
|
|
|
'noup' => true})
|
2005-10-10 00:30:14 +00:00
|
|
|
|
|
|
|
# Create a new instance of the module
|
|
|
|
if (mod = create(refname))
|
|
|
|
mod.datastore.update(ds)
|
|
|
|
else
|
|
|
|
elog("Failed to create instance of #{refname} after reload.", 'core')
|
|
|
|
end
|
|
|
|
|
2007-08-11 00:37:50 +00:00
|
|
|
# Let the specific module sets have an opportunity to handle the fact
|
|
|
|
# that this module was reloaded. For instance, the payload module set
|
|
|
|
# will need to flush the blob cache entry associated with this module
|
|
|
|
module_sets[mod.type].on_module_reload(mod)
|
|
|
|
|
2005-10-10 00:30:14 +00:00
|
|
|
mod
|
|
|
|
end
|
|
|
|
|
2005-10-31 15:56:59 +00:00
|
|
|
#
|
|
|
|
# Overrides the module set method for adding a module so that some extra
|
|
|
|
# steps can be taken to subscribe the module and notify the event
|
|
|
|
# dispatcher.
|
|
|
|
#
|
2006-02-21 03:10:58 +00:00
|
|
|
def add_module(mod, name, file_paths)
|
2005-10-31 15:56:59 +00:00
|
|
|
# Call the module set implementation of add_module
|
|
|
|
dup = super
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
# If the module cache is not being used, update the cache with
|
|
|
|
# information about the files that are associated with this module.
|
|
|
|
if (!using_cache)
|
2008-10-02 05:23:59 +00:00
|
|
|
update_module_cache_info(dup.fullname, mod, file_paths)
|
2006-02-21 03:10:58 +00:00
|
|
|
end
|
|
|
|
|
2005-10-31 15:56:59 +00:00
|
|
|
# Automatically subscribe a wrapper around this module to the necessary
|
|
|
|
# event providers based on whatever events it wishes to receive. We
|
|
|
|
# only do this if we are the module manager instance, as individual
|
|
|
|
# module sets need not subscribe.
|
|
|
|
auto_subscribe_module(dup)
|
|
|
|
|
|
|
|
# Notify the framework that a module was loaded
|
|
|
|
framework.events.on_module_load(name, dup)
|
|
|
|
end
|
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
#
|
|
|
|
# Loads the files associated with a module and recalculates module
|
|
|
|
# associations.
|
|
|
|
#
|
|
|
|
def demand_load_module(fullname)
|
|
|
|
dlog("Demand loading module #{fullname}.", 'core', LEV_1)
|
|
|
|
|
|
|
|
return nil if (@modcache.group?(fullname) == false)
|
|
|
|
return nil if (@modcache[fullname]['FileNames'].nil?)
|
|
|
|
return nil if (@modcache[fullname]['FilePaths'].nil?)
|
|
|
|
|
|
|
|
type = fullname.split(/\//)[0]
|
|
|
|
files = @modcache[fullname]['FileNames'].split(',')
|
|
|
|
paths = @modcache[fullname]['FilePaths'].split(',')
|
|
|
|
|
|
|
|
files.each_with_index { |file, idx|
|
|
|
|
dlog("Loading from file #{file}", 'core', LEV_2)
|
|
|
|
|
|
|
|
load_module_from_file(paths[idx], file, nil, nil, nil, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (module_sets[type].postpone_recalc != true)
|
|
|
|
module_sets[type].recalculate
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-07-30 22:28:47 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Provide a list of the types of modules in the set
|
|
|
|
#
|
|
|
|
def module_types
|
|
|
|
module_sets.keys.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Provide a list of module names of a specific type
|
|
|
|
#
|
|
|
|
def module_names(set)
|
|
|
|
module_sets[set] ? module_sets[set].keys.dup : []
|
|
|
|
end
|
|
|
|
|
2005-05-22 07:14:16 +00:00
|
|
|
protected
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
# Load all of the modules from the supplied module path (independent of
|
2005-11-15 15:11:43 +00:00
|
|
|
# module type).
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2009-01-02 07:29:56 +00:00
|
|
|
def load_modules(bpath, demand = false)
|
2005-05-22 07:14:16 +00:00
|
|
|
loaded = {}
|
2005-07-09 00:24:02 +00:00
|
|
|
recalc = {}
|
2005-07-14 06:34:58 +00:00
|
|
|
counts = {}
|
2005-08-22 01:42:13 +00:00
|
|
|
delay = {}
|
|
|
|
ks = true
|
2009-01-02 07:29:56 +00:00
|
|
|
|
|
|
|
dbase = Dir.new(bpath)
|
|
|
|
dbase.entries.each do |ent|
|
2009-03-28 20:45:46 +00:00
|
|
|
next if ent.downcase == '.svn'
|
|
|
|
|
2009-01-02 07:29:56 +00:00
|
|
|
path = File.join(bpath, ent)
|
|
|
|
mtype = ent.gsub(/s$/, '')
|
2009-03-28 20:45:46 +00:00
|
|
|
|
2009-01-02 07:29:56 +00:00
|
|
|
next if not File.directory?(path)
|
|
|
|
next if not MODULE_TYPES.include?(mtype)
|
|
|
|
next if not enabled_types[mtype]
|
2005-05-22 07:14:16 +00:00
|
|
|
|
2009-01-02 07:29:56 +00:00
|
|
|
# Try to load modules from all the files in the supplied path
|
|
|
|
Rex::Find.find(path) do |file|
|
2006-08-28 00:24:34 +00:00
|
|
|
|
2009-01-02 07:29:56 +00:00
|
|
|
# Skip non-ruby files
|
2009-03-28 20:45:46 +00:00
|
|
|
next if file[-3,3] != ".rb"
|
2007-03-25 07:38:11 +00:00
|
|
|
|
2009-01-02 07:29:56 +00:00
|
|
|
# Skip unit test files
|
|
|
|
next if (file =~ /rb\.(ut|ts)\.rb$/)
|
|
|
|
|
|
|
|
# Skip files with a leading period
|
2009-03-28 20:45:46 +00:00
|
|
|
next if file[0,1] =="."
|
2009-01-02 07:29:56 +00:00
|
|
|
|
2009-03-28 20:45:46 +00:00
|
|
|
load_module_from_file(bpath, file, loaded, recalc, counts, demand)
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
2009-01-02 07:29:56 +00:00
|
|
|
end
|
2005-05-22 07:14:16 +00:00
|
|
|
|
2005-07-09 00:24:02 +00:00
|
|
|
# Perform any required recalculations for the individual module types
|
2008-10-02 05:23:59 +00:00
|
|
|
# that actually had load changes
|
2005-07-09 00:24:02 +00:00
|
|
|
recalc.each_key { |key|
|
2008-10-02 05:23:59 +00:00
|
|
|
module_sets[key].recalculate
|
2005-07-09 00:24:02 +00:00
|
|
|
}
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
# Return per-module loaded counts
|
|
|
|
return counts
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
2005-08-22 01:42:13 +00:00
|
|
|
# Loads a module from the supplied file.
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
2006-02-21 03:10:58 +00:00
|
|
|
def load_module_from_file(path, file, loaded, recalc, counts, demand = false)
|
2007-03-25 07:38:11 +00:00
|
|
|
|
2005-08-22 01:42:13 +00:00
|
|
|
# If the file on disk hasn't changed with what we have stored in the
|
|
|
|
# cache, then there's no sense in loading it
|
2006-02-21 17:58:21 +00:00
|
|
|
if (!has_module_file_changed?(file))
|
2007-03-25 07:38:11 +00:00
|
|
|
dlog("Cached module from file #{file} has not changed.", 'core', LEV_2)
|
2006-02-21 17:17:25 +00:00
|
|
|
return false
|
2005-08-22 01:42:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Substitute the base path
|
|
|
|
path_base = file.sub(path + File::SEPARATOR, '')
|
|
|
|
|
|
|
|
# Derive the name from the path with the exclusion of the .rb
|
|
|
|
name = path_base.match(/^(.+?)#{File::SEPARATOR}(.*)(.rb?)$/)[2]
|
|
|
|
|
|
|
|
# Chop off the file name
|
|
|
|
path_base.sub!(/(.+)(#{File::SEPARATOR}.+)(.rb?)$/, '\1')
|
|
|
|
|
2005-11-28 23:49:48 +00:00
|
|
|
if (m = path_base.match(/^(.+?)#{File::SEPARATOR}+?/))
|
|
|
|
type = m[1]
|
|
|
|
else
|
|
|
|
type = path_base
|
|
|
|
end
|
|
|
|
|
|
|
|
type.sub!(/s$/, '')
|
2005-08-22 01:42:13 +00:00
|
|
|
|
2008-09-24 04:15:10 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
added = nil
|
|
|
|
|
2005-08-22 01:42:13 +00:00
|
|
|
begin
|
2008-10-02 05:23:59 +00:00
|
|
|
wrap = ::Module.new
|
|
|
|
wrap.module_eval(File.read(file, File.size(file)))
|
2009-03-28 20:45:46 +00:00
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
rescue ::Exception => e
|
2009-07-27 03:40:45 +00:00
|
|
|
errmsg = "#{file}: #{e.class} #{e}"
|
2008-10-02 05:23:59 +00:00
|
|
|
self.module_failed[file] = errmsg
|
|
|
|
elog(errmsg)
|
Merged revisions 5366-5377 via svnmerge from
svn+ssh://metasploit.com/home/svn/framework3/branches/framework-3.1
........
r5366 | hdm | 2008-01-26 20:30:53 -0600 (Sat, 26 Jan 2008) | 2 lines
Update version information
........
r5367 | hdm | 2008-01-26 21:10:57 -0600 (Sat, 26 Jan 2008) | 3 lines
Updated for version 3.1
........
r5369 | hdm | 2008-01-26 21:13:31 -0600 (Sat, 26 Jan 2008) | 3 lines
Wipe the private directories from the branch.
........
r5371 | hdm | 2008-01-27 17:24:24 -0600 (Sun, 27 Jan 2008) | 5 lines
Timeout options added for dcerpc connect and read times. Addition of novell netware as a supported target platform. Inclusion of the serverprotect exploit (still works on the latest version). Addition of the first remote netware kernel exploit that leads to a shell, addition of netware stager and shell, and first draft of the release notes for 3.1
........
r5372 | hdm | 2008-01-27 17:30:08 -0600 (Sun, 27 Jan 2008) | 3 lines
Formatting, indentation, fixed the static IP embedded in the request
........
r5373 | hdm | 2008-01-27 20:02:48 -0600 (Sun, 27 Jan 2008) | 3 lines
Correctly trap exploit errors in a way that works with all of the UIs
........
r5374 | hdm | 2008-01-27 20:23:25 -0600 (Sun, 27 Jan 2008) | 3 lines
More last-minute bug fixes
........
r5375 | hdm | 2008-01-27 20:37:43 -0600 (Sun, 27 Jan 2008) | 3 lines
Force multi-bind off in netware, correct label display in gtk gui labels
........
r5376 | hdm | 2008-01-27 20:50:03 -0600 (Sun, 27 Jan 2008) | 3 lines
More exception handling fun
........
git-svn-id: file:///home/svn/framework3/trunk@5378 4d416f70-5f16-0410-b530-b9f4589650da
2008-01-28 03:06:31 +00:00
|
|
|
return false
|
2005-08-22 01:42:13 +00:00
|
|
|
end
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
if(not wrap.const_defined?('Metasploit3'))
|
|
|
|
errmsg = "Missing Metasploit3 constant"
|
|
|
|
self.module_failed[file] = errmsg
|
|
|
|
elog(errmsg)
|
2006-02-21 03:10:58 +00:00
|
|
|
return false
|
2005-08-22 01:42:13 +00:00
|
|
|
end
|
2008-10-02 05:23:59 +00:00
|
|
|
added = wrap.const_get('Metasploit3')
|
2005-08-22 01:42:13 +00:00
|
|
|
|
2005-11-02 14:18:50 +00:00
|
|
|
# If the module indicates that it is not usable on this system, then we
|
|
|
|
# will not try to use it.
|
|
|
|
usable = false
|
|
|
|
|
|
|
|
begin
|
2009-06-25 17:59:51 +00:00
|
|
|
usable = respond_to?(:is_usable) ? added.is_usable : true
|
2005-11-02 14:18:50 +00:00
|
|
|
rescue
|
|
|
|
elog("Exception caught during is_usable check: #{$!}")
|
|
|
|
end
|
|
|
|
|
2007-02-15 05:32:48 +00:00
|
|
|
# Synchronize the modification time for this file.
|
2008-10-02 05:23:59 +00:00
|
|
|
update_module_cache_info(nil, added, {
|
2007-02-15 05:32:48 +00:00
|
|
|
'paths' => [ path ],
|
|
|
|
'files' => [ file ],
|
|
|
|
'type' => type}) if (!using_cache)
|
|
|
|
|
2005-11-02 14:18:50 +00:00
|
|
|
if (usable == false)
|
2008-10-02 05:23:59 +00:00
|
|
|
ilog("Skipping module in #{file} because is_usable returned false.", 'core', LEV_1)
|
2006-02-21 03:10:58 +00:00
|
|
|
return false
|
2005-11-02 14:18:50 +00:00
|
|
|
end
|
|
|
|
|
2005-11-02 00:27:59 +00:00
|
|
|
ilog("Loaded #{type} module #{added} from #{file}.", 'core', LEV_2)
|
2006-09-16 06:27:14 +00:00
|
|
|
self.module_failed.delete(file)
|
|
|
|
|
2005-08-22 01:42:13 +00:00
|
|
|
# Do some processing on the loaded module to get it into the
|
|
|
|
# right associations
|
2006-02-21 03:10:58 +00:00
|
|
|
on_module_load(added, type, name, {
|
|
|
|
'files' => [ file ],
|
|
|
|
'paths' => [ path ],
|
|
|
|
'type' => type })
|
2005-08-22 01:42:13 +00:00
|
|
|
|
|
|
|
# Set this module type as needing recalculation
|
2006-02-21 03:10:58 +00:00
|
|
|
recalc[type] = true if (recalc)
|
2005-08-22 01:42:13 +00:00
|
|
|
|
|
|
|
# Append the added module to the hash of file->module
|
2006-02-21 03:10:58 +00:00
|
|
|
loaded[file] = added if (loaded)
|
2006-02-21 17:58:21 +00:00
|
|
|
|
|
|
|
# Track module load history for future reference
|
|
|
|
module_history[file] = added
|
|
|
|
module_history_mtime[file] = File::Stat.new(file).mtime.to_i
|
2005-08-22 01:42:13 +00:00
|
|
|
|
|
|
|
# The number of loaded modules this round
|
2006-02-21 03:10:58 +00:00
|
|
|
if (counts)
|
|
|
|
counts[type] = (counts[type]) ? (counts[type] + 1) : 1
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
2005-08-22 01:42:13 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
# Checks to see if the supplied file has changed (if it's even in the
|
2005-11-15 15:11:43 +00:00
|
|
|
# cache).
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
def has_module_file_changed?(file)
|
2006-02-21 16:36:58 +00:00
|
|
|
begin
|
2006-02-21 17:17:25 +00:00
|
|
|
return (module_history_mtime[file] != File::Stat.new(file).mtime.to_i)
|
2006-02-21 16:36:58 +00:00
|
|
|
rescue Errno::ENOENT
|
2006-02-21 17:17:25 +00:00
|
|
|
return true
|
2006-02-21 16:36:58 +00:00
|
|
|
end
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2005-05-22 07:14:16 +00:00
|
|
|
# Called when a module is initially loaded such that it can be
|
2005-11-15 15:11:43 +00:00
|
|
|
# categorized accordingly.
|
2005-07-14 06:34:58 +00:00
|
|
|
#
|
2006-02-21 03:10:58 +00:00
|
|
|
def on_module_load(mod, type, name, modinfo)
|
2005-07-09 00:24:02 +00:00
|
|
|
# Payload modules require custom loading as the individual files
|
|
|
|
# may not directly contain a logical payload that a user would
|
|
|
|
# reference, such as would be the case with a payload stager or
|
|
|
|
# stage. As such, when payload modules are loaded they are handed
|
|
|
|
# off to a special payload set. The payload set, in turn, will
|
|
|
|
# automatically create all the permutations after all the payload
|
|
|
|
# modules have been loaded.
|
|
|
|
if (type != MODULE_PAYLOAD)
|
|
|
|
# Add the module class to the list of modules and add it to the
|
|
|
|
# type separated set of module classes
|
2006-02-21 03:10:58 +00:00
|
|
|
add_module(mod, name, modinfo)
|
2005-07-09 00:24:02 +00:00
|
|
|
end
|
2005-07-11 05:15:30 +00:00
|
|
|
|
2006-02-21 03:10:58 +00:00
|
|
|
module_sets[type].add_module(mod, name, modinfo)
|
2005-05-22 07:14:16 +00:00
|
|
|
end
|
|
|
|
|
2005-10-31 15:56:59 +00:00
|
|
|
#
|
|
|
|
# This method automatically subscribes a module to whatever event providers
|
|
|
|
# it wishes to monitor. This can be used to allow modules to automatically
|
|
|
|
# execute or perform other tasks when certain events occur. For instance,
|
2006-01-24 03:59:44 +00:00
|
|
|
# when a new host is detected, other aux modules may wish to run such
|
2005-10-31 15:56:59 +00:00
|
|
|
# that they can collect more information about the host that was detected.
|
|
|
|
#
|
|
|
|
def auto_subscribe_module(mod)
|
|
|
|
# If auto-subscribe has been disabled
|
|
|
|
if (framework.datastore['DisableAutoSubscribe'] and
|
|
|
|
framework.datastore['DisableAutoSubscribe'] =~ /^(y|1|t)/)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# If auto-subscription is enabled (which it is by default), figure out
|
|
|
|
# if it subscribes to any particular interfaces.
|
|
|
|
inst = nil
|
|
|
|
|
|
|
|
#
|
|
|
|
# Exploit event subscriber check
|
|
|
|
#
|
|
|
|
if (mod.include?(ExploitEvent) == true)
|
|
|
|
framework.events.add_exploit_subscriber((inst) ? inst : (inst = mod.new))
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Session event subscriber check
|
|
|
|
#
|
|
|
|
if (mod.include?(SessionEvent) == true)
|
|
|
|
framework.events.add_session_subscriber((inst) ? inst : (inst = mod.new))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
attr_accessor :modules, :module_sets # :nodoc:
|
|
|
|
attr_accessor :module_paths # :nodoc:
|
|
|
|
attr_accessor :module_history, :module_history_mtime # :nodoc:
|
2006-09-16 06:27:14 +00:00
|
|
|
attr_accessor :module_failed # :nodoc:
|
2009-01-02 07:29:56 +00:00
|
|
|
attr_accessor :enabled_types # :nodoc:
|
2005-05-22 07:14:16 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-11-16 19:26:59 +00:00
|
|
|
end
|