2012-06-29 05:18:28 +00:00
|
|
|
# -*- coding: binary -*-
|
2005-07-09 21:18:49 +00:00
|
|
|
require 'msf/core'
|
2005-05-21 17:57:00 +00:00
|
|
|
|
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# The module base class is responsible for providing the common interface
|
|
|
|
# that is used to interact with modules at the most basic levels, such as
|
|
|
|
# by inspecting a given module's attributes (name, dsecription, version,
|
|
|
|
# authors, etc) and by managing the module's data store.
|
|
|
|
#
|
|
|
|
###
|
|
|
|
class Module
|
|
|
|
|
2005-07-17 07:06:05 +00:00
|
|
|
# Modules can subscribe to a user-interface, and as such they include the
|
|
|
|
# UI subscriber module. This provides methods like print, print_line, etc.
|
|
|
|
# User interfaces are designed to be medium independent, and as such the
|
|
|
|
# user interface subscribes are designed to provide a flexible way of
|
|
|
|
# interacting with the user, n stuff.
|
|
|
|
include Rex::Ui::Subscriber
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-07-11 20:49:33 +00:00
|
|
|
# Make include public so we can runtime extend
|
|
|
|
public_class_method :include
|
|
|
|
|
2009-11-16 02:39:08 +00:00
|
|
|
class << self
|
2005-07-13 18:06:12 +00:00
|
|
|
include Framework::Offspring
|
|
|
|
|
2005-07-14 20:05:41 +00:00
|
|
|
#
|
|
|
|
# Class method to figure out what type of module this is
|
|
|
|
#
|
|
|
|
def type
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2005-07-15 22:30:04 +00:00
|
|
|
def fullname
|
|
|
|
return type + '/' + refname
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2006-07-29 22:37:39 +00:00
|
|
|
def shortname
|
|
|
|
return refname.split('/')[-1]
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-10-01 21:26:17 +00:00
|
|
|
#
|
|
|
|
# Returns this module's ranking.
|
|
|
|
#
|
|
|
|
def rank
|
|
|
|
(const_defined?('Rank')) ? const_get('Rank') : NormalRanking
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-10-01 21:26:17 +00:00
|
|
|
#
|
|
|
|
# Returns this module's ranking as a string representation.
|
|
|
|
#
|
|
|
|
def rank_to_s
|
|
|
|
RankingName[rank]
|
|
|
|
end
|
|
|
|
|
2009-12-06 14:35:16 +00:00
|
|
|
#
|
|
|
|
# Returns this module's ranking as a string for display.
|
|
|
|
#
|
|
|
|
def rank_to_h
|
|
|
|
rank_to_s.gsub('Rank', '').downcase
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
#
|
2005-07-10 19:21:40 +00:00
|
|
|
# The module's name that is assigned it it by the framework
|
|
|
|
# or derived from the path that the module is loaded from.
|
|
|
|
#
|
|
|
|
attr_accessor :refname
|
2005-10-10 00:30:14 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# This attribute holds the non-duplicated copy of the module
|
|
|
|
# implementation. This attribute is used for reloading purposes so that
|
|
|
|
# it can be re-duplicated.
|
|
|
|
#
|
|
|
|
attr_accessor :orig_cls
|
|
|
|
|
|
|
|
#
|
|
|
|
# The path from which the module was loaded.
|
|
|
|
#
|
|
|
|
attr_accessor :file_path
|
2005-07-10 19:21:40 +00:00
|
|
|
end
|
|
|
|
|
2005-07-13 18:06:12 +00:00
|
|
|
#
|
|
|
|
# Returns the class reference to the framework
|
|
|
|
#
|
|
|
|
def framework
|
|
|
|
return self.class.framework
|
|
|
|
end
|
|
|
|
|
2005-11-02 14:18:50 +00:00
|
|
|
#
|
|
|
|
# This method allows modules to tell the framework if they are usable
|
|
|
|
# on the system that they are being loaded on in a generic fashion.
|
|
|
|
# By default, all modules are indicated as being usable. An example of
|
|
|
|
# where this is useful is if the module depends on something external to
|
|
|
|
# ruby, such as a binary.
|
|
|
|
#
|
|
|
|
def self.is_usable
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2011-05-12 20:03:55 +00:00
|
|
|
require 'msf/core/module/author'
|
|
|
|
require 'msf/core/module/platform_list'
|
|
|
|
require 'msf/core/module/reference'
|
|
|
|
require 'msf/core/module/target'
|
|
|
|
require 'msf/core/module/auxiliary_action'
|
|
|
|
require 'msf/core/module/has_actions'
|
2005-06-05 00:03:23 +00:00
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Creates an instance of an abstract module using the supplied information
|
|
|
|
# hash.
|
|
|
|
#
|
2005-06-04 22:26:42 +00:00
|
|
|
def initialize(info = {})
|
2010-07-14 20:16:22 +00:00
|
|
|
@module_info_copy = info.dup
|
|
|
|
|
2005-06-04 22:26:42 +00:00
|
|
|
self.module_info = info
|
2010-07-07 16:37:23 +00:00
|
|
|
generate_uuid
|
2005-05-21 17:57:00 +00:00
|
|
|
|
|
|
|
set_defaults
|
|
|
|
|
2005-10-19 01:48:10 +00:00
|
|
|
# Initialize module compatibility hashes
|
|
|
|
init_compat
|
|
|
|
|
2009-10-17 05:25:29 +00:00
|
|
|
# Fixup module fields as needed
|
|
|
|
info_fixups
|
|
|
|
|
2005-05-21 17:57:00 +00:00
|
|
|
# Transform some of the fields to arrays as necessary
|
2005-06-05 00:03:23 +00:00
|
|
|
self.author = Author.transform(module_info['Author'])
|
2009-10-17 05:25:29 +00:00
|
|
|
self.arch = Rex::Transformer.transform(module_info['Arch'], Array, [ String ], 'Arch')
|
2005-06-05 00:33:38 +00:00
|
|
|
self.platform = PlatformList.transform(module_info['Platform'])
|
2009-10-17 05:25:29 +00:00
|
|
|
self.references = Rex::Transformer.transform(module_info['References'], Array, [ SiteReference, Reference ], 'Ref')
|
2005-05-21 17:57:00 +00:00
|
|
|
|
2005-05-21 18:27:24 +00:00
|
|
|
# Create and initialize the option container for this module
|
|
|
|
self.options = OptionContainer.new
|
2005-06-05 23:45:58 +00:00
|
|
|
self.options.add_options(info['Options'], self.class)
|
|
|
|
self.options.add_advanced_options(info['AdvancedOptions'], self.class)
|
2006-01-05 03:57:12 +00:00
|
|
|
self.options.add_evasion_options(info['EvasionOptions'], self.class)
|
2005-05-21 18:27:24 +00:00
|
|
|
|
|
|
|
# Create and initialize the data store for this module
|
2005-07-14 06:34:58 +00:00
|
|
|
self.datastore = ModuleDataStore.new(self)
|
2005-06-05 05:42:14 +00:00
|
|
|
|
2007-02-21 03:07:12 +00:00
|
|
|
# Import default options into the datastore
|
|
|
|
import_defaults
|
2005-07-11 15:34:31 +00:00
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
self.privileged = module_info['Privileged'] || false
|
2006-01-22 19:25:55 +00:00
|
|
|
self.license = module_info['License'] || MSF_LICENSE
|
2010-02-22 17:54:44 +00:00
|
|
|
|
|
|
|
# Allow all modules to track their current workspace
|
|
|
|
register_advanced_options(
|
|
|
|
[
|
2011-07-15 15:33:35 +00:00
|
|
|
OptString.new('WORKSPACE', [ false, "Specify the workspace for this module" ]),
|
|
|
|
OptBool.new('VERBOSE', [ false, 'Enable detailed status messages', false ])
|
2010-02-22 17:54:44 +00:00
|
|
|
], Msf::Module)
|
2011-07-15 15:33:35 +00:00
|
|
|
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2009-03-28 05:49:33 +00:00
|
|
|
#
|
|
|
|
# Creates a fresh copy of an instantiated module
|
|
|
|
#
|
|
|
|
def replicant
|
2010-07-14 20:16:22 +00:00
|
|
|
|
2010-07-14 17:06:12 +00:00
|
|
|
obj = self.class.new
|
2010-08-07 05:57:58 +00:00
|
|
|
self.instance_variables.each { |k|
|
|
|
|
v = instance_variable_get(k)
|
2010-07-14 20:16:22 +00:00
|
|
|
v = v.dup rescue v
|
2010-08-07 05:57:58 +00:00
|
|
|
obj.instance_variable_set(k, v)
|
|
|
|
}
|
2010-07-14 20:16:22 +00:00
|
|
|
|
2010-07-06 17:59:36 +00:00
|
|
|
obj.datastore = self.datastore.copy
|
2010-02-22 17:54:44 +00:00
|
|
|
obj.user_input = self.user_input
|
|
|
|
obj.user_output = self.user_output
|
2010-07-14 20:18:39 +00:00
|
|
|
obj.module_store = self.module_store.clone
|
2009-03-28 05:49:33 +00:00
|
|
|
obj
|
|
|
|
end
|
2005-07-15 22:30:04 +00:00
|
|
|
|
2009-08-18 03:02:37 +00:00
|
|
|
#
|
2011-02-26 02:35:38 +00:00
|
|
|
# Overwrite the Subscriber print_(status|error|good) to do time stamps
|
2009-08-18 03:02:37 +00:00
|
|
|
#
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2011-07-04 20:09:32 +00:00
|
|
|
def print_prefix
|
2013-06-11 21:14:03 +00:00
|
|
|
if (datastore['TimestampOutput'] =~ /^(t|y|1)/i) || (
|
|
|
|
framework && framework.datastore['TimestampOutput'] =~ /^(t|y|1)/i
|
2009-08-18 03:02:37 +00:00
|
|
|
)
|
2010-09-23 02:16:29 +00:00
|
|
|
prefix = "[#{Time.now.strftime("%Y.%m.%d-%H:%M:%S")}] "
|
|
|
|
|
|
|
|
xn ||= datastore['ExploitNumber']
|
|
|
|
xn ||= framework.datastore['ExploitNumber']
|
|
|
|
if xn.is_a?(Fixnum)
|
|
|
|
prefix << "[%04d] " % xn
|
|
|
|
end
|
|
|
|
|
2011-02-26 02:35:38 +00:00
|
|
|
return prefix
|
2013-06-10 21:02:19 +00:00
|
|
|
else
|
|
|
|
return ''
|
2009-08-18 03:02:37 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2009-08-18 03:02:37 +00:00
|
|
|
def print_status(msg='')
|
2009-11-10 03:27:48 +00:00
|
|
|
super(print_prefix + msg)
|
2009-08-18 03:02:37 +00:00
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2009-08-18 03:02:37 +00:00
|
|
|
def print_error(msg='')
|
2009-11-10 03:27:48 +00:00
|
|
|
super(print_prefix + msg)
|
2009-08-18 03:02:37 +00:00
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2010-04-04 22:48:35 +00:00
|
|
|
def print_good(msg='')
|
|
|
|
super(print_prefix + msg)
|
|
|
|
end
|
2011-02-26 02:35:38 +00:00
|
|
|
|
2012-10-13 02:48:15 +00:00
|
|
|
def print_warning(msg='')
|
|
|
|
super(print_prefix + msg)
|
|
|
|
end
|
|
|
|
|
2011-02-26 02:35:38 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Overwrite the Subscriber print_line to do custom prefixes
|
|
|
|
#
|
|
|
|
|
|
|
|
def print_line_prefix
|
2011-07-04 20:09:32 +00:00
|
|
|
datastore['CustomPrintPrefix'] || framework.datastore['CustomPrintPrefix'] || ''
|
2011-02-26 02:35:38 +00:00
|
|
|
end
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2011-02-26 02:35:38 +00:00
|
|
|
def print_line(msg='')
|
|
|
|
super(print_line_prefix + msg)
|
|
|
|
end
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2011-07-15 15:33:35 +00:00
|
|
|
# Verbose version of #print_status
|
|
|
|
def vprint_status(msg)
|
|
|
|
print_status(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
|
|
|
|
end
|
|
|
|
# Verbose version of #print_error
|
|
|
|
def vprint_error(msg)
|
|
|
|
print_error(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
|
|
|
|
end
|
|
|
|
# Verbose version of #print_good
|
|
|
|
def vprint_good(msg)
|
|
|
|
print_good(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
|
|
|
|
end
|
|
|
|
# Verbose version of #print_line
|
|
|
|
def vprint_line(msg)
|
|
|
|
print_line(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
|
|
|
|
end
|
2011-10-09 05:34:30 +00:00
|
|
|
# Verbose version of #print_debug
|
|
|
|
def vprint_debug(msg)
|
|
|
|
print_debug(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
|
|
|
|
end
|
2012-10-13 02:48:15 +00:00
|
|
|
# Verbose version of #print_warning
|
|
|
|
def vprint_warning(msg)
|
|
|
|
print_warning(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE']
|
|
|
|
end
|
2011-07-15 15:33:35 +00:00
|
|
|
|
2005-07-15 22:30:04 +00:00
|
|
|
#
|
|
|
|
# Returns the module's framework full reference name. This is the
|
|
|
|
# short name that end-users work with (refname) plus the type
|
|
|
|
# of module prepended. Ex:
|
|
|
|
#
|
|
|
|
# payloads/windows/shell/reverse_tcp
|
|
|
|
#
|
|
|
|
def fullname
|
|
|
|
return self.class.fullname
|
|
|
|
end
|
|
|
|
|
2005-07-10 19:21:40 +00:00
|
|
|
#
|
2005-07-15 22:30:04 +00:00
|
|
|
# Returns the module's framework reference name. This is the
|
2009-11-03 18:09:05 +00:00
|
|
|
# short name that end-users work with. Ex:
|
2005-07-10 19:21:40 +00:00
|
|
|
#
|
2005-07-15 22:30:04 +00:00
|
|
|
# windows/shell/reverse_tcp
|
2005-07-10 19:21:40 +00:00
|
|
|
#
|
|
|
|
def refname
|
|
|
|
return self.class.refname
|
|
|
|
end
|
2005-05-21 17:57:00 +00:00
|
|
|
|
2006-09-12 05:34:58 +00:00
|
|
|
#
|
|
|
|
# Returns the module's rank.
|
|
|
|
#
|
|
|
|
def rank
|
|
|
|
return self.class.rank
|
|
|
|
end
|
|
|
|
|
2009-12-06 14:35:16 +00:00
|
|
|
#
|
|
|
|
# Returns the module's rank in string format.
|
|
|
|
#
|
|
|
|
def rank_to_s
|
|
|
|
return self.class.rank_to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Returns the module's rank in display format.
|
|
|
|
#
|
|
|
|
def rank_to_h
|
|
|
|
return self.class.rank_to_h
|
|
|
|
end
|
|
|
|
|
2006-07-29 22:37:39 +00:00
|
|
|
#
|
|
|
|
# Returns the module's framework short name. This is a
|
|
|
|
# possibly conflicting name used for things like console
|
|
|
|
# prompts.
|
|
|
|
#
|
|
|
|
# reverse_tcp
|
|
|
|
#
|
|
|
|
def shortname
|
|
|
|
return self.class.shortname
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-10-10 00:30:14 +00:00
|
|
|
#
|
|
|
|
# Returns the unduplicated class associated with this module.
|
|
|
|
#
|
|
|
|
def orig_cls
|
|
|
|
return self.class.orig_cls
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# The path to the file in which the module can be loaded from.
|
|
|
|
#
|
|
|
|
def file_path
|
|
|
|
self.class.file_path
|
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-02 14:18:50 +00:00
|
|
|
# Return the module's name from the module information hash.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def name
|
2005-10-19 01:48:10 +00:00
|
|
|
module_info['Name']
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
|
|
|
|
2005-07-07 23:11:03 +00:00
|
|
|
#
|
|
|
|
# Returns the module's alias, if it has one. Otherwise, the module's
|
|
|
|
# name is returned.
|
|
|
|
#
|
|
|
|
def alias
|
2005-10-19 01:48:10 +00:00
|
|
|
module_info['Alias']
|
2005-07-07 23:11:03 +00:00
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Return the module's description.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def description
|
2005-10-19 01:48:10 +00:00
|
|
|
module_info['Description']
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
|
|
|
|
2010-06-25 04:21:23 +00:00
|
|
|
#
|
|
|
|
# Returns the disclosure date, if known.
|
|
|
|
#
|
|
|
|
def disclosure_date
|
2010-11-03 15:31:28 +00:00
|
|
|
date_str = Date.parse(module_info['DisclosureDate'].to_s) rescue nil
|
2010-06-25 04:21:23 +00:00
|
|
|
end
|
|
|
|
|
2013-05-23 16:40:04 +00:00
|
|
|
#
|
|
|
|
# Checks to see if the target is vulnerable, returning unsupported if it's
|
|
|
|
# not supported.
|
|
|
|
#
|
|
|
|
# This method is designed to be overriden by exploit modules.
|
|
|
|
#
|
|
|
|
def check
|
|
|
|
Msf::Exploit::CheckCode::Unsupported
|
|
|
|
end
|
|
|
|
|
2005-10-19 01:48:10 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Returns the hash that describes this module's compatibilities.
|
2005-10-19 01:48:10 +00:00
|
|
|
#
|
|
|
|
def compat
|
|
|
|
module_info['Compat'] || {}
|
|
|
|
end
|
|
|
|
|
2010-02-22 17:54:44 +00:00
|
|
|
#
|
|
|
|
# Returns the address of the last target host (rough estimate)
|
|
|
|
#
|
|
|
|
def target_host
|
|
|
|
if(self.respond_to?('rhost'))
|
|
|
|
return rhost()
|
|
|
|
end
|
|
|
|
|
|
|
|
if(self.datastore['RHOST'])
|
|
|
|
return self.datastore['RHOST']
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2012-02-29 01:28:47 +00:00
|
|
|
#
|
|
|
|
# Returns the address of the last target port (rough estimate)
|
|
|
|
#
|
|
|
|
def target_port
|
|
|
|
if(self.respond_to?('rport'))
|
|
|
|
return rport()
|
|
|
|
end
|
|
|
|
|
|
|
|
if(self.datastore['RPORT'])
|
|
|
|
return self.datastore['RPORT']
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
2013-03-08 00:20:08 +00:00
|
|
|
|
2010-02-22 17:54:44 +00:00
|
|
|
#
|
|
|
|
# Returns the current workspace
|
|
|
|
#
|
|
|
|
def workspace
|
|
|
|
self.datastore['WORKSPACE'] ||
|
2010-02-22 19:04:15 +00:00
|
|
|
(framework.db and framework.db.active and framework.db.workspace and framework.db.workspace.name)
|
2010-02-22 17:54:44 +00:00
|
|
|
end
|
|
|
|
|
2010-03-16 15:11:07 +00:00
|
|
|
#
|
2010-10-09 18:11:11 +00:00
|
|
|
# Returns the username that instantiated this module, this tries a handful of methods
|
2011-07-04 20:09:32 +00:00
|
|
|
# to determine what actual user ran this module.
|
2010-03-16 15:11:07 +00:00
|
|
|
#
|
|
|
|
def owner
|
2010-10-09 18:11:11 +00:00
|
|
|
# Generic method to configure a module owner
|
|
|
|
username = self.datastore['MODULE_OWNER'].to_s.strip
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2010-10-09 18:11:11 +00:00
|
|
|
# Specific method used by the commercial products
|
|
|
|
if username.empty?
|
|
|
|
username = self.datastore['PROUSER'].to_s.strip
|
|
|
|
end
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2010-10-09 18:11:11 +00:00
|
|
|
# Fallback when neither prior method is available, common for msfconsole
|
|
|
|
if username.empty?
|
2010-10-09 18:27:09 +00:00
|
|
|
username = (ENV['LOGNAME'] || ENV['USERNAME'] || ENV['USER'] || "unknown").to_s.strip
|
2010-10-09 18:11:11 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
username
|
2010-03-16 15:11:07 +00:00
|
|
|
end
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2011-02-28 04:24:35 +00:00
|
|
|
#
|
|
|
|
# Scans the parent module reference to populate additional information. This
|
|
|
|
# is used to inherit common settings (owner, workspace, parent uuid, etc).
|
|
|
|
#
|
|
|
|
def register_parent(ref)
|
2011-03-05 20:15:36 +00:00
|
|
|
self.datastore['WORKSPACE'] = (ref.datastore['WORKSPACE'] ? ref.datastore['WORKSPACE'].dup : nil)
|
|
|
|
self.datastore['PROUSER'] = (ref.datastore['PROUSER'] ? ref.datastore['PROUSER'].dup : nil)
|
2011-02-28 04:24:35 +00:00
|
|
|
self.datastore['MODULE_OWNER'] = ref.owner.dup
|
|
|
|
self.datastore['ParentUUID'] = ref.uuid.dup
|
|
|
|
end
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2005-10-19 01:48:10 +00:00
|
|
|
#
|
|
|
|
# Returns whether or not this module is compatible with the supplied
|
|
|
|
# module.
|
|
|
|
#
|
|
|
|
def compatible?(mod)
|
|
|
|
ch = nil
|
|
|
|
|
|
|
|
# Invalid module? Shoot, we can't compare that.
|
|
|
|
return true if (mod == nil)
|
|
|
|
|
|
|
|
# Determine which hash to used based on the supplied module type
|
|
|
|
if (mod.type == MODULE_ENCODER)
|
|
|
|
ch = self.compat['Encoder']
|
|
|
|
elsif (mod.type == MODULE_NOP)
|
|
|
|
ch = self.compat['Nop']
|
|
|
|
elsif (mod.type == MODULE_PAYLOAD)
|
|
|
|
ch = self.compat['Payload']
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-10-19 01:48:10 +00:00
|
|
|
# Enumerate each compatibility item in our hash to find out
|
|
|
|
# if we're compatible with this sucker.
|
2005-12-27 04:16:23 +00:00
|
|
|
ch.each_pair do |k,v|
|
|
|
|
|
2005-10-19 01:48:10 +00:00
|
|
|
# Get the value of the current key from the module, such as
|
|
|
|
# the ConnectionType for a stager (ws2ord, for instance).
|
|
|
|
mval = mod.module_info[k]
|
|
|
|
|
2005-12-27 04:16:23 +00:00
|
|
|
# Reject a filled compat item on one side, but not the other
|
2011-07-04 20:09:32 +00:00
|
|
|
if (v and not mval)
|
|
|
|
dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}")
|
|
|
|
return false
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-12-27 04:16:23 +00:00
|
|
|
# Track how many of our values matched the module
|
|
|
|
mcnt = 0
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-12-27 04:16:23 +00:00
|
|
|
# Values are whitespace separated
|
|
|
|
sv = v.split(/\s+/)
|
|
|
|
mv = mval.split(/\s+/)
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-12-27 04:16:23 +00:00
|
|
|
sv.each do |x|
|
2005-12-27 02:42:46 +00:00
|
|
|
|
2006-01-03 04:43:40 +00:00
|
|
|
dlog("Checking compat [#{mod.refname} with #{self.refname}]: #{x} to #{mv.join(", ")}", 'core', LEV_3)
|
|
|
|
|
2005-12-27 04:16:23 +00:00
|
|
|
# Verify that any negate values are not matched
|
2009-07-22 13:38:23 +00:00
|
|
|
if (x[0,1] == '-' and mv.include?(x[1, x.length-1]))
|
2005-12-27 04:16:23 +00:00
|
|
|
dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{x}, value was #{mval}", 'core', LEV_1)
|
2005-12-27 02:42:46 +00:00
|
|
|
return false
|
|
|
|
end
|
2005-12-27 04:16:23 +00:00
|
|
|
|
|
|
|
mcnt += 1 if mv.include?(x)
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-12-27 04:16:23 +00:00
|
|
|
# No values matched, reject this module
|
|
|
|
if (mcnt == 0)
|
2009-11-03 18:09:05 +00:00
|
|
|
dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}, value was #{mval}", 'core', LEV_1)
|
2005-12-27 04:16:23 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
2005-10-19 01:48:10 +00:00
|
|
|
|
2011-07-04 20:09:32 +00:00
|
|
|
dlog("Module #{mod.refname} is compatible with #{self.refname}", "core", LEV_1)
|
|
|
|
|
|
|
|
|
2005-10-19 01:48:10 +00:00
|
|
|
# If we get here, we're compatible.
|
|
|
|
return true
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Return the module's abstract type.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def type
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Return a comma separated list of author for this module.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def author_to_s
|
|
|
|
return author.collect { |author| author.to_s }.join(", ")
|
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Enumerate each author.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def each_author(&block)
|
|
|
|
author.each(&block)
|
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Return a comma separated list of supported architectures, if any.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def arch_to_s
|
|
|
|
return arch.join(", ")
|
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Enumerate each architecture.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def each_arch(&block)
|
|
|
|
arch.each(&block)
|
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Return whether or not the module supports the supplied architecture.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def arch?(what)
|
2005-05-22 07:14:16 +00:00
|
|
|
return true if (what == ARCH_ANY)
|
|
|
|
|
2009-11-03 18:09:05 +00:00
|
|
|
return arch.index(what) != nil
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Return a comma separated list of supported platforms, if any.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def platform_to_s
|
2009-10-01 05:47:51 +00:00
|
|
|
return ((platform.all?) ? [ "All" ] : platform.names).join(", ")
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
2005-06-05 05:42:14 +00:00
|
|
|
|
2007-06-16 05:04:03 +00:00
|
|
|
#
|
|
|
|
# Checks to see if this module is compatible with the supplied platform
|
|
|
|
#
|
|
|
|
def platform?(what)
|
|
|
|
(platform & what).empty? == false
|
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Returns whether or not the module requires or grants high privileges.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
|
|
|
def privileged?
|
|
|
|
return (privileged == true)
|
|
|
|
end
|
2005-07-09 19:35:29 +00:00
|
|
|
|
2005-07-11 02:03:48 +00:00
|
|
|
#
|
|
|
|
# The default communication subsystem for this module. We may need to move
|
|
|
|
# this somewhere else.
|
|
|
|
#
|
|
|
|
def comm
|
|
|
|
return Rex::Socket::Comm::Local
|
|
|
|
end
|
|
|
|
|
2005-07-15 22:30:04 +00:00
|
|
|
#
|
|
|
|
# Overrides the class' own datastore with the one supplied. This is used
|
|
|
|
# to allow modules to share datastores, such as a payload sharing an
|
|
|
|
# exploit module's datastore.
|
|
|
|
#
|
|
|
|
def share_datastore(ds)
|
|
|
|
self.datastore = ds
|
|
|
|
self.datastore.import_options(self.options)
|
|
|
|
end
|
2007-02-21 03:07:12 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Imports default options into the module's datastore, optionally clearing
|
|
|
|
# all of the values currently set in the datastore.
|
|
|
|
#
|
|
|
|
def import_defaults(clear_datastore = true)
|
|
|
|
# Clear the datastore if the caller asked us to
|
|
|
|
self.datastore.clear if clear_datastore
|
|
|
|
|
|
|
|
self.datastore.import_options(self.options, 'self', true)
|
|
|
|
|
|
|
|
# If there are default options, import their values into the datastore
|
|
|
|
if (module_info['DefaultOptions'])
|
|
|
|
self.datastore.import_options_from_hash(module_info['DefaultOptions'], true, 'self')
|
|
|
|
end
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2006-01-06 02:25:47 +00:00
|
|
|
#
|
|
|
|
# This method ensures that the options associated with this module all
|
|
|
|
# have valid values according to each required option in the option
|
|
|
|
# container.
|
|
|
|
#
|
|
|
|
def validate
|
|
|
|
self.options.validate(self.datastore)
|
|
|
|
end
|
|
|
|
|
2007-01-05 06:38:24 +00:00
|
|
|
#
|
|
|
|
# Returns true if this module is being debugged. The debug flag is set
|
|
|
|
# by setting datastore['DEBUG'] to 1|true|yes
|
|
|
|
#
|
|
|
|
def debugging?
|
|
|
|
(datastore['DEBUG'] || '') =~ /^(1|t|y)/i
|
|
|
|
end
|
2013-03-08 00:20:08 +00:00
|
|
|
|
2011-12-04 18:38:06 +00:00
|
|
|
#
|
|
|
|
# Indicates whether the module supports IPv6. This is true by default,
|
|
|
|
# but certain modules require additional work to be compatible or are
|
|
|
|
# hardcoded in terms of application support and should be skipped.
|
|
|
|
#
|
|
|
|
def support_ipv6?
|
|
|
|
true
|
|
|
|
end
|
2011-05-28 02:26:04 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# This provides a standard set of search filters for every module.
|
|
|
|
# The search terms are in the form of:
|
2011-07-04 20:09:32 +00:00
|
|
|
# {
|
2011-05-28 02:26:04 +00:00
|
|
|
# "text" => [ [ "include_term1", "include_term2", ...], [ "exclude_term1", "exclude_term2"], ... ],
|
|
|
|
# "cve" => [ [ "include_term1", "include_term2", ...], [ "exclude_term1", "exclude_term2"], ... ]
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# Returns true on no match, false on match
|
|
|
|
#
|
2011-05-28 02:29:22 +00:00
|
|
|
def search_filter(search_string)
|
|
|
|
return false if not search_string
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2011-05-28 02:29:22 +00:00
|
|
|
search_string += " "
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2011-05-28 02:29:22 +00:00
|
|
|
# Split search terms by space, but allow quoted strings
|
|
|
|
terms = search_string.split(/\"/).collect{|t| t.strip==t ? t : t.split(' ')}.flatten
|
|
|
|
terms.delete('')
|
|
|
|
|
|
|
|
# All terms are either included or excluded
|
|
|
|
res = {}
|
|
|
|
|
|
|
|
terms.each do |t|
|
|
|
|
f,v = t.split(":", 2)
|
|
|
|
if not v
|
|
|
|
v = f
|
|
|
|
f = 'text'
|
|
|
|
end
|
|
|
|
next if v.length == 0
|
|
|
|
f.downcase!
|
|
|
|
v.downcase!
|
|
|
|
res[f] ||=[ [], [] ]
|
|
|
|
if v[0,1] == "-"
|
|
|
|
next if v.length == 1
|
|
|
|
res[f][1] << v[1,v.length-1]
|
|
|
|
else
|
|
|
|
res[f][0] << v
|
|
|
|
end
|
2011-07-04 20:09:32 +00:00
|
|
|
end
|
2011-05-28 02:29:22 +00:00
|
|
|
|
|
|
|
k = res
|
2011-07-04 20:09:32 +00:00
|
|
|
|
2011-05-28 02:26:04 +00:00
|
|
|
refs = self.references.map{|x| [x.ctx_id, x.ctx_val].join("-") }
|
|
|
|
is_server = (self.respond_to?(:stance) and self.stance == "aggressive")
|
2011-07-04 20:09:32 +00:00
|
|
|
is_client = (self.respond_to?(:stance) and self.stance == "passive")
|
|
|
|
|
2011-05-28 02:26:04 +00:00
|
|
|
[0,1].each do |mode|
|
|
|
|
match = false
|
|
|
|
k.keys.each do |t|
|
|
|
|
next if k[t][mode].length == 0
|
|
|
|
|
|
|
|
k[t][mode].each do |w|
|
|
|
|
# Reset the match flag for each keyword for inclusive search
|
|
|
|
match = false if mode == 0
|
|
|
|
|
|
|
|
# Convert into a case-insensitive regex
|
|
|
|
r = Regexp.new(Regexp.escape(w), true)
|
|
|
|
|
|
|
|
case t
|
|
|
|
when 'text'
|
|
|
|
terms = [self.name, self.fullname, self.description] + refs + self.author.map{|x| x.to_s}
|
|
|
|
if self.respond_to?(:targets) and self.targets
|
|
|
|
terms = terms + self.targets.map{|x| x.name}
|
|
|
|
end
|
|
|
|
match = [t,w] if terms.any? { |x| x =~ r }
|
|
|
|
when 'name'
|
|
|
|
match = [t,w] if self.name =~ r
|
|
|
|
when 'path'
|
|
|
|
match = [t,w] if self.fullname =~ r
|
|
|
|
when 'author'
|
|
|
|
match = [t,w] if self.author.map{|x| x.to_s}.any? { |a| a =~ r }
|
|
|
|
when 'os', 'platform'
|
|
|
|
match = [t,w] if self.platform_to_s =~ r or self.arch_to_s =~ r
|
|
|
|
if not match and self.respond_to?(:targets) and self.targets
|
|
|
|
match = [t,w] if self.targets.map{|x| x.name}.any? { |t| t =~ r }
|
|
|
|
end
|
2012-01-18 17:19:37 +00:00
|
|
|
when 'port'
|
|
|
|
match = [t,w] if self.datastore['RPORT'].to_s =~ r
|
2011-05-28 02:26:04 +00:00
|
|
|
when 'type'
|
2013-07-18 17:46:23 +00:00
|
|
|
match = [t,w] if Msf::MODULE_TYPES.any? { |modt| w == modt and self.type == modt }
|
2011-05-28 02:26:04 +00:00
|
|
|
when 'app'
|
2011-07-19 08:35:25 +00:00
|
|
|
match = [t,w] if (w == "server" and is_server)
|
|
|
|
match = [t,w] if (w == "client" and is_client)
|
2011-05-28 02:26:04 +00:00
|
|
|
when 'cve'
|
|
|
|
match = [t,w] if refs.any? { |ref| ref =~ /^cve\-/i and ref =~ r }
|
|
|
|
when 'bid'
|
|
|
|
match = [t,w] if refs.any? { |ref| ref =~ /^bid\-/i and ref =~ r }
|
|
|
|
when 'osvdb'
|
|
|
|
match = [t,w] if refs.any? { |ref| ref =~ /^osvdb\-/i and ref =~ r }
|
2012-03-20 13:01:08 +00:00
|
|
|
when 'edb'
|
|
|
|
match = [t,w] if refs.any? { |ref| ref =~ /^edb\-/i and ref =~ r }
|
2011-05-28 02:26:04 +00:00
|
|
|
end
|
|
|
|
break if match
|
|
|
|
end
|
|
|
|
# Filter this module if no matches for a given keyword type
|
|
|
|
if mode == 0 and not match
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
2013-07-18 17:46:23 +00:00
|
|
|
# Filter this module if we matched an exclusion keyword (-value)
|
2011-05-28 02:26:04 +00:00
|
|
|
if mode == 1 and match
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2013-08-15 18:30:47 +00:00
|
|
|
#
|
|
|
|
# Support fail_with for all module types, allow specific classes to override
|
|
|
|
#
|
|
|
|
def fail_with(reason, msg=nil)
|
|
|
|
raise RuntimeError, "#{reason.to_s}: #{msg}"
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Constants indicating the reason for an unsuccessful module attempt
|
|
|
|
#
|
|
|
|
module Failure
|
|
|
|
|
|
|
|
#
|
|
|
|
# No confidence in success or failure
|
|
|
|
#
|
|
|
|
None = 'none'
|
|
|
|
|
|
|
|
#
|
|
|
|
# No confidence in success or failure
|
|
|
|
#
|
|
|
|
Unknown = 'unknown'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The network service was unreachable (connection refused, etc)
|
|
|
|
#
|
|
|
|
Unreachable = 'unreachable'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The exploit settings were incorrect
|
|
|
|
#
|
|
|
|
BadConfig = 'bad-config'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The network service disconnected us mid-attempt
|
|
|
|
#
|
|
|
|
Disconnected = 'disconnected'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The application endpoint or specific service was not found
|
|
|
|
#
|
|
|
|
NotFound = 'not-found'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The application replied in an unexpected fashion
|
|
|
|
#
|
|
|
|
UnexpectedReply = 'unexpected-reply'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The exploit triggered some form of timeout
|
|
|
|
#
|
|
|
|
TimeoutExpired = 'timeout-expired'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The exploit was interrupted by the user
|
|
|
|
#
|
|
|
|
UserInterrupt = 'user-interrupt'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The application replied indication we do not have access
|
|
|
|
#
|
|
|
|
NoAccess = 'no-access'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The target is not compatible with this exploit or settings
|
|
|
|
#
|
|
|
|
NoTarget = 'no-target'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The application response indicated it was not vulnerable
|
|
|
|
#
|
|
|
|
NotVulnerable = 'not-vulnerable'
|
|
|
|
|
|
|
|
#
|
|
|
|
# The payload was delivered but no session was opened (AV, network, etc)
|
|
|
|
#
|
|
|
|
PayloadFailed = 'payload-failed'
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2005-07-15 22:30:04 +00:00
|
|
|
##
|
2005-07-14 14:46:18 +00:00
|
|
|
#
|
|
|
|
# Just some handy quick checks
|
|
|
|
#
|
2005-07-15 22:30:04 +00:00
|
|
|
##
|
2005-11-15 15:11:43 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Returns true if this module is an exploit module.
|
|
|
|
#
|
2005-07-14 14:46:18 +00:00
|
|
|
def exploit?
|
|
|
|
return (type == MODULE_EXPLOIT)
|
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Returns true if this module is a payload module.
|
|
|
|
#
|
2005-07-14 14:46:18 +00:00
|
|
|
def payload?
|
|
|
|
return (type == MODULE_PAYLOAD)
|
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Returns true if this module is an encoder module.
|
|
|
|
#
|
2005-07-14 14:46:18 +00:00
|
|
|
def encoder?
|
|
|
|
return (type == MODULE_ENCODER)
|
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Returns true if this module is a nop module.
|
|
|
|
#
|
2005-07-14 14:46:18 +00:00
|
|
|
def nop?
|
|
|
|
return (type == MODULE_NOP)
|
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
2006-01-24 03:59:44 +00:00
|
|
|
# Returns true if this module is an auxiliary module.
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
2006-01-24 03:59:44 +00:00
|
|
|
def auxiliary?
|
|
|
|
return (type == MODULE_AUX)
|
2005-07-14 14:46:18 +00:00
|
|
|
end
|
|
|
|
|
2010-12-27 17:46:42 +00:00
|
|
|
#
|
|
|
|
# Returns true if this module is an post-exploitation module.
|
|
|
|
#
|
|
|
|
def post?
|
|
|
|
return (type == MODULE_POST)
|
|
|
|
end
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
#
|
|
|
|
# Returns false since this is the real module
|
|
|
|
#
|
|
|
|
def self.cached?
|
|
|
|
false
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2010-01-14 18:09:34 +00:00
|
|
|
#
|
|
|
|
# Read a value from the module store
|
|
|
|
#
|
|
|
|
def [](k)
|
|
|
|
self.module_store[k]
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Store a value into the module
|
|
|
|
#
|
|
|
|
def []=(k,v)
|
|
|
|
self.module_store[k] = v
|
|
|
|
end
|
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# The array of zero or more authors.
|
|
|
|
#
|
|
|
|
attr_reader :author
|
|
|
|
#
|
|
|
|
# The array of zero or more architectures.
|
|
|
|
#
|
|
|
|
attr_reader :arch
|
|
|
|
#
|
|
|
|
# The array of zero or more platforms.
|
|
|
|
#
|
|
|
|
attr_reader :platform
|
|
|
|
#
|
|
|
|
# The reference count for the module.
|
|
|
|
#
|
|
|
|
attr_reader :references
|
|
|
|
#
|
|
|
|
# The module-specific datastore instance.
|
|
|
|
#
|
|
|
|
attr_reader :datastore
|
|
|
|
#
|
|
|
|
# The module-specific options.
|
|
|
|
#
|
|
|
|
attr_reader :options
|
|
|
|
#
|
|
|
|
# Whether or not this module requires privileged access.
|
|
|
|
#
|
2005-06-05 05:42:14 +00:00
|
|
|
attr_reader :privileged
|
2006-01-22 19:25:55 +00:00
|
|
|
#
|
|
|
|
# The license under which this module is provided.
|
|
|
|
#
|
|
|
|
attr_reader :license
|
2007-04-04 02:49:08 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# The job identifier that this module is running as, if any.
|
|
|
|
#
|
|
|
|
attr_accessor :job_id
|
|
|
|
|
2010-01-14 18:09:34 +00:00
|
|
|
#
|
|
|
|
# A generic hash used for passing additional information to modules
|
|
|
|
#
|
|
|
|
attr_accessor :module_store
|
|
|
|
|
2010-03-26 01:18:10 +00:00
|
|
|
#
|
|
|
|
# The last exception to occur using this module
|
|
|
|
#
|
|
|
|
attr_accessor :error
|
|
|
|
|
2010-03-27 02:39:52 +00:00
|
|
|
#
|
|
|
|
# A unique identifier for this module instance
|
|
|
|
#
|
2010-07-07 16:37:23 +00:00
|
|
|
attr_reader :uuid
|
2010-03-27 02:39:52 +00:00
|
|
|
|
2005-05-21 17:57:00 +00:00
|
|
|
protected
|
2010-07-07 16:37:23 +00:00
|
|
|
attr_writer :uuid
|
|
|
|
def generate_uuid
|
|
|
|
self.uuid = Rex::Text.rand_text_alphanumeric(8).downcase
|
|
|
|
end
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# The list of options that support merging in an information hash.
|
|
|
|
#
|
2010-04-03 05:21:15 +00:00
|
|
|
UpdateableOptions = [ "Name", "Description", "Alias", "PayloadCompat" ]
|
2005-07-13 18:06:12 +00:00
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
#
|
|
|
|
# Sets the modules unsupplied info fields to their default values.
|
|
|
|
#
|
2005-05-21 17:57:00 +00:00
|
|
|
def set_defaults
|
2005-05-22 07:46:41 +00:00
|
|
|
self.module_info = {
|
2009-11-03 18:09:05 +00:00
|
|
|
'Name' => 'No module name',
|
2005-05-21 17:57:00 +00:00
|
|
|
'Description' => 'No module description',
|
|
|
|
'Version' => '0',
|
2005-07-13 18:06:12 +00:00
|
|
|
'Author' => nil,
|
2005-11-24 04:23:43 +00:00
|
|
|
'Arch' => nil, # No architectures by default.
|
|
|
|
'Platform' => [], # No platforms by default.
|
2005-06-05 05:42:14 +00:00
|
|
|
'Ref' => nil,
|
|
|
|
'Privileged' => false,
|
2006-01-22 19:28:05 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2005-05-22 07:46:41 +00:00
|
|
|
}.update(self.module_info)
|
2010-01-14 18:09:34 +00:00
|
|
|
self.module_store = {}
|
2005-05-21 17:57:00 +00:00
|
|
|
end
|
|
|
|
|
2005-10-19 01:48:10 +00:00
|
|
|
#
|
|
|
|
# This method initializes the module's compatibility hashes by normalizing
|
|
|
|
# them into one single hash. As it stands, modules can define
|
|
|
|
# compatibility in their supplied info hash through:
|
|
|
|
#
|
2012-06-06 23:04:54 +00:00
|
|
|
# Compat:: direct compat definitions
|
|
|
|
# PayloadCompat:: payload compatibilities
|
|
|
|
# EncoderCompat:: encoder compatibilities
|
|
|
|
# NopCompat:: nop compatibilities
|
2005-10-19 01:48:10 +00:00
|
|
|
#
|
|
|
|
# In the end, the module specific compatibilities are merged as sub-hashes
|
|
|
|
# of the primary Compat hash key to make checks more uniform.
|
|
|
|
#
|
|
|
|
def init_compat
|
2005-12-27 02:42:46 +00:00
|
|
|
c = module_info['Compat']
|
|
|
|
|
|
|
|
if (c == nil)
|
|
|
|
c = module_info['Compat'] = Hash.new
|
|
|
|
end
|
2005-10-19 01:48:10 +00:00
|
|
|
|
|
|
|
# Initialize the module sub compatibilities
|
|
|
|
c['Payload'] = Hash.new if (c['Payload'] == nil)
|
|
|
|
c['Encoder'] = Hash.new if (c['Encoder'] == nil)
|
|
|
|
c['Nop'] = Hash.new if (c['Nop'] == nil)
|
|
|
|
|
|
|
|
# Update the compat-derived module specific compatibilities from
|
|
|
|
# the specific ones to make a uniform view of compatibilities
|
|
|
|
c['Payload'].update(module_info['PayloadCompat'] || {})
|
|
|
|
c['Encoder'].update(module_info['EncoderCompat'] || {})
|
|
|
|
c['Nop'].update(module_info['NopCompat'] || {})
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2009-10-17 05:25:29 +00:00
|
|
|
#
|
|
|
|
# Register options with a specific owning class.
|
|
|
|
#
|
|
|
|
def info_fixups
|
|
|
|
# Each reference should be an array consisting of two elements
|
|
|
|
refs = module_info['References']
|
|
|
|
if(refs and not refs.empty?)
|
|
|
|
refs.each_index do |i|
|
2009-10-25 17:18:23 +00:00
|
|
|
if !(refs[i].respond_to?('[]') and refs[i].length == 2)
|
2009-10-17 05:25:29 +00:00
|
|
|
refs[i] = nil
|
|
|
|
end
|
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2009-10-17 05:25:29 +00:00
|
|
|
# Purge invalid references
|
|
|
|
refs.delete(nil)
|
|
|
|
end
|
|
|
|
end
|
2005-10-19 01:48:10 +00:00
|
|
|
|
2005-06-05 23:45:58 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Register options with a specific owning class.
|
2005-06-05 23:45:58 +00:00
|
|
|
#
|
|
|
|
def register_options(options, owner = self.class)
|
|
|
|
self.options.add_options(options, owner)
|
2006-05-11 16:11:06 +00:00
|
|
|
self.datastore.import_options(self.options, 'self', true)
|
2009-11-16 02:39:08 +00:00
|
|
|
import_defaults(false)
|
2005-06-05 23:45:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Register advanced options with a specific owning class.
|
2005-06-05 23:45:58 +00:00
|
|
|
#
|
|
|
|
def register_advanced_options(options, owner = self.class)
|
|
|
|
self.options.add_advanced_options(options, owner)
|
2006-05-11 16:11:06 +00:00
|
|
|
self.datastore.import_options(self.options, 'self', true)
|
2009-11-16 02:39:08 +00:00
|
|
|
import_defaults(false)
|
2005-06-05 23:45:58 +00:00
|
|
|
end
|
|
|
|
|
2006-01-05 03:57:12 +00:00
|
|
|
#
|
|
|
|
# Register evasion options with a specific owning class.
|
|
|
|
#
|
|
|
|
def register_evasion_options(options, owner = self.class)
|
|
|
|
self.options.add_evasion_options(options, owner)
|
2006-05-11 16:11:06 +00:00
|
|
|
self.datastore.import_options(self.options, 'self', true)
|
2009-11-16 02:39:08 +00:00
|
|
|
import_defaults(false)
|
2006-01-05 03:57:12 +00:00
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2005-07-11 05:21:19 +00:00
|
|
|
#
|
|
|
|
# Removes the supplied options from the module's option container
|
2005-11-15 15:11:43 +00:00
|
|
|
# and data store.
|
2005-07-11 05:21:19 +00:00
|
|
|
#
|
|
|
|
def deregister_options(*names)
|
|
|
|
names.each { |name|
|
|
|
|
self.options.remove_option(name)
|
|
|
|
self.datastore.delete(name)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2005-06-04 22:26:42 +00:00
|
|
|
#
|
|
|
|
# Checks to see if a derived instance of a given module implements a method
|
|
|
|
# beyond the one that is provided by a base class. This is a pretty lame
|
|
|
|
# way of doing it, but I couldn't find a better one, so meh.
|
|
|
|
#
|
|
|
|
def derived_implementor?(parent, method_name)
|
2008-12-19 07:11:08 +00:00
|
|
|
(self.method(method_name).to_s.match(/#{parent}[^:]/)) ? false : true
|
2005-06-04 22:26:42 +00:00
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
|
|
|
# Merges options in the info hash in a sane fashion, as some options
|
|
|
|
# require special attention.
|
|
|
|
#
|
|
|
|
def merge_info(info, opts)
|
|
|
|
opts.each_pair { |name, val|
|
2005-07-11 05:15:30 +00:00
|
|
|
merge_check_key(info, name, val)
|
|
|
|
}
|
|
|
|
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Updates information in the supplied info hash and merges other
|
|
|
|
# information. This method is used to override things like Name, Version,
|
|
|
|
# and Description without losing the ability to merge architectures,
|
|
|
|
# platforms, and options.
|
|
|
|
#
|
|
|
|
def update_info(info, opts)
|
|
|
|
opts.each_pair { |name, val|
|
|
|
|
# If the supplied option name is one of the ones that we should
|
|
|
|
# override by default
|
|
|
|
if (UpdateableOptions.include?(name) == true)
|
|
|
|
# Only if the entry is currently nil do we use our value
|
|
|
|
if (info[name] == nil)
|
2005-07-09 00:24:02 +00:00
|
|
|
info[name] = val
|
|
|
|
end
|
2005-07-11 05:15:30 +00:00
|
|
|
# Otherwise, perform the merge operation like normal
|
|
|
|
else
|
|
|
|
merge_check_key(info, name, val)
|
2005-06-05 05:42:14 +00:00
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
return info
|
|
|
|
end
|
|
|
|
|
2005-07-11 05:15:30 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Checks and merges the supplied key/value pair in the supplied hash.
|
2005-07-11 05:15:30 +00:00
|
|
|
#
|
|
|
|
def merge_check_key(info, name, val)
|
|
|
|
if (self.respond_to?("merge_info_#{name.downcase}"))
|
|
|
|
eval("merge_info_#{name.downcase}(info, val)")
|
|
|
|
else
|
|
|
|
# If the info hash already has an entry for this name
|
|
|
|
if (info[name])
|
|
|
|
# If it's not an array, convert it to an array and merge the
|
|
|
|
# two
|
|
|
|
if (info[name].kind_of?(Array) == false)
|
|
|
|
curr = info[name]
|
2005-07-18 04:07:56 +00:00
|
|
|
info[name] = [ curr ]
|
|
|
|
end
|
|
|
|
|
|
|
|
# If the value being merged is an array, add each one
|
|
|
|
if (val.kind_of?(Array) == true)
|
|
|
|
val.each { |v|
|
|
|
|
if (info[name].include?(v) == false)
|
|
|
|
info[name] << v
|
|
|
|
end
|
|
|
|
}
|
|
|
|
# Otherwise just add the value
|
|
|
|
elsif (info[name].include?(val) == false)
|
|
|
|
info[name] << val
|
2005-07-11 05:15:30 +00:00
|
|
|
end
|
|
|
|
# Otherwise, just set the value equal if no current value
|
|
|
|
# exists
|
|
|
|
else
|
|
|
|
info[name] = val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-07-09 00:24:02 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Merge aliases with an underscore delimiter.
|
2005-07-09 00:24:02 +00:00
|
|
|
#
|
|
|
|
def merge_info_alias(info, val)
|
|
|
|
merge_info_string(info, 'Alias', val, '_')
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Merges the module name.
|
2005-07-09 00:24:02 +00:00
|
|
|
#
|
|
|
|
def merge_info_name(info, val)
|
2005-07-11 23:10:48 +00:00
|
|
|
merge_info_string(info, 'Name', val, ', ', true)
|
2009-11-03 18:09:05 +00:00
|
|
|
end
|
2005-07-09 00:24:02 +00:00
|
|
|
|
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Merges the module description.
|
2005-07-09 00:24:02 +00:00
|
|
|
#
|
|
|
|
def merge_info_description(info, val)
|
|
|
|
merge_info_string(info, 'Description', val)
|
|
|
|
end
|
|
|
|
|
2005-07-10 00:16:48 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Merge the module version.
|
2005-07-10 00:16:48 +00:00
|
|
|
#
|
|
|
|
def merge_info_version(info, val)
|
|
|
|
merge_info_string(info, 'Version', val)
|
|
|
|
end
|
|
|
|
|
2005-07-09 00:24:02 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Merges a given key in the info hash with a delimiter.
|
2005-07-09 00:24:02 +00:00
|
|
|
#
|
2005-07-11 23:10:48 +00:00
|
|
|
def merge_info_string(info, key, val, delim = ', ', inverse = false)
|
2005-07-09 00:24:02 +00:00
|
|
|
if (info[key])
|
2005-07-11 23:10:48 +00:00
|
|
|
if (inverse == true)
|
|
|
|
info[key] = info[key] + delim + val
|
|
|
|
else
|
|
|
|
info[key] = val + delim + info[key]
|
|
|
|
end
|
2005-07-09 00:24:02 +00:00
|
|
|
else
|
|
|
|
info[key] = val
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Merges options.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2006-01-05 03:57:12 +00:00
|
|
|
def merge_info_options(info, val, advanced = false, evasion = false)
|
2009-11-03 18:09:05 +00:00
|
|
|
|
2006-01-05 03:57:12 +00:00
|
|
|
key_name = ((advanced) ? 'Advanced' : (evasion) ? 'Evasion' : '') + 'Options'
|
2005-06-05 05:42:14 +00:00
|
|
|
|
|
|
|
new_cont = OptionContainer.new
|
2006-01-05 03:57:12 +00:00
|
|
|
new_cont.add_options(val, advanced, evasion)
|
2005-06-05 05:42:14 +00:00
|
|
|
cur_cont = OptionContainer.new
|
2006-01-05 03:57:12 +00:00
|
|
|
cur_cont.add_options(info[key_name] || [], advanced, evasion)
|
2005-06-05 05:42:14 +00:00
|
|
|
|
|
|
|
new_cont.each_option { |name, option|
|
|
|
|
next if (cur_cont.get(name))
|
|
|
|
|
|
|
|
info[key_name] = [] if (!info[key_name])
|
|
|
|
info[key_name] << option
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2009-11-03 18:09:05 +00:00
|
|
|
#
|
2005-11-15 15:11:43 +00:00
|
|
|
# Merges advanced options.
|
2005-06-05 05:42:14 +00:00
|
|
|
#
|
2006-01-05 03:57:12 +00:00
|
|
|
def merge_info_advanced_options(info, val)
|
|
|
|
merge_info_options(info, val, true, false)
|
2005-06-05 05:42:14 +00:00
|
|
|
end
|
|
|
|
|
2009-11-03 18:09:05 +00:00
|
|
|
#
|
2006-01-05 03:57:12 +00:00
|
|
|
# Merges advanced options.
|
|
|
|
#
|
|
|
|
def merge_info_evasion_options(info, val)
|
|
|
|
merge_info_options(info, val, false, true)
|
|
|
|
end
|
2009-08-18 03:02:37 +00:00
|
|
|
|
2005-11-15 15:11:43 +00:00
|
|
|
attr_accessor :module_info # :nodoc:
|
|
|
|
attr_writer :author, :arch, :platform, :references, :datastore, :options # :nodoc:
|
|
|
|
attr_writer :privileged # :nodoc:
|
2006-01-22 19:25:55 +00:00
|
|
|
attr_writer :license # :nodoc:
|
2005-05-21 17:57:00 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2005-06-05 00:03:23 +00:00
|
|
|
#
|
|
|
|
# Alias the data types so people can reference them just by Msf:: and not
|
|
|
|
# Msf::Module::
|
|
|
|
#
|
|
|
|
Author = Msf::Module::Author
|
|
|
|
Reference = Msf::Module::Reference
|
|
|
|
SiteReference = Msf::Module::SiteReference
|
|
|
|
Platform = Msf::Module::Platform
|
|
|
|
Target = Msf::Module::Target
|
|
|
|
|
2008-12-21 04:18:17 +00:00
|
|
|
end
|
2009-11-03 18:09:05 +00:00
|
|
|
|