From 370daaed5e90fb59abf92d8df09438ace1e9d42e Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Wed, 15 Oct 2014 15:52:26 -0500 Subject: [PATCH 01/51] Extract Msf::Module::Failure MSP-11126 Move `Msf::Module::Failure` to a file of its own. --- lib/msf/core/module.rb | 73 +--------------------------------- lib/msf/core/module/failure.rb | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 72 deletions(-) create mode 100644 lib/msf/core/module/failure.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 740af69610..7e18674a5e 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -12,6 +12,7 @@ module Msf # ### class Module + autoload :Failure, 'msf/core/module/failure' # Modules can subscribe to a user-interface, and as such they include the # UI subscriber module. This provides methods like print, print_line, etc. @@ -731,78 +732,6 @@ class Module 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 - - ## # # Just some handy quick checks diff --git a/lib/msf/core/module/failure.rb b/lib/msf/core/module/failure.rb new file mode 100644 index 0000000000..c07f4913f6 --- /dev/null +++ b/lib/msf/core/module/failure.rb @@ -0,0 +1,41 @@ +# Constants indicating the reason for an unsuccessful module attempt +module Msf::Module::Failure + # The exploit settings were incorrect + BadConfig = 'bad-config' + + # The network service disconnected us mid-attempt + Disconnected = 'disconnected' + + # The application replied indication we do not have access + NoAccess = 'no-access' + + # No confidence in success or failure + None = 'none' + + # The target is not compatible with this exploit or settings + NoTarget = 'no-target' + + # The application endpoint or specific service was not found + NotFound = 'not-found' + + # 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' + + # The exploit triggered some form of timeout + TimeoutExpired = 'timeout-expired' + + # The application replied in an unexpected fashion + UnexpectedReply = 'unexpected-reply' + + # No confidence in success or failure + Unknown = 'unknown' + + # The network service was unreachable (connection refused, etc) + Unreachable = 'unreachable' + + # The exploit was interrupted by the user + UserInterrupt = 'user-interrupt' +end \ No newline at end of file From f068d669d647580fe1d54280d8b10a051854fbcd Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 08:14:24 -0500 Subject: [PATCH 02/51] Extract Msf::Module::ModuleStore MSP-11126 --- lib/msf/core/module.rb | 22 +++------------------- lib/msf/core/module/module_store.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 19 deletions(-) create mode 100644 lib/msf/core/module/module_store.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 7e18674a5e..6255da63cf 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -13,6 +13,9 @@ module Msf ### class Module autoload :Failure, 'msf/core/module/failure' + autoload :ModuleStore, 'msf/core/module/module_store' + + include Msf::Module::ModuleStore # Modules can subscribe to a user-interface, and as such they include the # UI subscriber module. This provides methods like print, print_line, etc. @@ -787,20 +790,6 @@ class Module false end - # - # 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 - # # The array of zero or more authors. # @@ -839,11 +828,6 @@ class Module # attr_accessor :job_id - # - # A generic hash used for passing additional information to modules - # - attr_accessor :module_store - # # The last exception to occur using this module # diff --git a/lib/msf/core/module/module_store.rb b/lib/msf/core/module/module_store.rb new file mode 100644 index 0000000000..8e34ebee79 --- /dev/null +++ b/lib/msf/core/module/module_store.rb @@ -0,0 +1,28 @@ +module Msf::Module::ModuleStore + # + # Attributes + # + + # + # A generic hash used for passing additional information to modules + # + attr_accessor :module_store + + # + # Instance Methods + # + + # + # 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 +end \ No newline at end of file From 6a194b3a88915f7370454f8e6dbcfe25283d7940 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 08:20:55 -0500 Subject: [PATCH 03/51] Extract Msf::Module::ModuleStore shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 4 ++-- spec/support/shared/examples/msf/module/module_store.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/module_store.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 43ac00ef64..a5937b082e 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -38,8 +38,6 @@ end REF_TYPES = %w(CVE BID OSVDB EDB) describe Msf::Module do - it { is_expected.to respond_to :[] } - it { is_expected.to respond_to :[]= } it { is_expected.to respond_to :alias } it { is_expected.to respond_to :arch? } it { is_expected.to respond_to :arch_to_s } @@ -118,6 +116,8 @@ describe Msf::Module do it { is_expected.to respond_to :vprint_warning } it { is_expected.to respond_to :workspace } + it_should_behave_like 'Msf::Module::ModuleStore' + context 'CONSTANTS' do context 'UpdateableOptions' do subject(:updateable_options) { diff --git a/spec/support/shared/examples/msf/module/module_store.rb b/spec/support/shared/examples/msf/module/module_store.rb new file mode 100644 index 0000000000..57588117d6 --- /dev/null +++ b/spec/support/shared/examples/msf/module/module_store.rb @@ -0,0 +1,6 @@ +shared_examples_for 'Msf::Module::ModuleStore' do + it { is_expected.to respond_to :[] } + it { is_expected.to respond_to :[]= } + it { is_expected.to respond_to :module_store } + it { is_expected.to respond_to :module_store= } +end \ No newline at end of file From 85169d5e8d23272f99293100f7bd1dca8c1e2f32 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 08:31:43 -0500 Subject: [PATCH 04/51] Extract Msf::Module::DataStore MSP-11126 --- lib/msf/core/module.rb | 36 +++------------------------ lib/msf/core/module/data_store.rb | 41 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 32 deletions(-) create mode 100644 lib/msf/core/module/data_store.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 6255da63cf..2686e471db 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -12,9 +12,11 @@ module Msf # ### class Module - autoload :Failure, 'msf/core/module/failure' + autoload :DataStore, 'msf/core/module/data_store' + autoload :ModuleStore, 'msf/core/module/module_store' autoload :ModuleStore, 'msf/core/module/module_store' + include Msf::Module::DataStore include Msf::Module::ModuleStore # Modules can subscribe to a user-interface, and as such they include the @@ -568,32 +570,6 @@ class Module Rex::Socket::Comm::Local end - # - # 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 - - # - # 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 - # # This method ensures that the options associated with this module all # have valid values according to each required option in the option @@ -807,10 +783,6 @@ class Module # attr_reader :references # - # The module-specific datastore instance. - # - attr_reader :datastore - # # The module-specific options. # attr_reader :options @@ -1112,7 +1084,7 @@ protected end attr_accessor :module_info # :nodoc: - attr_writer :author, :arch, :platform, :references, :datastore, :options # :nodoc: + attr_writer :author, :arch, :platform, :references, :options # :nodoc: attr_writer :privileged # :nodoc: attr_writer :license # :nodoc: diff --git a/lib/msf/core/module/data_store.rb b/lib/msf/core/module/data_store.rb new file mode 100644 index 0000000000..d2ca02e6f3 --- /dev/null +++ b/lib/msf/core/module/data_store.rb @@ -0,0 +1,41 @@ +module Msf::Module::DataStore + # + # Attributes + # + + # @attribute [r] datastore + # The module-specific datastore instance. + # + # @return [Hash{String => String}] + attr_reader :datastore + + # + # 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 + + # + # 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 + + protected + + attr_writer :datastore +end \ No newline at end of file From 9b10a3f1dc47ba82408e97523857ef591f5e4925 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 08:35:15 -0500 Subject: [PATCH 05/51] Extract Msf::Module::DataStore shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 3 +-- spec/support/shared/examples/msf/module/data_store.rb | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/data_store.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index a5937b082e..1d2048a73b 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -61,7 +61,6 @@ describe Msf::Module do it { is_expected.to respond_to :framework } it { is_expected.to respond_to :fullname } it { is_expected.to respond_to :generate_uuid } - it { is_expected.to respond_to :import_defaults } it { is_expected.to respond_to :info_fixups } it { is_expected.to respond_to :init_compat } it { is_expected.to respond_to :merge_check_key } @@ -100,7 +99,6 @@ describe Msf::Module do it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } it { is_expected.to respond_to :set_defaults } - it { is_expected.to respond_to :share_datastore } it { is_expected.to respond_to :shortname } it { is_expected.to respond_to :support_ipv6? } it { is_expected.to respond_to :target_host } @@ -116,6 +114,7 @@ describe Msf::Module do it { is_expected.to respond_to :vprint_warning } it { is_expected.to respond_to :workspace } + it_should_behave_like 'Msf::Module::DataStore' it_should_behave_like 'Msf::Module::ModuleStore' context 'CONSTANTS' do diff --git a/spec/support/shared/examples/msf/module/data_store.rb b/spec/support/shared/examples/msf/module/data_store.rb new file mode 100644 index 0000000000..ecc3f78de9 --- /dev/null +++ b/spec/support/shared/examples/msf/module/data_store.rb @@ -0,0 +1,5 @@ +shared_examples_for 'Msf::Module::DataStore' do + it { is_expected.to respond_to :datastore } + it { is_expected.to respond_to :import_defaults } + it { is_expected.to respond_to :share_datastore } +end \ No newline at end of file From f5d09f735e90767f4dc900d7d5091de1bf225be1 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 08:51:07 -0500 Subject: [PATCH 06/51] Extract Msf::Module::Compatibility MSP-11126 --- lib/msf/core/module.rb | 114 +------------------------- lib/msf/core/module/compatibility.rb | 115 +++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 112 deletions(-) create mode 100644 lib/msf/core/module/compatibility.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 2686e471db..d68da9132c 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -12,10 +12,12 @@ module Msf # ### class Module + autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' autoload :ModuleStore, 'msf/core/module/module_store' autoload :ModuleStore, 'msf/core/module/module_store' + include Msf::Module::Compatibility include Msf::Module::DataStore include Msf::Module::ModuleStore @@ -361,13 +363,6 @@ class Module Msf::Exploit::CheckCode::Unsupported end - # - # Returns the hash that describes this module's compatibilities. - # - def compat - module_info['Compat'] || {} - end - # # Returns the address of the last target host (rough estimate) # @@ -422,79 +417,6 @@ class Module self.datastore['ParentUUID'] = ref.uuid.dup end - # - # 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'] - if self.respond_to?("target") and self.target and self.target['Payload'] and self.target['Payload']['Compat'] - ch = ch.merge(self.target['Payload']['Compat']) - end - else - return true - end - - # Enumerate each compatibility item in our hash to find out - # if we're compatible with this sucker. - ch.each_pair do |k,v| - - # 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] - - # Reject a filled compat item on one side, but not the other - if (v and not mval) - dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}") - return false - end - - # Track how many of our values matched the module - mcnt = 0 - - # Values are whitespace separated - sv = v.split(/\s+/) - mv = mval.split(/\s+/) - - sv.each do |x| - - dlog("Checking compat [#{mod.refname} with #{self.refname}]: #{x} to #{mv.join(", ")}", 'core', LEV_3) - - # Verify that any negate values are not matched - if (x[0,1] == '-' and mv.include?(x[1, x.length-1])) - dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{x}, value was #{mval}", 'core', LEV_1) - return false - end - - mcnt += 1 if mv.include?(x) - end - - # No values matched, reject this module - if (mcnt == 0) - dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}, value was #{mval}", 'core', LEV_1) - return false - end - - end - - dlog("Module #{mod.refname} is compatible with #{self.refname}", "core", LEV_1) - - - # If we get here, we're compatible. - return true - end - # # Return the module's abstract type. # @@ -838,38 +760,6 @@ protected self.module_store = {} end - # - # 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: - # - # Compat:: direct compat definitions - # PayloadCompat:: payload compatibilities - # EncoderCompat:: encoder compatibilities - # NopCompat:: nop compatibilities - # - # 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 - c = module_info['Compat'] - - if (c == nil) - c = module_info['Compat'] = Hash.new - end - - # 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 - # # Register options with a specific owning class. # diff --git a/lib/msf/core/module/compatibility.rb b/lib/msf/core/module/compatibility.rb new file mode 100644 index 0000000000..e1e7ca300a --- /dev/null +++ b/lib/msf/core/module/compatibility.rb @@ -0,0 +1,115 @@ +module Msf::Module::Compatibility + # + # Returns the hash that describes this module's compatibilities. + # + def compat + module_info['Compat'] || {} + end + + # + # 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'] + if self.respond_to?("target") and self.target and self.target['Payload'] and self.target['Payload']['Compat'] + ch = ch.merge(self.target['Payload']['Compat']) + end + else + return true + end + + # Enumerate each compatibility item in our hash to find out + # if we're compatible with this sucker. + ch.each_pair do |k,v| + + # 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] + + # Reject a filled compat item on one side, but not the other + if (v and not mval) + dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}") + return false + end + + # Track how many of our values matched the module + mcnt = 0 + + # Values are whitespace separated + sv = v.split(/\s+/) + mv = mval.split(/\s+/) + + sv.each do |x| + + dlog("Checking compat [#{mod.refname} with #{self.refname}]: #{x} to #{mv.join(", ")}", 'core', LEV_3) + + # Verify that any negate values are not matched + if (x[0,1] == '-' and mv.include?(x[1, x.length-1])) + dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{x}, value was #{mval}", 'core', LEV_1) + return false + end + + mcnt += 1 if mv.include?(x) + end + + # No values matched, reject this module + if (mcnt == 0) + dlog("Module #{mod.refname} is incompatible with #{self.refname} for #{k}: limiter was #{v}, value was #{mval}", 'core', LEV_1) + return false + end + + end + + dlog("Module #{mod.refname} is compatible with #{self.refname}", "core", LEV_1) + + + # If we get here, we're compatible. + return true + end + + protected + + # + # 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: + # + # Compat:: direct compat definitions + # PayloadCompat:: payload compatibilities + # EncoderCompat:: encoder compatibilities + # NopCompat:: nop compatibilities + # + # 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 + c = module_info['Compat'] + + if (c == nil) + c = module_info['Compat'] = Hash.new + end + + # 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 +end \ No newline at end of file From 4d9f7db15a2b1aed77782bfd9a1a323fcc5eb07d Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 09:29:31 -0500 Subject: [PATCH 07/51] Extract Msf::Module::Compatibility MSP-11126 --- spec/lib/msf/core/module_spec.rb | 4 +--- spec/support/shared/examples/msf/module/compatibility.rb | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/compatibility.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 1d2048a73b..dde97c7a11 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -45,8 +45,6 @@ describe Msf::Module do it { is_expected.to respond_to :auxiliary? } it { is_expected.to respond_to :check } it { is_expected.to respond_to :comm } - it { is_expected.to respond_to :compat } - it { is_expected.to respond_to :compatible? } it { is_expected.to respond_to :debugging? } it { is_expected.to respond_to :deregister_options } it { is_expected.to respond_to :derived_implementor? } @@ -62,7 +60,6 @@ describe Msf::Module do it { is_expected.to respond_to :fullname } it { is_expected.to respond_to :generate_uuid } it { is_expected.to respond_to :info_fixups } - it { is_expected.to respond_to :init_compat } it { is_expected.to respond_to :merge_check_key } it { is_expected.to respond_to :merge_info } it { is_expected.to respond_to :merge_info_advanced_options } @@ -114,6 +111,7 @@ describe Msf::Module do it { is_expected.to respond_to :vprint_warning } it { is_expected.to respond_to :workspace } + it_should_behave_like 'Msf::Module::Compatibility' it_should_behave_like 'Msf::Module::DataStore' it_should_behave_like 'Msf::Module::ModuleStore' diff --git a/spec/support/shared/examples/msf/module/compatibility.rb b/spec/support/shared/examples/msf/module/compatibility.rb new file mode 100644 index 0000000000..bf9933379b --- /dev/null +++ b/spec/support/shared/examples/msf/module/compatibility.rb @@ -0,0 +1,5 @@ +shared_examples_for 'Msf::Module::Compatibility' do + it { is_expected.to respond_to :compat } + it { is_expected.to respond_to :compatible? } + it { is_expected.to respond_to :init_compat } +end From bc2bd996984d204609df889eae14b416511deed8 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 09:39:30 -0500 Subject: [PATCH 08/51] Extract Msf::Module::UI::Message MSP-11126 --- lib/msf/core/module.rb | 48 ++----------------------------- lib/msf/core/module/ui.rb | 13 +++++++++ lib/msf/core/module/ui/message.rb | 36 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 46 deletions(-) create mode 100644 lib/msf/core/module/ui.rb create mode 100644 lib/msf/core/module/ui/message.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index d68da9132c..e73a4a34bf 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -16,17 +16,12 @@ class Module autoload :DataStore, 'msf/core/module/data_store' autoload :ModuleStore, 'msf/core/module/module_store' autoload :ModuleStore, 'msf/core/module/module_store' + autoload :UI, 'msf/core/module/ui' include Msf::Module::Compatibility include Msf::Module::DataStore include Msf::Module::ModuleStore - - # 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 + include Msf::Module::UI # Make include public so we can runtime extend public_class_method :include @@ -181,45 +176,6 @@ class Module obj end - # - # Overwrite the Subscriber print_(status|error|good) to do time stamps - # - - def print_prefix - ret = '' - if (datastore['TimestampOutput'] =~ /^(t|y|1)/i) || ( - framework && framework.datastore['TimestampOutput'] =~ /^(t|y|1)/i - ) - 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 - - ret = prefix - end - ret - end - - def print_status(msg='') - super(print_prefix + msg) - end - - def print_error(msg='') - super(print_prefix + msg) - end - - def print_good(msg='') - super(print_prefix + msg) - end - - def print_warning(msg='') - super(print_prefix + msg) - end - - # # Overwrite the Subscriber print_line to do custom prefixes # diff --git a/lib/msf/core/module/ui.rb b/lib/msf/core/module/ui.rb new file mode 100644 index 0000000000..4518d62216 --- /dev/null +++ b/lib/msf/core/module/ui.rb @@ -0,0 +1,13 @@ +module Msf::Module::UI + autoload :Message, 'msf/core/module/ui/message' + + # 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 + + # Overwrite the {Rex::Ui::Subscriber} print_(status|error|good) to do time stamps + include Msf::Module::UI::Message +end \ No newline at end of file diff --git a/lib/msf/core/module/ui/message.rb b/lib/msf/core/module/ui/message.rb new file mode 100644 index 0000000000..764930a18b --- /dev/null +++ b/lib/msf/core/module/ui/message.rb @@ -0,0 +1,36 @@ +# Methods for print messages with status indicators +module Msf::Module::UI::Message + def print_error(msg='') + super(print_prefix + msg) + end + + def print_good(msg='') + super(print_prefix + msg) + end + + def print_prefix + ret = '' + if (datastore['TimestampOutput'] =~ /^(t|y|1)/i) || ( + framework && framework.datastore['TimestampOutput'] =~ /^(t|y|1)/i + ) + 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 + + ret = prefix + end + ret + end + + def print_status(msg='') + super(print_prefix + msg) + end + + def print_warning(msg='') + super(print_prefix + msg) + end +end \ No newline at end of file From 96864b38925fc89506c2f7fa8f6559ae8d23432d Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 09:45:17 -0500 Subject: [PATCH 09/51] Extract Msf::Module::UI::Message shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 6 +----- spec/support/shared/examples/msf/module/ui.rb | 3 +++ spec/support/shared/examples/msf/module/ui/message.rb | 7 +++++++ 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/ui.rb create mode 100644 spec/support/shared/examples/msf/module/ui/message.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index dde97c7a11..4bfc2c9bf1 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -78,13 +78,8 @@ describe Msf::Module do it { is_expected.to respond_to :platform? } it { is_expected.to respond_to :platform_to_s } it { is_expected.to respond_to :post? } - it { is_expected.to respond_to :print_error } - it { is_expected.to respond_to :print_good } it { is_expected.to respond_to :print_line } it { is_expected.to respond_to :print_line_prefix } - it { is_expected.to respond_to :print_prefix } - it { is_expected.to respond_to :print_status } - it { is_expected.to respond_to :print_warning } it { is_expected.to respond_to :privileged? } it { is_expected.to respond_to :rank } it { is_expected.to respond_to :rank_to_h } @@ -114,6 +109,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::Compatibility' it_should_behave_like 'Msf::Module::DataStore' it_should_behave_like 'Msf::Module::ModuleStore' + it_should_behave_like 'Msf::Module::UI' context 'CONSTANTS' do context 'UpdateableOptions' do diff --git a/spec/support/shared/examples/msf/module/ui.rb b/spec/support/shared/examples/msf/module/ui.rb new file mode 100644 index 0000000000..455e302839 --- /dev/null +++ b/spec/support/shared/examples/msf/module/ui.rb @@ -0,0 +1,3 @@ +shared_examples_for 'Msf::Module::UI' do + it_should_behave_like 'Msf::Module::UI::Message' +end \ No newline at end of file diff --git a/spec/support/shared/examples/msf/module/ui/message.rb b/spec/support/shared/examples/msf/module/ui/message.rb new file mode 100644 index 0000000000..72f4fae72b --- /dev/null +++ b/spec/support/shared/examples/msf/module/ui/message.rb @@ -0,0 +1,7 @@ +shared_examples_for 'Msf::Module::UI::Message' do + it { is_expected.to respond_to :print_error } + it { is_expected.to respond_to :print_good } + it { is_expected.to respond_to :print_prefix } + it { is_expected.to respond_to :print_status } + it { is_expected.to respond_to :print_warning } +end \ No newline at end of file From a9a6f0c5f9009ef161caf268e61d075af7526406 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 09:50:07 -0500 Subject: [PATCH 10/51] Extract Msf::Module::UI::Line MSP-11126 --- lib/msf/core/module.rb | 12 ------------ lib/msf/core/module/ui.rb | 3 +++ lib/msf/core/module/ui/line.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 lib/msf/core/module/ui/line.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index e73a4a34bf..e526409ca6 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -176,18 +176,6 @@ class Module obj end - # - # Overwrite the Subscriber print_line to do custom prefixes - # - - def print_line_prefix - datastore['CustomPrintPrefix'] || framework.datastore['CustomPrintPrefix'] || '' - end - - def print_line(msg='') - super(print_line_prefix + msg) - end - # Verbose version of #print_status def vprint_status(msg) print_status(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE'] diff --git a/lib/msf/core/module/ui.rb b/lib/msf/core/module/ui.rb index 4518d62216..2cbd697896 100644 --- a/lib/msf/core/module/ui.rb +++ b/lib/msf/core/module/ui.rb @@ -1,4 +1,5 @@ module Msf::Module::UI + autoload :Line, 'msf/core/module/ui/line' autoload :Message, 'msf/core/module/ui/message' # Modules can subscribe to a user-interface, and as such they include the @@ -8,6 +9,8 @@ module Msf::Module::UI # interacting with the user, n stuff. include Rex::Ui::Subscriber + # Overwrite the {Rex::UI::Subscriber#print_line} to do custom prefixes + include Msf::Module::UI::Line # Overwrite the {Rex::Ui::Subscriber} print_(status|error|good) to do time stamps include Msf::Module::UI::Message end \ No newline at end of file diff --git a/lib/msf/core/module/ui/line.rb b/lib/msf/core/module/ui/line.rb new file mode 100644 index 0000000000..f923c956b1 --- /dev/null +++ b/lib/msf/core/module/ui/line.rb @@ -0,0 +1,9 @@ +module Msf::Module::UI::Line + def print_line(msg='') + super(print_line_prefix + msg) + end + + def print_line_prefix + datastore['CustomPrintPrefix'] || framework.datastore['CustomPrintPrefix'] || '' + end +end From a3afb92ee2884d670c2a1b5101c3e3425530d783 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 09:51:23 -0500 Subject: [PATCH 11/51] Extract Msf::Module::UI::Line shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 2 -- spec/support/shared/examples/msf/module/ui.rb | 1 + spec/support/shared/examples/msf/module/ui/line.rb | 4 ++++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/ui/line.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 4bfc2c9bf1..e6da41a184 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -78,8 +78,6 @@ describe Msf::Module do it { is_expected.to respond_to :platform? } it { is_expected.to respond_to :platform_to_s } it { is_expected.to respond_to :post? } - it { is_expected.to respond_to :print_line } - it { is_expected.to respond_to :print_line_prefix } it { is_expected.to respond_to :privileged? } it { is_expected.to respond_to :rank } it { is_expected.to respond_to :rank_to_h } diff --git a/spec/support/shared/examples/msf/module/ui.rb b/spec/support/shared/examples/msf/module/ui.rb index 455e302839..ca1f26232e 100644 --- a/spec/support/shared/examples/msf/module/ui.rb +++ b/spec/support/shared/examples/msf/module/ui.rb @@ -1,3 +1,4 @@ shared_examples_for 'Msf::Module::UI' do + it_should_behave_like 'Msf::Module::UI::Line' it_should_behave_like 'Msf::Module::UI::Message' end \ No newline at end of file diff --git a/spec/support/shared/examples/msf/module/ui/line.rb b/spec/support/shared/examples/msf/module/ui/line.rb new file mode 100644 index 0000000000..311f555120 --- /dev/null +++ b/spec/support/shared/examples/msf/module/ui/line.rb @@ -0,0 +1,4 @@ +shared_examples_for 'Msf::Module::UI::Line' do + it { is_expected.to respond_to :print_line } + it { is_expected.to respond_to :print_line_prefix } +end \ No newline at end of file From c50cb2eb8a76cc3e293bea2ff9359a738c31a5c6 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 10:05:45 -0500 Subject: [PATCH 12/51] Extract Msf::Module::UI::*::Verbose and shared examples MSP-11126 --- lib/msf/core/module.rb | 25 ------------------ lib/msf/core/module/ui/line.rb | 4 +++ lib/msf/core/module/ui/line/verbose.rb | 6 +++++ lib/msf/core/module/ui/message.rb | 4 +++ lib/msf/core/module/ui/message/verbose.rb | 26 +++++++++++++++++++ spec/lib/msf/core/module_spec.rb | 6 ----- .../shared/examples/msf/module/ui/line.rb | 2 ++ .../examples/msf/module/ui/line/verbose.rb | 3 +++ .../shared/examples/msf/module/ui/message.rb | 2 ++ .../examples/msf/module/ui/message/verbose.rb | 7 +++++ 10 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 lib/msf/core/module/ui/line/verbose.rb create mode 100644 lib/msf/core/module/ui/message/verbose.rb create mode 100644 spec/support/shared/examples/msf/module/ui/line/verbose.rb create mode 100644 spec/support/shared/examples/msf/module/ui/message/verbose.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index e526409ca6..930ad0657d 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -176,31 +176,6 @@ class Module obj end - # 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 - # Verbose version of #print_debug - def vprint_debug(msg) - print_debug(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE'] - end - # Verbose version of #print_warning - def vprint_warning(msg) - print_warning(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE'] - end - # # Returns the module's framework full reference name. This is the # short name that end-users work with (refname) plus the type diff --git a/lib/msf/core/module/ui/line.rb b/lib/msf/core/module/ui/line.rb index f923c956b1..abfaedd22b 100644 --- a/lib/msf/core/module/ui/line.rb +++ b/lib/msf/core/module/ui/line.rb @@ -1,4 +1,8 @@ module Msf::Module::UI::Line + autoload :Verbose, 'msf/core/module/ui/line/verbose' + + include Msf::Module::UI::Line::Verbose + def print_line(msg='') super(print_line_prefix + msg) end diff --git a/lib/msf/core/module/ui/line/verbose.rb b/lib/msf/core/module/ui/line/verbose.rb new file mode 100644 index 0000000000..399ef5c82b --- /dev/null +++ b/lib/msf/core/module/ui/line/verbose.rb @@ -0,0 +1,6 @@ +module Msf::Module::UI::Line::Verbose + # Verbose version of #print_line + def vprint_line(msg) + print_line(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE'] + end +end \ No newline at end of file diff --git a/lib/msf/core/module/ui/message.rb b/lib/msf/core/module/ui/message.rb index 764930a18b..7370ded212 100644 --- a/lib/msf/core/module/ui/message.rb +++ b/lib/msf/core/module/ui/message.rb @@ -1,5 +1,9 @@ # Methods for print messages with status indicators module Msf::Module::UI::Message + autoload :Verbose, 'msf/core/module/ui/message/verbose' + + include Msf::Module::UI::Message::Verbose + def print_error(msg='') super(print_prefix + msg) end diff --git a/lib/msf/core/module/ui/message/verbose.rb b/lib/msf/core/module/ui/message/verbose.rb new file mode 100644 index 0000000000..089960cbfc --- /dev/null +++ b/lib/msf/core/module/ui/message/verbose.rb @@ -0,0 +1,26 @@ +module Msf::Module::UI::Message::Verbose + # Verbose version of #print_debug + def vprint_debug(msg) + print_debug(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_status + def vprint_status(msg) + print_status(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE'] + end + + # Verbose version of #print_warning + def vprint_warning(msg) + print_warning(msg) if datastore['VERBOSE'] || framework.datastore['VERBOSE'] + end +end \ No newline at end of file diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index e6da41a184..ae19f5301b 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -96,12 +96,6 @@ describe Msf::Module do it { is_expected.to respond_to :type } it { is_expected.to respond_to :update_info } it { is_expected.to respond_to :validate } - it { is_expected.to respond_to :vprint_debug } - it { is_expected.to respond_to :vprint_error } - it { is_expected.to respond_to :vprint_good } - it { is_expected.to respond_to :vprint_line } - it { is_expected.to respond_to :vprint_status } - it { is_expected.to respond_to :vprint_warning } it { is_expected.to respond_to :workspace } it_should_behave_like 'Msf::Module::Compatibility' diff --git a/spec/support/shared/examples/msf/module/ui/line.rb b/spec/support/shared/examples/msf/module/ui/line.rb index 311f555120..4835d802b5 100644 --- a/spec/support/shared/examples/msf/module/ui/line.rb +++ b/spec/support/shared/examples/msf/module/ui/line.rb @@ -1,4 +1,6 @@ shared_examples_for 'Msf::Module::UI::Line' do + it_should_behave_like 'Msf::Module::UI::Line::Verbose' + it { is_expected.to respond_to :print_line } it { is_expected.to respond_to :print_line_prefix } end \ No newline at end of file diff --git a/spec/support/shared/examples/msf/module/ui/line/verbose.rb b/spec/support/shared/examples/msf/module/ui/line/verbose.rb new file mode 100644 index 0000000000..f5bcfbd63c --- /dev/null +++ b/spec/support/shared/examples/msf/module/ui/line/verbose.rb @@ -0,0 +1,3 @@ +shared_examples_for 'Msf::Module::UI::Line::Verbose' do + it { is_expected.to respond_to :vprint_line } +end diff --git a/spec/support/shared/examples/msf/module/ui/message.rb b/spec/support/shared/examples/msf/module/ui/message.rb index 72f4fae72b..1aef68f978 100644 --- a/spec/support/shared/examples/msf/module/ui/message.rb +++ b/spec/support/shared/examples/msf/module/ui/message.rb @@ -1,4 +1,6 @@ shared_examples_for 'Msf::Module::UI::Message' do + it_should_behave_like 'Msf::Module::UI::Message::Verbose' + it { is_expected.to respond_to :print_error } it { is_expected.to respond_to :print_good } it { is_expected.to respond_to :print_prefix } diff --git a/spec/support/shared/examples/msf/module/ui/message/verbose.rb b/spec/support/shared/examples/msf/module/ui/message/verbose.rb new file mode 100644 index 0000000000..eb250134a2 --- /dev/null +++ b/spec/support/shared/examples/msf/module/ui/message/verbose.rb @@ -0,0 +1,7 @@ +shared_examples_for 'Msf::Module::UI::Message::Verbose' do + it { is_expected.to respond_to :vprint_debug } + it { is_expected.to respond_to :vprint_error } + it { is_expected.to respond_to :vprint_good } + it { is_expected.to respond_to :vprint_status } + it { is_expected.to respond_to :vprint_warning } +end \ No newline at end of file From f9caa4d25e74edd718e68d420aa6d72b119c6256 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 11:14:42 -0500 Subject: [PATCH 13/51] Extract Msf::Module::Options MSP-11126 Methods for registering, derigsterings, and validating options. --- lib/msf/core/module.rb | 57 +++-------------------------- lib/msf/core/module/options.rb | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 53 deletions(-) create mode 100644 lib/msf/core/module/options.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 930ad0657d..33fae15d0d 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -15,12 +15,13 @@ class Module autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' autoload :ModuleStore, 'msf/core/module/module_store' - autoload :ModuleStore, 'msf/core/module/module_store' + autoload :Options, 'msf/core/module/options' autoload :UI, 'msf/core/module/ui' include Msf::Module::Compatibility include Msf::Module::DataStore include Msf::Module::ModuleStore + include Msf::Module::Options include Msf::Module::UI # Make include public so we can runtime extend @@ -411,15 +412,6 @@ class Module Rex::Socket::Comm::Local end - # - # 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 - # # Returns true if this module is being debugged. The debug flag is set # by setting datastore['DEBUG'] to 1|true|yes @@ -623,10 +615,7 @@ class Module # The reference count for the module. # attr_reader :references - # - # The module-specific options. - # - attr_reader :options + # # Whether or not this module requires privileged access. # @@ -697,44 +686,6 @@ protected end end - # - # Register options with a specific owning class. - # - def register_options(options, owner = self.class) - self.options.add_options(options, owner) - self.datastore.import_options(self.options, 'self', true) - import_defaults(false) - end - - # - # Register advanced options with a specific owning class. - # - def register_advanced_options(options, owner = self.class) - self.options.add_advanced_options(options, owner) - self.datastore.import_options(self.options, 'self', true) - import_defaults(false) - end - - # - # Register evasion options with a specific owning class. - # - def register_evasion_options(options, owner = self.class) - self.options.add_evasion_options(options, owner) - self.datastore.import_options(self.options, 'self', true) - import_defaults(false) - end - - # - # Removes the supplied options from the module's option container - # and data store. - # - def deregister_options(*names) - names.each { |name| - self.options.remove_option(name) - self.datastore.delete(name) - } - end - # # 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 @@ -893,7 +844,7 @@ protected end attr_accessor :module_info # :nodoc: - attr_writer :author, :arch, :platform, :references, :options # :nodoc: + attr_writer :author, :arch, :platform, :references # :nodoc: attr_writer :privileged # :nodoc: attr_writer :license # :nodoc: diff --git a/lib/msf/core/module/options.rb b/lib/msf/core/module/options.rb new file mode 100644 index 0000000000..244d5000e4 --- /dev/null +++ b/lib/msf/core/module/options.rb @@ -0,0 +1,65 @@ +# Register, deregister, and validate {#options}. +module Msf::Module::Options + # + # Attributes + # + + # @attribute [r] options + # The module-specific options. + attr_reader :options + + # + # Instance Methods + # + + # + # 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 + + protected + + # + # Removes the supplied options from the module's option container + # and data store. + # + def deregister_options(*names) + names.each { |name| + self.options.remove_option(name) + self.datastore.delete(name) + } + end + + attr_writer :options + + # + # Register advanced options with a specific owning class. + # + def register_advanced_options(options, owner = self.class) + self.options.add_advanced_options(options, owner) + self.datastore.import_options(self.options, 'self', true) + import_defaults(false) + end + + # + # Register evasion options with a specific owning class. + # + def register_evasion_options(options, owner = self.class) + self.options.add_evasion_options(options, owner) + self.datastore.import_options(self.options, 'self', true) + import_defaults(false) + end + + # + # Register options with a specific owning class. + # + def register_options(options, owner = self.class) + self.options.add_options(options, owner) + self.datastore.import_options(self.options, 'self', true) + import_defaults(false) + end +end \ No newline at end of file From f8ada87e86d6506a378d4d22fcf9b67ad21a9b7b Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 11:24:03 -0500 Subject: [PATCH 14/51] Extract Msf::Module::Options shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 6 +----- spec/support/shared/examples/msf/module/options.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/options.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index ae19f5301b..278ba8ce61 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -46,7 +46,6 @@ describe Msf::Module do it { is_expected.to respond_to :check } it { is_expected.to respond_to :comm } it { is_expected.to respond_to :debugging? } - it { is_expected.to respond_to :deregister_options } it { is_expected.to respond_to :derived_implementor? } it { is_expected.to respond_to :description } it { is_expected.to respond_to :disclosure_date } @@ -83,9 +82,6 @@ describe Msf::Module do it { is_expected.to respond_to :rank_to_h } it { is_expected.to respond_to :rank_to_s } it { is_expected.to respond_to :refname } - it { is_expected.to respond_to :register_advanced_options } - it { is_expected.to respond_to :register_evasion_options } - it { is_expected.to respond_to :register_options } it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } it { is_expected.to respond_to :set_defaults } @@ -95,12 +91,12 @@ describe Msf::Module do it { is_expected.to respond_to :target_port } it { is_expected.to respond_to :type } it { is_expected.to respond_to :update_info } - it { is_expected.to respond_to :validate } it { is_expected.to respond_to :workspace } it_should_behave_like 'Msf::Module::Compatibility' it_should_behave_like 'Msf::Module::DataStore' it_should_behave_like 'Msf::Module::ModuleStore' + it_should_behave_like 'Msf::Module::Options' it_should_behave_like 'Msf::Module::UI' context 'CONSTANTS' do diff --git a/spec/support/shared/examples/msf/module/options.rb b/spec/support/shared/examples/msf/module/options.rb new file mode 100644 index 0000000000..75dc97ac71 --- /dev/null +++ b/spec/support/shared/examples/msf/module/options.rb @@ -0,0 +1,8 @@ +shared_examples_for 'Msf::Module::Options' do + it { is_expected.to respond_to :deregister_options } + it { is_expected.to respond_to :options } + it { is_expected.to respond_to :validate } + it { is_expected.to respond_to :register_advanced_options } + it { is_expected.to respond_to :register_evasion_options } + it { is_expected.to respond_to :register_options } +end \ No newline at end of file From 31c93e9dbc3c91e55b6f2ed9ad60a4cfc23e91cc Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 13:01:42 -0500 Subject: [PATCH 15/51] Extract Msf::Module::ModuleInfo MSP-11126 --- lib/msf/core/module.rb | 202 +------------------------- lib/msf/core/module/module_info.rb | 220 +++++++++++++++++++++++++++++ 2 files changed, 222 insertions(+), 200 deletions(-) create mode 100644 lib/msf/core/module/module_info.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 33fae15d0d..628822ea98 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -14,12 +14,14 @@ module Msf class Module autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' + autoload :ModuleInfo, 'msf/core/module/module_info' autoload :ModuleStore, 'msf/core/module/module_store' autoload :Options, 'msf/core/module/options' autoload :UI, 'msf/core/module/ui' include Msf::Module::Compatibility include Msf::Module::DataStore + include Msf::Module::ModuleInfo include Msf::Module::ModuleStore include Msf::Module::Options include Msf::Module::UI @@ -244,35 +246,6 @@ class Module self.class.file_path end - # - # Return the module's name from the module information hash. - # - def name - module_info['Name'] - end - - # - # Returns the module's alias, if it has one. Otherwise, the module's - # name is returned. - # - def alias - module_info['Alias'] - end - - # - # Return the module's description. - # - def description - module_info['Description'] - end - - # - # Returns the disclosure date, if known. - # - def disclosure_date - date_str = Date.parse(module_info['DisclosureDate'].to_s) rescue nil - end - # # Checks to see if the target is vulnerable, returning unsupported if it's # not supported. @@ -645,10 +618,6 @@ protected def generate_uuid self.uuid = Rex::Text.rand_text_alphanumeric(8).downcase end - # - # The list of options that support merging in an information hash. - # - UpdateableOptions = [ "Name", "Description", "Alias", "PayloadCompat" ] # # Sets the modules unsupplied info fields to their default values. @@ -668,24 +637,6 @@ protected self.module_store = {} end - # - # 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| - if !(refs[i].respond_to?('[]') and refs[i].length == 2) - refs[i] = nil - end - end - - # Purge invalid references - refs.delete(nil) - end - end - # # 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 @@ -695,155 +646,6 @@ protected (self.method(method_name).to_s.match(/#{parent}[^:]/)) ? false : true end - # - # 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| - merge_check_key(info, name, val) - } - - 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) - info[name] = val - end - # Otherwise, perform the merge operation like normal - else - merge_check_key(info, name, val) - end - } - - return info - end - - # - # Checks and merges the supplied key/value pair in the supplied hash. - # - 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] - 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 - end - # Otherwise, just set the value equal if no current value - # exists - else - info[name] = val - end - end - end - - # - # Merge aliases with an underscore delimiter. - # - def merge_info_alias(info, val) - merge_info_string(info, 'Alias', val, '_') - end - - # - # Merges the module name. - # - def merge_info_name(info, val) - merge_info_string(info, 'Name', val, ', ', true) - end - - # - # Merges the module description. - # - def merge_info_description(info, val) - merge_info_string(info, 'Description', val, ". ", true) - end - - # - # Merge the module version. - # - def merge_info_version(info, val) - merge_info_string(info, 'Version', val) - end - - # - # Merges a given key in the info hash with a delimiter. - # - def merge_info_string(info, key, val, delim = ', ', inverse = false) - if (info[key]) - if (inverse == true) - info[key] = info[key] + delim + val - else - info[key] = val + delim + info[key] - end - else - info[key] = val - end - end - - # - # Merges options. - # - def merge_info_options(info, val, advanced = false, evasion = false) - - key_name = ((advanced) ? 'Advanced' : (evasion) ? 'Evasion' : '') + 'Options' - - new_cont = OptionContainer.new - new_cont.add_options(val, advanced, evasion) - cur_cont = OptionContainer.new - cur_cont.add_options(info[key_name] || [], advanced, evasion) - - new_cont.each_option { |name, option| - next if (cur_cont.get(name)) - - info[key_name] = [] if (!info[key_name]) - info[key_name] << option - } - end - - # - # Merges advanced options. - # - def merge_info_advanced_options(info, val) - merge_info_options(info, val, true, false) - end - - # - # Merges advanced options. - # - def merge_info_evasion_options(info, val) - merge_info_options(info, val, false, true) - end - - attr_accessor :module_info # :nodoc: attr_writer :author, :arch, :platform, :references # :nodoc: attr_writer :privileged # :nodoc: attr_writer :license # :nodoc: diff --git a/lib/msf/core/module/module_info.rb b/lib/msf/core/module/module_info.rb new file mode 100644 index 0000000000..a341b91bc5 --- /dev/null +++ b/lib/msf/core/module/module_info.rb @@ -0,0 +1,220 @@ +module Msf::Module::ModuleInfo + # + # CONSTANTS + # + + # The list of options that support merging in an information hash. + UpdateableOptions = [ "Name", "Description", "Alias", "PayloadCompat" ] + + # + # Instance Methods + # + + # + # Returns the module's alias, if it has one. Otherwise, the module's + # name is returned. + # + def alias + module_info['Alias'] + end + + # + # Return the module's description. + # + def description + module_info['Description'] + end + + # + # Returns the disclosure date, if known. + # + def disclosure_date + date_str = Date.parse(module_info['DisclosureDate'].to_s) rescue nil + end + + # + # Return the module's name from the module information hash. + # + def name + module_info['Name'] + end + + protected + + # + # Attributes + # + + # @!attribute module_info + attr_accessor :module_info + + # + # Instance Methods + # + + # + # 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| + if !(refs[i].respond_to?('[]') and refs[i].length == 2) + refs[i] = nil + end + end + + # Purge invalid references + refs.delete(nil) + end + end + + # + # Checks and merges the supplied key/value pair in the supplied hash. + # + 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] + 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 + end + # Otherwise, just set the value equal if no current value + # exists + else + info[name] = val + end + end + end + + # + # 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| + merge_check_key(info, name, val) + } + + info + end + + # + # Merges advanced options. + # + def merge_info_advanced_options(info, val) + merge_info_options(info, val, true, false) + end + + # + # Merge aliases with an underscore delimiter. + # + def merge_info_alias(info, val) + merge_info_string(info, 'Alias', val, '_') + end + + # + # Merges the module description. + # + def merge_info_description(info, val) + merge_info_string(info, 'Description', val, ". ", true) + end + + # + # Merges advanced options. + # + def merge_info_evasion_options(info, val) + merge_info_options(info, val, false, true) + end + + # + # Merges the module name. + # + def merge_info_name(info, val) + merge_info_string(info, 'Name', val, ', ', true) + end + + # + # Merges options. + # + def merge_info_options(info, val, advanced = false, evasion = false) + + key_name = ((advanced) ? 'Advanced' : (evasion) ? 'Evasion' : '') + 'Options' + + new_cont = OptionContainer.new + new_cont.add_options(val, advanced, evasion) + cur_cont = OptionContainer.new + cur_cont.add_options(info[key_name] || [], advanced, evasion) + + new_cont.each_option { |name, option| + next if (cur_cont.get(name)) + + info[key_name] = [] if (!info[key_name]) + info[key_name] << option + } + end + + # + # Merges a given key in the info hash with a delimiter. + # + def merge_info_string(info, key, val, delim = ', ', inverse = false) + if (info[key]) + if (inverse == true) + info[key] = info[key] + delim + val + else + info[key] = val + delim + info[key] + end + else + info[key] = val + end + end + + # + # Merge the module version. + # + def merge_info_version(info, val) + merge_info_string(info, 'Version', val) + 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) + info[name] = val + end + # Otherwise, perform the merge operation like normal + else + merge_check_key(info, name, val) + end + } + + return info + end +end \ No newline at end of file From a2dc3b754f5ead1f98a2926cb241dd82fd4ed0dd Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 13:10:15 -0500 Subject: [PATCH 16/51] Extract Msf::Module::ModuleInfo shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 27 +----------------- .../shared/examples/msf/module/module_info.rb | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 26 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/module_info.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 278ba8ce61..e67aeaada4 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -38,7 +38,6 @@ end REF_TYPES = %w(CVE BID OSVDB EDB) describe Msf::Module do - it { is_expected.to respond_to :alias } it { is_expected.to respond_to :arch? } it { is_expected.to respond_to :arch_to_s } it { is_expected.to respond_to :author_to_s } @@ -47,8 +46,6 @@ describe Msf::Module do it { is_expected.to respond_to :comm } it { is_expected.to respond_to :debugging? } it { is_expected.to respond_to :derived_implementor? } - it { is_expected.to respond_to :description } - it { is_expected.to respond_to :disclosure_date } it { is_expected.to respond_to :each_arch } it { is_expected.to respond_to :each_author } it { is_expected.to respond_to :encoder? } @@ -58,18 +55,6 @@ describe Msf::Module do it { is_expected.to respond_to :framework } it { is_expected.to respond_to :fullname } it { is_expected.to respond_to :generate_uuid } - it { is_expected.to respond_to :info_fixups } - it { is_expected.to respond_to :merge_check_key } - it { is_expected.to respond_to :merge_info } - it { is_expected.to respond_to :merge_info_advanced_options } - it { is_expected.to respond_to :merge_info_alias } - it { is_expected.to respond_to :merge_info_description } - it { is_expected.to respond_to :merge_info_evasion_options } - it { is_expected.to respond_to :merge_info_name } - it { is_expected.to respond_to :merge_info_options } - it { is_expected.to respond_to :merge_info_string } - it { is_expected.to respond_to :merge_info_version } - it { is_expected.to respond_to :name } it { is_expected.to respond_to :nop? } it { is_expected.to respond_to :orig_cls } it { is_expected.to respond_to :owner } @@ -90,25 +75,15 @@ describe Msf::Module do it { is_expected.to respond_to :target_host } it { is_expected.to respond_to :target_port } it { is_expected.to respond_to :type } - it { is_expected.to respond_to :update_info } it { is_expected.to respond_to :workspace } it_should_behave_like 'Msf::Module::Compatibility' it_should_behave_like 'Msf::Module::DataStore' + it_should_behave_like 'Msf::Module::ModuleInfo' it_should_behave_like 'Msf::Module::ModuleStore' it_should_behave_like 'Msf::Module::Options' it_should_behave_like 'Msf::Module::UI' - context 'CONSTANTS' do - context 'UpdateableOptions' do - subject(:updateable_options) { - described_class::UpdateableOptions - } - - it { is_expected.to match_array(%w{Name Description Alias PayloadCompat})} - end - end - context 'class' do subject { described_class diff --git a/spec/support/shared/examples/msf/module/module_info.rb b/spec/support/shared/examples/msf/module/module_info.rb new file mode 100644 index 0000000000..dbc310eaeb --- /dev/null +++ b/spec/support/shared/examples/msf/module/module_info.rb @@ -0,0 +1,28 @@ +shared_examples_for 'Msf::Module::ModuleInfo' do + context 'CONSTANTS' do + context 'UpdateableOptions' do + subject(:updateable_options) { + described_class::UpdateableOptions + } + + it { is_expected.to match_array(%w{Name Description Alias PayloadCompat})} + end + end + + it { is_expected.to respond_to :alias } + it { is_expected.to respond_to :description } + it { is_expected.to respond_to :disclosure_date } + it { is_expected.to respond_to :info_fixups } + it { is_expected.to respond_to :merge_check_key } + it { is_expected.to respond_to :merge_info } + it { is_expected.to respond_to :merge_info_advanced_options } + it { is_expected.to respond_to :merge_info_alias } + it { is_expected.to respond_to :merge_info_description } + it { is_expected.to respond_to :merge_info_evasion_options } + it { is_expected.to respond_to :merge_info_name } + it { is_expected.to respond_to :merge_info_options } + it { is_expected.to respond_to :merge_info_string } + it { is_expected.to respond_to :merge_info_version } + it { is_expected.to respond_to :name } + it { is_expected.to respond_to :update_info } +end \ No newline at end of file From 44b2e5e35c454a8c2d4499ecf1ecfd84c296191e Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 13:14:56 -0500 Subject: [PATCH 17/51] Extract Msf::Module::Arch MSP-11126 --- lib/msf/core/module.rb | 27 ++------------------------- lib/msf/core/module/arch.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 lib/msf/core/module/arch.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 628822ea98..9b3dbdc782 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -12,6 +12,7 @@ module Msf # ### class Module + autoload :Arch, 'msf/core/module/arch' autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' autoload :ModuleInfo, 'msf/core/module/module_info' @@ -19,6 +20,7 @@ class Module autoload :Options, 'msf/core/module/options' autoload :UI, 'msf/core/module/ui' + include Msf::Module::Arch include Msf::Module::Compatibility include Msf::Module::DataStore include Msf::Module::ModuleInfo @@ -331,31 +333,6 @@ class Module author.each(&block) end - # - # Return a comma separated list of supported architectures, if any. - # - def arch_to_s - arch.join(", ") - end - - # - # Enumerate each architecture. - # - def each_arch(&block) - arch.each(&block) - end - - # - # Return whether or not the module supports the supplied architecture. - # - def arch?(what) - if (what == ARCH_ANY) - true - else - arch.index(what) != nil - end - end - # # Return a comma separated list of supported platforms, if any. # diff --git a/lib/msf/core/module/arch.rb b/lib/msf/core/module/arch.rb new file mode 100644 index 0000000000..a5ab67d7db --- /dev/null +++ b/lib/msf/core/module/arch.rb @@ -0,0 +1,26 @@ +module Msf::Module::Arch + # + # Return whether or not the module supports the supplied architecture. + # + def arch?(what) + if (what == ARCH_ANY) + true + else + arch.index(what) != nil + end + end + + # + # Return a comma separated list of supported architectures, if any. + # + def arch_to_s + arch.join(", ") + end + + # + # Enumerate each architecture. + # + def each_arch(&block) + arch.each(&block) + end +end \ No newline at end of file From 28af6a490b22fa4eec1b1b48bd35497e84def0e3 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 13:16:57 -0500 Subject: [PATCH 18/51] Extract Msf::Module::Arch shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 4 +--- spec/support/shared/examples/msf/module/arch.rb | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/arch.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index e67aeaada4..ac98fd7ef0 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -38,15 +38,12 @@ end REF_TYPES = %w(CVE BID OSVDB EDB) describe Msf::Module do - it { is_expected.to respond_to :arch? } - it { is_expected.to respond_to :arch_to_s } it { is_expected.to respond_to :author_to_s } it { is_expected.to respond_to :auxiliary? } it { is_expected.to respond_to :check } it { is_expected.to respond_to :comm } it { is_expected.to respond_to :debugging? } it { is_expected.to respond_to :derived_implementor? } - it { is_expected.to respond_to :each_arch } it { is_expected.to respond_to :each_author } it { is_expected.to respond_to :encoder? } it { is_expected.to respond_to :exploit? } @@ -77,6 +74,7 @@ describe Msf::Module do it { is_expected.to respond_to :type } it { is_expected.to respond_to :workspace } + it_should_behave_like 'Msf::Module::Arch' it_should_behave_like 'Msf::Module::Compatibility' it_should_behave_like 'Msf::Module::DataStore' it_should_behave_like 'Msf::Module::ModuleInfo' diff --git a/spec/support/shared/examples/msf/module/arch.rb b/spec/support/shared/examples/msf/module/arch.rb new file mode 100644 index 0000000000..6c2971bad8 --- /dev/null +++ b/spec/support/shared/examples/msf/module/arch.rb @@ -0,0 +1,5 @@ +shared_examples_for 'Msf::Module::Arch' do + it { is_expected.to respond_to :arch? } + it { is_expected.to respond_to :arch_to_s } + it { is_expected.to respond_to :each_arch } +end \ No newline at end of file From e418f98d456d71a42e9a9806d9ce0beff5f6ee81 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 13:21:11 -0500 Subject: [PATCH 19/51] arch -> Msf::Module::Arch MSP-11126 --- lib/msf/core/module.rb | 7 ++----- lib/msf/core/module/arch.rb | 20 +++++++++++++++++++ .../shared/examples/msf/module/arch.rb | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 9b3dbdc782..d82c191f57 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -553,10 +553,7 @@ class Module # 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. # @@ -623,7 +620,7 @@ protected (self.method(method_name).to_s.match(/#{parent}[^:]/)) ? false : true end - attr_writer :author, :arch, :platform, :references # :nodoc: + attr_writer :author, :platform, :references # :nodoc: attr_writer :privileged # :nodoc: attr_writer :license # :nodoc: diff --git a/lib/msf/core/module/arch.rb b/lib/msf/core/module/arch.rb index a5ab67d7db..408c9c9395 100644 --- a/lib/msf/core/module/arch.rb +++ b/lib/msf/core/module/arch.rb @@ -1,4 +1,16 @@ module Msf::Module::Arch + # + # Attributes + # + + # @!attribute arch + # The array of zero or more architectures. + attr_reader :arch + + # + # Instance Methods + # + # # Return whether or not the module supports the supplied architecture. # @@ -23,4 +35,12 @@ module Msf::Module::Arch def each_arch(&block) arch.each(&block) end + + protected + + # + # Attributes + # + + attr_writer :arch end \ No newline at end of file diff --git a/spec/support/shared/examples/msf/module/arch.rb b/spec/support/shared/examples/msf/module/arch.rb index 6c2971bad8..c4140c6f9f 100644 --- a/spec/support/shared/examples/msf/module/arch.rb +++ b/spec/support/shared/examples/msf/module/arch.rb @@ -1,4 +1,5 @@ shared_examples_for 'Msf::Module::Arch' do + it { is_expected.to respond_to :arch } it { is_expected.to respond_to :arch? } it { is_expected.to respond_to :arch_to_s } it { is_expected.to respond_to :each_arch } From e6f442697b0d0ad3bf092fdfffcfbda864a4ffc5 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 14:23:21 -0500 Subject: [PATCH 20/51] Extract Msf::Module::Type MSP-11126 --- lib/msf/core/module.rb | 58 ++------------------------------- lib/msf/core/module/type.rb | 65 +++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 lib/msf/core/module/type.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index d82c191f57..4db22b5f6b 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -18,6 +18,7 @@ class Module autoload :ModuleInfo, 'msf/core/module/module_info' autoload :ModuleStore, 'msf/core/module/module_store' autoload :Options, 'msf/core/module/options' + autoload :Type, 'msf/core/module/type' autoload :UI, 'msf/core/module/ui' include Msf::Module::Arch @@ -26,6 +27,7 @@ class Module include Msf::Module::ModuleInfo include Msf::Module::ModuleStore include Msf::Module::Options + include Msf::Module::Type include Msf::Module::UI # Make include public so we can runtime extend @@ -34,13 +36,6 @@ class Module class << self include Framework::Offspring - # - # Class method to figure out what type of module this is - # - def type - raise NotImplementedError - end - def fullname type + '/' + refname end @@ -312,13 +307,6 @@ class Module self.datastore['ParentUUID'] = ref.uuid.dup end - # - # Return the module's abstract type. - # - def type - raise NotImplementedError - end - # # Return a comma separated list of author for this module. # @@ -500,48 +488,6 @@ class Module # ## - # - # Returns true if this module is an exploit module. - # - def exploit? - (type == MODULE_EXPLOIT) - end - - # - # Returns true if this module is a payload module. - # - def payload? - (type == MODULE_PAYLOAD) - end - - # - # Returns true if this module is an encoder module. - # - def encoder? - (type == MODULE_ENCODER) - end - - # - # Returns true if this module is a nop module. - # - def nop? - (type == MODULE_NOP) - end - - # - # Returns true if this module is an auxiliary module. - # - def auxiliary? - (type == MODULE_AUX) - end - - # - # Returns true if this module is an post-exploitation module. - # - def post? - (type == MODULE_POST) - end - # # Returns false since this is the real module # diff --git a/lib/msf/core/module/type.rb b/lib/msf/core/module/type.rb new file mode 100644 index 0000000000..14b4c6be77 --- /dev/null +++ b/lib/msf/core/module/type.rb @@ -0,0 +1,65 @@ +module Msf::Module::Type + extend ActiveSupport::Concern + + module ClassMethods + # + # Class method to figure out what type of module this is + # + def type + raise NotImplementedError + end + end + + # + # Instance Methods + # + + # + # Returns true if this module is an auxiliary module. + # + def auxiliary? + (type == MODULE_AUX) + end + + # + # Returns true if this module is an encoder module. + # + def encoder? + (type == MODULE_ENCODER) + end + + # + # Returns true if this module is an exploit module. + # + def exploit? + (type == MODULE_EXPLOIT) + end + + # + # Returns true if this module is a nop module. + # + def nop? + (type == MODULE_NOP) + end + + # + # Returns true if this module is a payload module. + # + def payload? + (type == MODULE_PAYLOAD) + end + + # + # Returns true if this module is an post-exploitation module. + # + def post? + (type == MODULE_POST) + end + + # + # Return the module's abstract type. + # + def type + raise NotImplementedError + end +end \ No newline at end of file From 925cd63171be5b9cf0afd00f81d34833b37e75a7 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 14:28:43 -0500 Subject: [PATCH 21/51] Extrat Msf::Module::Type shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 8 +------- spec/support/shared/examples/msf/module/type.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/type.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index ac98fd7ef0..7100aa90d0 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -39,26 +39,20 @@ REF_TYPES = %w(CVE BID OSVDB EDB) describe Msf::Module do it { is_expected.to respond_to :author_to_s } - it { is_expected.to respond_to :auxiliary? } it { is_expected.to respond_to :check } it { is_expected.to respond_to :comm } it { is_expected.to respond_to :debugging? } it { is_expected.to respond_to :derived_implementor? } it { is_expected.to respond_to :each_author } - it { is_expected.to respond_to :encoder? } - it { is_expected.to respond_to :exploit? } it { is_expected.to respond_to :fail_with } it { is_expected.to respond_to :file_path } it { is_expected.to respond_to :framework } it { is_expected.to respond_to :fullname } it { is_expected.to respond_to :generate_uuid } - it { is_expected.to respond_to :nop? } it { is_expected.to respond_to :orig_cls } it { is_expected.to respond_to :owner } - it { is_expected.to respond_to :payload? } it { is_expected.to respond_to :platform? } it { is_expected.to respond_to :platform_to_s } - it { is_expected.to respond_to :post? } it { is_expected.to respond_to :privileged? } it { is_expected.to respond_to :rank } it { is_expected.to respond_to :rank_to_h } @@ -71,7 +65,6 @@ describe Msf::Module do it { is_expected.to respond_to :support_ipv6? } it { is_expected.to respond_to :target_host } it { is_expected.to respond_to :target_port } - it { is_expected.to respond_to :type } it { is_expected.to respond_to :workspace } it_should_behave_like 'Msf::Module::Arch' @@ -80,6 +73,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::ModuleInfo' it_should_behave_like 'Msf::Module::ModuleStore' it_should_behave_like 'Msf::Module::Options' + it_should_behave_like 'Msf::Module::Type' it_should_behave_like 'Msf::Module::UI' context 'class' do diff --git a/spec/support/shared/examples/msf/module/type.rb b/spec/support/shared/examples/msf/module/type.rb new file mode 100644 index 0000000000..1f8d13f02a --- /dev/null +++ b/spec/support/shared/examples/msf/module/type.rb @@ -0,0 +1,17 @@ +shared_examples_for 'Msf::Module::Type' do + it { is_expected.to respond_to :auxiliary? } + it { is_expected.to respond_to :encoder? } + it { is_expected.to respond_to :exploit? } + it { is_expected.to respond_to :nop? } + it { is_expected.to respond_to :payload? } + it { is_expected.to respond_to :post? } + it { is_expected.to respond_to :type } + + context 'class' do + subject { + described_class + } + + it { is_expected.to respond_to :type } + end +end \ No newline at end of file From d5c7a50e86e841d97a26c11b55ade710f92d8b23 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 14:39:33 -0500 Subject: [PATCH 22/51] Extract Msf::Module::Rank MSP-11126 --- lib/msf/core/module.rb | 43 ++----------------------------- lib/msf/core/module/rank.rb | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 lib/msf/core/module/rank.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 4db22b5f6b..3787584430 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -18,6 +18,7 @@ class Module autoload :ModuleInfo, 'msf/core/module/module_info' autoload :ModuleStore, 'msf/core/module/module_store' autoload :Options, 'msf/core/module/options' + autoload :Rank, 'msf/core/module/rank' autoload :Type, 'msf/core/module/type' autoload :UI, 'msf/core/module/ui' @@ -27,6 +28,7 @@ class Module include Msf::Module::ModuleInfo include Msf::Module::ModuleStore include Msf::Module::Options + include Msf::Module::Rank include Msf::Module::Type include Msf::Module::UI @@ -44,26 +46,6 @@ class Module refname.split('/').last end - # - # Returns this module's ranking. - # - def rank - (const_defined?('Rank')) ? const_get('Rank') : NormalRanking - end - - # - # Returns this module's ranking as a string representation. - # - def rank_to_s - RankingName[rank] - end - - # - # Returns this module's ranking as a string for display. - # - def rank_to_h - rank_to_s.gsub('Rank', '').downcase - end # # The module's name that is assigned it it by the framework # or derived from the path that the module is loaded from. @@ -197,27 +179,6 @@ class Module self.class.refname end - # - # Returns the module's rank. - # - def rank - self.class.rank - end - - # - # Returns the module's rank in string format. - # - def rank_to_s - self.class.rank_to_s - end - - # - # Returns the module's rank in display format. - # - def rank_to_h - self.class.rank_to_h - end - # # Returns the module's framework short name. This is a # possibly conflicting name used for things like console diff --git a/lib/msf/core/module/rank.rb b/lib/msf/core/module/rank.rb new file mode 100644 index 0000000000..c671764c96 --- /dev/null +++ b/lib/msf/core/module/rank.rb @@ -0,0 +1,51 @@ +module Msf::Module::Rank + extend ActiveSupport::Concern + + module ClassMethods + # + # Returns this module's ranking. + # + def rank + (const_defined?('Rank')) ? const_get('Rank') : NormalRanking + end + + # + # Returns this module's ranking as a string for display. + # + def rank_to_h + rank_to_s.gsub('Rank', '').downcase + end + + # + # Returns this module's ranking as a string representation. + # + def rank_to_s + RankingName[rank] + end + end + + # + # Instance Methods + # + + # + # Returns the module's rank. + # + def rank + self.class.rank + end + + # + # Returns the module's rank in display format. + # + def rank_to_h + self.class.rank_to_h + end + + # + # Returns the module's rank in string format. + # + def rank_to_s + self.class.rank_to_s + end +end From c501e1e58a10061cc7832dd31a04ecc322d1a483 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 14:41:59 -0500 Subject: [PATCH 23/51] Extract Msf::Module::Rank shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 4 +--- spec/support/shared/examples/msf/module/rank.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/rank.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 7100aa90d0..5edfe7ecd6 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -54,9 +54,6 @@ describe Msf::Module do it { is_expected.to respond_to :platform? } it { is_expected.to respond_to :platform_to_s } it { is_expected.to respond_to :privileged? } - it { is_expected.to respond_to :rank } - it { is_expected.to respond_to :rank_to_h } - it { is_expected.to respond_to :rank_to_s } it { is_expected.to respond_to :refname } it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } @@ -73,6 +70,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::ModuleInfo' it_should_behave_like 'Msf::Module::ModuleStore' it_should_behave_like 'Msf::Module::Options' + it_should_behave_like 'Msf::Module::Rank' it_should_behave_like 'Msf::Module::Type' it_should_behave_like 'Msf::Module::UI' diff --git a/spec/support/shared/examples/msf/module/rank.rb b/spec/support/shared/examples/msf/module/rank.rb new file mode 100644 index 0000000000..823aa2a81a --- /dev/null +++ b/spec/support/shared/examples/msf/module/rank.rb @@ -0,0 +1,15 @@ +shared_examples_for 'Msf::Module::Rank' do + it { is_expected.to respond_to :rank } + it { is_expected.to respond_to :rank_to_h } + it { is_expected.to respond_to :rank_to_s } + + context 'class' do + subject { + described_class + } + + it { is_expected.to respond_to :rank } + it { is_expected.to respond_to :rank_to_h } + it { is_expected.to respond_to :rank_to_s } + end +end \ No newline at end of file From fe5ffa9cec011e86674945d8d395608619f2d0c7 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 14:51:32 -0500 Subject: [PATCH 24/51] Standardize on autoload over require MSP-11126 Standardize on autoload to prevent trying to use colliding names for included Module with Modules/Classes just under the namespace. --- lib/msf/core/module.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 3787584430..8b35a229b9 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -13,12 +13,20 @@ module Msf ### class Module autoload :Arch, 'msf/core/module/arch' + autoload :Author, 'msf/core/module/author' + autoload :AuxiliaryAction, 'msf/core/module/auxiliary_action' autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' + autoload :Deprecated, 'msf/core/module/deprecated' + autoload :HasActions, 'msf/core/module/has_actions' autoload :ModuleInfo, 'msf/core/module/module_info' autoload :ModuleStore, 'msf/core/module/module_store' autoload :Options, 'msf/core/module/options' + autoload :Platform, 'msf/core/module/platform' + autoload :PlatformList, 'msf/core/module/platform_list' autoload :Rank, 'msf/core/module/rank' + autoload :Reference, 'msf/core/module/reference' + autoload :Target, 'msf/core/module/target' autoload :Type, 'msf/core/module/type' autoload :UI, 'msf/core/module/ui' @@ -83,14 +91,6 @@ class Module true end - 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' - require 'msf/core/module/deprecated' - # # Creates an instance of an abstract module using the supplied information # hash. From c8730ca55b88e185a08159d4ce2becd67937fad5 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 14:59:15 -0500 Subject: [PATCH 25/51] Extract Msf::Author MSP-11126 --- lib/msf/core.rb | 6 ++++++ lib/msf/core/author.rb | 1 + lib/msf/core/module.rb | 1 - 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 lib/msf/core/author.rb diff --git a/lib/msf/core.rb b/lib/msf/core.rb index cde0260688..aa3b7c2b4f 100644 --- a/lib/msf/core.rb +++ b/lib/msf/core.rb @@ -18,6 +18,12 @@ require 'rex' require 'rex/ui' module Msf + autoload :Author, 'msf/core/author' + + # + # Constants + # + LogSource = "core" end diff --git a/lib/msf/core/author.rb b/lib/msf/core/author.rb new file mode 100644 index 0000000000..c55c366640 --- /dev/null +++ b/lib/msf/core/author.rb @@ -0,0 +1 @@ +Msf::Author = Msf::Module::Author diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 8b35a229b9..911483dc9d 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -537,7 +537,6 @@ end # 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 From 9981271e2aec153617ab4f89b5eed756fa50a3c0 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:03:21 -0500 Subject: [PATCH 26/51] extract Msf::Reference MSP-11126 --- lib/msf/core.rb | 1 + lib/msf/core/module.rb | 2 +- lib/msf/core/reference.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 lib/msf/core/reference.rb diff --git a/lib/msf/core.rb b/lib/msf/core.rb index aa3b7c2b4f..69c9c92a57 100644 --- a/lib/msf/core.rb +++ b/lib/msf/core.rb @@ -19,6 +19,7 @@ require 'rex/ui' module Msf autoload :Author, 'msf/core/author' + autoload :Reference, 'msf/core/reference' # # Constants diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 911483dc9d..1e81a5c218 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -26,6 +26,7 @@ class Module autoload :PlatformList, 'msf/core/module/platform_list' autoload :Rank, 'msf/core/module/rank' autoload :Reference, 'msf/core/module/reference' + autoload :SiteReference, 'msf/core/module/reference' autoload :Target, 'msf/core/module/target' autoload :Type, 'msf/core/module/type' autoload :UI, 'msf/core/module/ui' @@ -537,7 +538,6 @@ end # Alias the data types so people can reference them just by Msf:: and not # Msf::Module:: # -Reference = Msf::Module::Reference SiteReference = Msf::Module::SiteReference Platform = Msf::Module::Platform Target = Msf::Module::Target diff --git a/lib/msf/core/reference.rb b/lib/msf/core/reference.rb new file mode 100644 index 0000000000..53e426f35c --- /dev/null +++ b/lib/msf/core/reference.rb @@ -0,0 +1 @@ +Msf::Reference = Msf::Module::Reference From 27c006a8f9e0cca8cf0bb005fe28378c4e2c0c6b Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:09:55 -0500 Subject: [PATCH 27/51] Extract Msf::SiteReference MSP-11126 --- lib/msf/core.rb | 1 + lib/msf/core/module.rb | 1 - lib/msf/core/site_reference.rb | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 lib/msf/core/site_reference.rb diff --git a/lib/msf/core.rb b/lib/msf/core.rb index 69c9c92a57..157533bec9 100644 --- a/lib/msf/core.rb +++ b/lib/msf/core.rb @@ -20,6 +20,7 @@ require 'rex/ui' module Msf autoload :Author, 'msf/core/author' autoload :Reference, 'msf/core/reference' + autoload :SiteReference, 'msf/core/site_reference' # # Constants diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 1e81a5c218..f771641e8c 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -538,7 +538,6 @@ end # Alias the data types so people can reference them just by Msf:: and not # Msf::Module:: # -SiteReference = Msf::Module::SiteReference Platform = Msf::Module::Platform Target = Msf::Module::Target diff --git a/lib/msf/core/site_reference.rb b/lib/msf/core/site_reference.rb new file mode 100644 index 0000000000..b215391028 --- /dev/null +++ b/lib/msf/core/site_reference.rb @@ -0,0 +1 @@ +Msf::SiteReference = Msf::Module::SiteReference From e5cc456be7b5cb1893ce5c4178e95b3fc4e2a2ec Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:11:59 -0500 Subject: [PATCH 28/51] Extract Msf::Platform MSP-11126 --- lib/msf/core.rb | 1 + lib/msf/core/module.rb | 1 - lib/msf/core/platform.rb | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 lib/msf/core/platform.rb diff --git a/lib/msf/core.rb b/lib/msf/core.rb index 157533bec9..ba9b21ac40 100644 --- a/lib/msf/core.rb +++ b/lib/msf/core.rb @@ -19,6 +19,7 @@ require 'rex/ui' module Msf autoload :Author, 'msf/core/author' + autoload :Platform, 'msf/core/platform' autoload :Reference, 'msf/core/reference' autoload :SiteReference, 'msf/core/site_reference' diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index f771641e8c..a5b0314f28 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -538,7 +538,6 @@ end # Alias the data types so people can reference them just by Msf:: and not # Msf::Module:: # -Platform = Msf::Module::Platform Target = Msf::Module::Target end diff --git a/lib/msf/core/platform.rb b/lib/msf/core/platform.rb new file mode 100644 index 0000000000..15bc889b29 --- /dev/null +++ b/lib/msf/core/platform.rb @@ -0,0 +1 @@ +Msf::Platform = Msf::Module::Platform From 0e53548c82cba6e2bd189b443424df3f62dc8a49 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:13:18 -0500 Subject: [PATCH 29/51] Extract Msf::Target MSP-11126 --- lib/msf/core.rb | 1 + lib/msf/core/module.rb | 8 -------- lib/msf/core/target.rb | 1 + 3 files changed, 2 insertions(+), 8 deletions(-) create mode 100644 lib/msf/core/target.rb diff --git a/lib/msf/core.rb b/lib/msf/core.rb index ba9b21ac40..d39635482c 100644 --- a/lib/msf/core.rb +++ b/lib/msf/core.rb @@ -22,6 +22,7 @@ module Msf autoload :Platform, 'msf/core/platform' autoload :Reference, 'msf/core/reference' autoload :SiteReference, 'msf/core/site_reference' + autoload :Target, 'msf/core/target' # # Constants diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index a5b0314f28..9b5f4b1ab3 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -533,12 +533,4 @@ protected attr_writer :license # :nodoc: end - -# -# Alias the data types so people can reference them just by Msf:: and not -# Msf::Module:: -# -Target = Msf::Module::Target - end - diff --git a/lib/msf/core/target.rb b/lib/msf/core/target.rb new file mode 100644 index 0000000000..a515dda6fc --- /dev/null +++ b/lib/msf/core/target.rb @@ -0,0 +1 @@ +Msf::Target = Msf::Module::Target From 7743fdb2f93e2b83597cd766451d19a2844277f6 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:24:59 -0500 Subject: [PATCH 30/51] Extract Msf::Module::FullName MSP-11126 --- lib/msf/core/module.rb | 48 +---------------------- lib/msf/core/module/full_name.rb | 67 ++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 46 deletions(-) create mode 100644 lib/msf/core/module/full_name.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 9b5f4b1ab3..64188714f7 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -18,6 +18,7 @@ class Module autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' autoload :Deprecated, 'msf/core/module/deprecated' + autoload :FullName, 'msf/core/module/full_name' autoload :HasActions, 'msf/core/module/has_actions' autoload :ModuleInfo, 'msf/core/module/module_info' autoload :ModuleStore, 'msf/core/module/module_store' @@ -34,6 +35,7 @@ class Module include Msf::Module::Arch include Msf::Module::Compatibility include Msf::Module::DataStore + include Msf::Module::FullName include Msf::Module::ModuleInfo include Msf::Module::ModuleStore include Msf::Module::Options @@ -47,20 +49,6 @@ class Module class << self include Framework::Offspring - def fullname - type + '/' + refname - end - - def shortname - refname.split('/').last - end - - # - # 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 - # # This attribute holds the non-duplicated copy of the module # implementation. This attribute is used for reloading purposes so that @@ -159,38 +147,6 @@ class Module obj end - # - # 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 - self.class.fullname - end - - # - # Returns the module's framework reference name. This is the - # short name that end-users work with. Ex: - # - # windows/shell/reverse_tcp - # - def refname - self.class.refname - end - - # - # Returns the module's framework short name. This is a - # possibly conflicting name used for things like console - # prompts. - # - # reverse_tcp - # - def shortname - self.class.shortname - end - # # Returns the unduplicated class associated with this module. # diff --git a/lib/msf/core/module/full_name.rb b/lib/msf/core/module/full_name.rb new file mode 100644 index 0000000000..1bcfc5ecd5 --- /dev/null +++ b/lib/msf/core/module/full_name.rb @@ -0,0 +1,67 @@ +# @note {Msf::Module::ModuleInfo#name} is unrelated to {#fullname} and should instead be thought of as the title or +# summary of the module. +# +# Names related to {#fullname}, such as {#fullname}, {#refname}, and {#shortname}. +module Msf::Module::FullName + extend ActiveSupport::Concern + + module ClassMethods + # + # Attributes + # + + + # @attribute refname + # 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 + + # + # Class Methods + # + + def fullname + type + '/' + refname + end + + def shortname + refname.split('/').last + end + end + + # + # Instance Methods + # + + # + # 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 + self.class.fullname + end + + # + # Returns the module's framework reference name. This is the + # short name that end-users work with. Ex: + # + # windows/shell/reverse_tcp + # + def refname + self.class.refname + end + + # + # Returns the module's framework short name. This is a + # possibly conflicting name used for things like console + # prompts. + # + # reverse_tcp + # + def shortname + self.class.shortname + end +end \ No newline at end of file From 2e538bd72deac918e8310ab13d341eedaaf6369a Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:27:54 -0500 Subject: [PATCH 31/51] Extract Msf::Module::Search MSP-11126 --- lib/msf/core/module.rb | 110 +--------------------------------- lib/msf/core/module/search.rb | 109 +++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 108 deletions(-) create mode 100644 lib/msf/core/module/search.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 64188714f7..aacf013813 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -27,6 +27,7 @@ class Module autoload :PlatformList, 'msf/core/module/platform_list' autoload :Rank, 'msf/core/module/rank' autoload :Reference, 'msf/core/module/reference' + autoload :Search, 'msf/core/module/search' autoload :SiteReference, 'msf/core/module/reference' autoload :Target, 'msf/core/module/target' autoload :Type, 'msf/core/module/type' @@ -40,6 +41,7 @@ class Module include Msf::Module::ModuleStore include Msf::Module::Options include Msf::Module::Rank + include Msf::Module::Search include Msf::Module::Type include Msf::Module::UI @@ -285,114 +287,6 @@ class Module true end - # - # This provides a standard set of search filters for every module. - # The search terms are in the form of: - # { - # "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 - # - def search_filter(search_string) - return false if not search_string - - search_string += " " - - # 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 - end - - k = res - - refs = self.references.map{|x| [x.ctx_id, x.ctx_val].join("-") } - is_server = (self.respond_to?(:stance) and self.stance == "aggressive") - is_client = (self.respond_to?(:stance) and self.stance == "passive") - - [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 - when 'port' - match = [t,w] if self.datastore['RPORT'].to_s =~ r - when 'type' - match = [t,w] if Msf::MODULE_TYPES.any? { |modt| w == modt and self.type == modt } - when 'app' - match = [t,w] if (w == "server" and is_server) - match = [t,w] if (w == "client" and is_client) - 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 } - when 'edb' - match = [t,w] if refs.any? { |ref| ref =~ /^edb\-/i and ref =~ r } - 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 - # Filter this module if we matched an exclusion keyword (-value) - if mode == 1 and match - return true - end - end - - false - end - # # Support fail_with for all module types, allow specific classes to override # diff --git a/lib/msf/core/module/search.rb b/lib/msf/core/module/search.rb new file mode 100644 index 0000000000..7c2e965b3d --- /dev/null +++ b/lib/msf/core/module/search.rb @@ -0,0 +1,109 @@ +module Msf::Module::Search + # + # This provides a standard set of search filters for every module. + # The search terms are in the form of: + # { + # "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 + # + def search_filter(search_string) + return false if not search_string + + search_string += " " + + # 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 + end + + k = res + + refs = self.references.map{|x| [x.ctx_id, x.ctx_val].join("-") } + is_server = (self.respond_to?(:stance) and self.stance == "aggressive") + is_client = (self.respond_to?(:stance) and self.stance == "passive") + + [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 + when 'port' + match = [t,w] if self.datastore['RPORT'].to_s =~ r + when 'type' + match = [t,w] if Msf::MODULE_TYPES.any? { |modt| w == modt and self.type == modt } + when 'app' + match = [t,w] if (w == "server" and is_server) + match = [t,w] if (w == "client" and is_client) + 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 } + when 'edb' + match = [t,w] if refs.any? { |ref| ref =~ /^edb\-/i and ref =~ r } + 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 + # Filter this module if we matched an exclusion keyword (-value) + if mode == 1 and match + return true + end + end + + false + end +end \ No newline at end of file From be945d26fc09e7fb154348b0ea7d6511a089a63b Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:33:13 -0500 Subject: [PATCH 32/51] Extract Msf::Module::FullName shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 4 +--- .../shared/examples/msf/module/full_name.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/full_name.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 5edfe7ecd6..bc4b05fae5 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -47,18 +47,15 @@ describe Msf::Module do it { is_expected.to respond_to :fail_with } it { is_expected.to respond_to :file_path } it { is_expected.to respond_to :framework } - it { is_expected.to respond_to :fullname } it { is_expected.to respond_to :generate_uuid } it { is_expected.to respond_to :orig_cls } it { is_expected.to respond_to :owner } it { is_expected.to respond_to :platform? } it { is_expected.to respond_to :platform_to_s } it { is_expected.to respond_to :privileged? } - it { is_expected.to respond_to :refname } it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } it { is_expected.to respond_to :set_defaults } - it { is_expected.to respond_to :shortname } it { is_expected.to respond_to :support_ipv6? } it { is_expected.to respond_to :target_host } it { is_expected.to respond_to :target_port } @@ -67,6 +64,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::Arch' it_should_behave_like 'Msf::Module::Compatibility' it_should_behave_like 'Msf::Module::DataStore' + it_should_behave_like 'Msf::Module::FullName' it_should_behave_like 'Msf::Module::ModuleInfo' it_should_behave_like 'Msf::Module::ModuleStore' it_should_behave_like 'Msf::Module::Options' diff --git a/spec/support/shared/examples/msf/module/full_name.rb b/spec/support/shared/examples/msf/module/full_name.rb new file mode 100644 index 0000000000..918b7e3b4b --- /dev/null +++ b/spec/support/shared/examples/msf/module/full_name.rb @@ -0,0 +1,16 @@ +shared_examples_for 'Msf::Module::FullName' do + it { is_expected.to respond_to :fullname } + it { is_expected.to respond_to :refname } + it { is_expected.to respond_to :shortname } + + context 'class' do + subject { + described_class + } + + it { is_expected.to respond_to :fullname } + it { is_expected.to respond_to :refname } + it { is_expected.to respond_to :refname= } + it { is_expected.to respond_to :shortname } + end +end \ No newline at end of file From 244e4a995406f0c9d6d8090659bcb8854edffc3b Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:40:19 -0500 Subject: [PATCH 33/51] Extract Msf::Module::Search shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 170 +----------------- .../shared/examples/msf/module/search.rb | 168 +++++++++++++++++ 2 files changed, 169 insertions(+), 169 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/search.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index bc4b05fae5..145a61e12a 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -1,41 +1,6 @@ # -*- coding:binary -*- require 'spec_helper' require 'msf/core/module' -require 'msf/core/module/platform_list' - -shared_examples "search_filter" do |opts| - accept = opts[:accept] || [] - reject = opts[:reject] || [] - - accept.each do |query| - it "should accept a query containing '#{query}'" do - # if the subject matches, search_filter returns false ("don't filter me out!") - subject.search_filter(query).should be_falsey - end - - unless opts.has_key?(:test_inverse) and not opts[:test_inverse] - it "should reject a query containing '-#{query}'" do - subject.search_filter("-#{query}").should be_truthy - end - end - end - - reject.each do |query| - it "should reject a query containing '#{query}'" do - # if the subject doesn't matches, search_filter returns true ("filter me out!") - subject.search_filter(query).should be_truthy - end - - unless opts.has_key?(:test_inverse) and not opts[:test_inverse] - it "should accept a query containing '-#{query}'" do - subject.search_filter("-#{query}").should be_truthy # what? why? - end - end - end -end - - -REF_TYPES = %w(CVE BID OSVDB EDB) describe Msf::Module do it { is_expected.to respond_to :author_to_s } @@ -69,6 +34,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::ModuleStore' it_should_behave_like 'Msf::Module::Options' it_should_behave_like 'Msf::Module::Rank' + it_should_behave_like 'Msf::Module::Search' it_should_behave_like 'Msf::Module::Type' it_should_behave_like 'Msf::Module::UI' @@ -86,138 +52,4 @@ describe Msf::Module do it { is_expected.to respond_to :shortname } it { is_expected.to respond_to :type } end - - describe '#search_filter' do - let(:opts) { Hash.new } - before { subject.stub(:fullname => '/module') } - subject { Msf::Module.new(opts) } - accept = [] - reject = [] - - context 'on a blank query' do - it_should_behave_like 'search_filter', :accept => [''], :test_inverse => false - end - - context 'on a client module' do - before { subject.stub(:stance => 'passive') } - accept = %w(app:client) - reject = %w(app:server) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a server module' do - before { subject.stub(:stance => 'aggressive') } - accept = %w(app:server) - reject = %w(app:client) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module with the author "joev"' do - let(:opts) { ({ 'Author' => ['joev'] }) } - accept = %w(author:joev author:joe) - reject = %w(author:unrelated) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module with the authors "joev" and "blarg"' do - let(:opts) { ({ 'Author' => ['joev', 'blarg'] }) } - accept = %w(author:joev author:joe) - reject = %w(author:sinn3r) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module that supports the osx platform' do - let(:opts) { ({ 'Platform' => %w(osx) }) } - accept = %w(platform:osx os:osx) - reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module that supports the linux platform' do - let(:opts) { ({ 'Platform' => %w(linux) }) } - accept = %w(platform:linux os:linux) - reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module that supports the windows platform' do - let(:opts) { ({ 'Platform' => %w(windows) }) } - accept = %w(platform:windows os:windows) - reject = %w(platform:bsd platform:osx platform:unix os:bsd os:osx os:unix) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module that supports the osx and linux platforms' do - let(:opts) { ({ 'Platform' => %w(osx linux) }) } - accept = %w(platform:osx platform:linux os:osx os:linux) - reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module that supports the windows and irix platforms' do - let(:opts) { ({ 'Platform' => %w(windows irix) }) } - accept = %w(platform:windows platform:irix os:windows os:irix) - reject = %w(platform:bsd platform:osx platform:linux os:bsd os:osx os:linux) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module with a default RPORT of 5555' do - before { subject.stub(:datastore => { 'RPORT' => 5555 }) } - accept = %w(port:5555) - reject = %w(port:5556) - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - - context 'on a module with a #name of "blah"' do - let(:opts) { ({ 'Name' => 'blah' }) } - it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo) - it_should_behave_like 'search_filter', :accept => %w(name:blah), :reject => %w(name:foo) - end - - context 'on a module with a #fullname of "blah"' do - before { subject.stub(:fullname => '/c/d/e/blah') } - it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo) - it_should_behave_like 'search_filter', :accept => %w(path:blah), :reject => %w(path:foo) - end - - context 'on a module with a #description of "blah"' do - let(:opts) { ({ 'Description' => 'blah' }) } - it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo) - end - - context 'when filtering by module #type' do - all_module_types = Msf::MODULE_TYPES - all_module_types.each do |mtype| - context "on a #{mtype} module" do - before(:each) { subject.stub(:type => mtype) } - - accept = ["type:#{mtype}"] - reject = all_module_types.reject { |t| t == mtype }.map { |t| "type:#{t}" } - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - end - end - - REF_TYPES.each do |ref_type| - ref_num = '1234-1111' - context 'on a module with reference #{ref_type}-#{ref_num}' do - let(:opts) { ({ 'References' => [[ref_type, ref_num]] }) } - accept = ["#{ref_type.downcase}:#{ref_num}"] - reject = %w(1235-1111 1234-1112 bad).map { |n| "#{ref_type.downcase}:#{n}" } - - it_should_behave_like 'search_filter', :accept => accept, :reject => reject - end - end - end end diff --git a/spec/support/shared/examples/msf/module/search.rb b/spec/support/shared/examples/msf/module/search.rb new file mode 100644 index 0000000000..53996575d8 --- /dev/null +++ b/spec/support/shared/examples/msf/module/search.rb @@ -0,0 +1,168 @@ +shared_examples_for 'Msf::Module::Search' do + describe '#search_filter' do + REF_TYPES = %w(CVE BID OSVDB EDB) + + shared_examples "search_filter" do |opts| + accept = opts[:accept] || [] + reject = opts[:reject] || [] + + accept.each do |query| + it "should accept a query containing '#{query}'" do + # if the subject matches, search_filter returns false ("don't filter me out!") + subject.search_filter(query).should be_falsey + end + + unless opts.has_key?(:test_inverse) and not opts[:test_inverse] + it "should reject a query containing '-#{query}'" do + subject.search_filter("-#{query}").should be_truthy + end + end + end + + reject.each do |query| + it "should reject a query containing '#{query}'" do + # if the subject doesn't matches, search_filter returns true ("filter me out!") + subject.search_filter(query).should be_truthy + end + + unless opts.has_key?(:test_inverse) and not opts[:test_inverse] + it "should accept a query containing '-#{query}'" do + subject.search_filter("-#{query}").should be_truthy # what? why? + end + end + end + end + + let(:opts) { Hash.new } + before { subject.stub(:fullname => '/module') } + subject { Msf::Module.new(opts) } + accept = [] + reject = [] + + context 'on a blank query' do + it_should_behave_like 'search_filter', :accept => [''], :test_inverse => false + end + + context 'on a client module' do + before { subject.stub(:stance => 'passive') } + accept = %w(app:client) + reject = %w(app:server) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a server module' do + before { subject.stub(:stance => 'aggressive') } + accept = %w(app:server) + reject = %w(app:client) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module with the author "joev"' do + let(:opts) { ({ 'Author' => ['joev'] }) } + accept = %w(author:joev author:joe) + reject = %w(author:unrelated) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module with the authors "joev" and "blarg"' do + let(:opts) { ({ 'Author' => ['joev', 'blarg'] }) } + accept = %w(author:joev author:joe) + reject = %w(author:sinn3r) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module that supports the osx platform' do + let(:opts) { ({ 'Platform' => %w(osx) }) } + accept = %w(platform:osx os:osx) + reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module that supports the linux platform' do + let(:opts) { ({ 'Platform' => %w(linux) }) } + accept = %w(platform:linux os:linux) + reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module that supports the windows platform' do + let(:opts) { ({ 'Platform' => %w(windows) }) } + accept = %w(platform:windows os:windows) + reject = %w(platform:bsd platform:osx platform:unix os:bsd os:osx os:unix) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module that supports the osx and linux platforms' do + let(:opts) { ({ 'Platform' => %w(osx linux) }) } + accept = %w(platform:osx platform:linux os:osx os:linux) + reject = %w(platform:bsd platform:windows platform:unix os:bsd os:windows os:unix) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module that supports the windows and irix platforms' do + let(:opts) { ({ 'Platform' => %w(windows irix) }) } + accept = %w(platform:windows platform:irix os:windows os:irix) + reject = %w(platform:bsd platform:osx platform:linux os:bsd os:osx os:linux) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module with a default RPORT of 5555' do + before { subject.stub(:datastore => { 'RPORT' => 5555 }) } + accept = %w(port:5555) + reject = %w(port:5556) + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + + context 'on a module with a #name of "blah"' do + let(:opts) { ({ 'Name' => 'blah' }) } + it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo) + it_should_behave_like 'search_filter', :accept => %w(name:blah), :reject => %w(name:foo) + end + + context 'on a module with a #fullname of "blah"' do + before { subject.stub(:fullname => '/c/d/e/blah') } + it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo) + it_should_behave_like 'search_filter', :accept => %w(path:blah), :reject => %w(path:foo) + end + + context 'on a module with a #description of "blah"' do + let(:opts) { ({ 'Description' => 'blah' }) } + it_should_behave_like 'search_filter', :accept => %w(text:blah), :reject => %w(text:foo) + end + + context 'when filtering by module #type' do + all_module_types = Msf::MODULE_TYPES + all_module_types.each do |mtype| + context "on a #{mtype} module" do + before(:each) { subject.stub(:type => mtype) } + + accept = ["type:#{mtype}"] + reject = all_module_types.reject { |t| t == mtype }.map { |t| "type:#{t}" } + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + end + end + + REF_TYPES.each do |ref_type| + ref_num = '1234-1111' + context 'on a module with reference #{ref_type}-#{ref_num}' do + let(:opts) { ({ 'References' => [[ref_type, ref_num]] }) } + accept = ["#{ref_type.downcase}:#{ref_num}"] + reject = %w(1235-1111 1234-1112 bad).map { |n| "#{ref_type.downcase}:#{n}" } + + it_should_behave_like 'search_filter', :accept => accept, :reject => reject + end + end + end +end \ No newline at end of file From ee9623c11e1d210f6c6ab285d46fa3a45d96080c Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:41:28 -0500 Subject: [PATCH 34/51] Remove class method examples moved to shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 145a61e12a..4804d9ee0d 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -44,12 +44,6 @@ describe Msf::Module do } it { is_expected.to respond_to :cached? } - it { is_expected.to respond_to :fullname } it { is_expected.to respond_to :is_usable } - it { is_expected.to respond_to :rank } - it { is_expected.to respond_to :rank_to_h } - it { is_expected.to respond_to :rank_to_s } - it { is_expected.to respond_to :shortname } - it { is_expected.to respond_to :type } end end From b5039c3817fd19133f729e3137ca922cf6797dde Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:51:59 -0500 Subject: [PATCH 35/51] Extract Msf::Module::Network MSP-11126 --- lib/msf/core/module.rb | 33 ++------------------------------- lib/msf/core/module/network.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 31 deletions(-) create mode 100644 lib/msf/core/module/network.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index aacf013813..1185c05da1 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -22,6 +22,7 @@ class Module autoload :HasActions, 'msf/core/module/has_actions' autoload :ModuleInfo, 'msf/core/module/module_info' autoload :ModuleStore, 'msf/core/module/module_store' + autoload :Network, 'msf/core/module/network' autoload :Options, 'msf/core/module/options' autoload :Platform, 'msf/core/module/platform' autoload :PlatformList, 'msf/core/module/platform_list' @@ -39,6 +40,7 @@ class Module include Msf::Module::FullName include Msf::Module::ModuleInfo include Msf::Module::ModuleStore + include Msf::Module::Network include Msf::Module::Options include Msf::Module::Rank include Msf::Module::Search @@ -173,20 +175,6 @@ class Module Msf::Exploit::CheckCode::Unsupported end - # - # Returns the address of the last target host (rough estimate) - # - def target_host - self.respond_to?('rhost') ? rhost : self.datastore['RHOST'] - end - - # - # Returns the address of the last target port (rough estimate) - # - def target_port - self.respond_to?('rport') ? rport : self.datastore['RPORT'] - end - # # Returns the current workspace # @@ -262,14 +250,6 @@ class Module privileged == true end - # - # The default communication subsystem for this module. We may need to move - # this somewhere else. - # - def comm - Rex::Socket::Comm::Local - end - # # Returns true if this module is being debugged. The debug flag is set # by setting datastore['DEBUG'] to 1|true|yes @@ -278,15 +258,6 @@ class Module (datastore['DEBUG'] || '') =~ /^(1|t|y)/i end - # - # 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 - # # Support fail_with for all module types, allow specific classes to override # diff --git a/lib/msf/core/module/network.rb b/lib/msf/core/module/network.rb new file mode 100644 index 0000000000..f68fbb1a0b --- /dev/null +++ b/lib/msf/core/module/network.rb @@ -0,0 +1,32 @@ +module Msf::Module::Network + # + # The default communication subsystem for this module. We may need to move + # this somewhere else. + # + def comm + Rex::Socket::Comm::Local + end + + # + # 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 + + # + # Returns the address of the last target host (rough estimate) + # + def target_host + self.respond_to?('rhost') ? rhost : self.datastore['RHOST'] + end + + # + # Returns the address of the last target port (rough estimate) + # + def target_port + self.respond_to?('rport') ? rport : self.datastore['RPORT'] + end +end \ No newline at end of file From 839657abec6e3c053ec454f134d85f345ec9e7bf Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 15:54:35 -0500 Subject: [PATCH 36/51] Extract Msf::Module::Network shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 5 +---- spec/support/shared/examples/msf/module/network.rb | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/network.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 4804d9ee0d..77df432560 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -5,7 +5,6 @@ require 'msf/core/module' describe Msf::Module do it { is_expected.to respond_to :author_to_s } it { is_expected.to respond_to :check } - it { is_expected.to respond_to :comm } it { is_expected.to respond_to :debugging? } it { is_expected.to respond_to :derived_implementor? } it { is_expected.to respond_to :each_author } @@ -21,9 +20,6 @@ describe Msf::Module do it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } it { is_expected.to respond_to :set_defaults } - it { is_expected.to respond_to :support_ipv6? } - it { is_expected.to respond_to :target_host } - it { is_expected.to respond_to :target_port } it { is_expected.to respond_to :workspace } it_should_behave_like 'Msf::Module::Arch' @@ -32,6 +28,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::FullName' it_should_behave_like 'Msf::Module::ModuleInfo' it_should_behave_like 'Msf::Module::ModuleStore' + it_should_behave_like 'Msf::Module::Network' it_should_behave_like 'Msf::Module::Options' it_should_behave_like 'Msf::Module::Rank' it_should_behave_like 'Msf::Module::Search' diff --git a/spec/support/shared/examples/msf/module/network.rb b/spec/support/shared/examples/msf/module/network.rb new file mode 100644 index 0000000000..5db6122242 --- /dev/null +++ b/spec/support/shared/examples/msf/module/network.rb @@ -0,0 +1,6 @@ +shared_examples_for 'Msf::Module::Network' do + it { is_expected.to respond_to :comm } + it { is_expected.to respond_to :support_ipv6? } + it { is_expected.to respond_to :target_host } + it { is_expected.to respond_to :target_port } +end \ No newline at end of file From ebc62cf9c9fa88126b3ae120e68a3150d9c3fed7 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Thu, 16 Oct 2014 16:03:28 -0500 Subject: [PATCH 37/51] Spec Msf::Module::Author MSP-11126 Bare minimum of methods to assist with moves. --- spec/lib/msf/core/module/author_spec.rb | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 spec/lib/msf/core/module/author_spec.rb diff --git a/spec/lib/msf/core/module/author_spec.rb b/spec/lib/msf/core/module/author_spec.rb new file mode 100644 index 0000000000..07256e06ef --- /dev/null +++ b/spec/lib/msf/core/module/author_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Msf::Module::Author do + context 'Known' do + subject(:known) { + described_class::Known + } + + it { is_expected.to be_a Hash } + end + + it { is_expected.to respond_to :== } + it { is_expected.to respond_to :email } + it { is_expected.to respond_to :email= } + it { is_expected.to respond_to :from_s } + it { is_expected.to respond_to :name } + it { is_expected.to respond_to :name= } + it { is_expected.to respond_to :to_s } + + context 'class' do + subject { + described_class + } + + it { is_expected.to respond_to :from_s } + it { is_expected.to respond_to :transform } + end +end \ No newline at end of file From e8229202986d0147e93451f0e1532af35bf962fc Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 08:46:13 -0500 Subject: [PATCH 38/51] Msf::Module::Author -> Msf::Author MSP-11126 `Msf::Module::Author` was already aliased to `Msf::Author`. This just moved `Msf::Module::Author` to that alias to free up `Msf::Module::Author` so it can be used for a concern for `Msf::Module`'s author methods. --- lib/msf/core/author.rb | 150 +++++++++++++++++++++++- lib/msf/core/module.rb | 3 +- lib/msf/core/module/author.rb | 149 ----------------------- spec/lib/msf/core/author_spec.rb | 25 +++- spec/lib/msf/core/module/author_spec.rb | 28 ----- 5 files changed, 173 insertions(+), 182 deletions(-) delete mode 100644 lib/msf/core/module/author.rb delete mode 100644 spec/lib/msf/core/module/author_spec.rb diff --git a/lib/msf/core/author.rb b/lib/msf/core/author.rb index c55c366640..b56ba29613 100644 --- a/lib/msf/core/author.rb +++ b/lib/msf/core/author.rb @@ -1 +1,149 @@ -Msf::Author = Msf::Module::Author +# -*- coding: binary -*- +require 'msf/core' + +### +# +# This data type represents an author of a piece of code in either +# the framework, a module, a script, or something entirely unrelated. +# +### +class Msf::Author + + # A hash of known author names + Known = + { + 'amaloteaux' => 'alex_maloteaux' + 0x40.chr + 'metasploit.com', + 'anonymous' => 'Unknown', + 'bannedit' => 'bannedit' + 0x40.chr + 'metasploit.com', + 'Carlos Perez' => 'carlos_perez' + 0x40.chr + 'darkoperator.com', + 'cazz' => 'bmc' + 0x40.chr + 'shmoo.com', + 'CG' => 'cg' + 0x40.chr + 'carnal0wnage.com', + 'ddz' => 'ddz' + 0x40.chr + 'theta44.org', + 'egypt' => 'egypt' + 0x40.chr + 'metasploit.com', + 'et' => 'et' + 0x40.chr + 'metasploit.com', + 'Christian Mehlmauer' => 'FireFart' + 0x40.chr + 'gmail.com', + 'hdm' => 'hdm' + 0x40.chr + 'metasploit.com', + 'I)ruid' => 'druid' + 0x40.chr + 'caughq.org', + 'jcran' => 'jcran' + 0x40.chr + 'metasploit.com', + 'jduck' => 'jduck' + 0x40.chr + 'metasploit.com', + 'joev' => 'joev' + 0x40.chr + 'metasploit.com', + 'juan vazquez' => 'juan.vazquez' + 0x40.chr + 'metasploit.com', + 'kf' => 'kf_list' + 0x40.chr + 'digitalmunition.com', + 'kris katterjohn' => 'katterjohn' + 0x40.chr + 'gmail.com', + 'MC' => 'mc' + 0x40.chr + 'metasploit.com', + 'Ben Campbell' => 'eat_meatballs' + 0x40.chr + 'hotmail.co.uk', + 'msmith' => 'msmith' + 0x40.chr + 'metasploit.com', + 'mubix' => 'mubix' + 0x40.chr + 'hak5.org', + 'natron' => 'natron' + 0x40.chr + 'metasploit.com', + 'optyx' => 'optyx' + 0x40.chr + 'no$email.com', + 'patrick' => 'patrick' + 0x40.chr + 'osisecurity.com.au', + 'pusscat' => 'pusscat' + 0x40.chr + 'metasploit.com', + 'Ramon de C Valle' => 'rcvalle' + 0x40.chr + 'metasploit.com', + 'sf' => 'stephen_fewer' + 0x40.chr + 'harmonysecurity.com', + 'sinn3r' => 'sinn3r' + 0x40.chr + 'metasploit.com', + 'skape' => 'mmiller' + 0x40.chr + 'hick.org', + 'skylined' => 'skylined' + 0x40.chr + 'edup.tudelft.nl', + 'spoonm' => 'spoonm' + 0x40.chr + 'no$email.com', + 'stinko' => 'vinnie' + 0x40.chr + 'metasploit.com', + 'theLightCosine' => 'theLightCosine' + 0x40.chr + 'metasploit.com', + 'todb' => 'todb' + 0x40.chr + 'metasploit.com', + 'vlad902' => 'vlad902' + 0x40.chr + 'gmail.com', + 'wvu' => 'wvu' + 0x40.chr + 'metasploit.com' + } + + # + # Class method that translates a string to an instance of the Author class, + # if it's of the right format, and returns the Author class instance + # + def self.from_s(str) + instance = self.new + + # If the serialization fails... + if (instance.from_s(str) == false) + return nil + end + + return instance + end + + # + # Transforms the supplied source into an array of authors + # + def self.transform(src) + Rex::Transformer.transform(src, Array, [ self ], 'Author') + end + + def initialize(name = nil, email = nil) + self.name = name + self.email = email || Known[name] + end + + # + # Compares authors + # + def ==(tgt) + return (tgt.to_s == to_s) + end + + # + # Serialize the author object to a string in form: + # + # name + # + def to_s + str = "#{name}" + + if (email and not email.empty?) + str += " <#{email}>" + end + + return str + end + + # + # Translate the author from the supplied string which may + # have either just a name or also an email address + # + def from_s(str) + + + # Supported formats: + # known_name + # user [at/@] host [dot/.] tld + # Name + + + if ((m = str.match(/^\s*([^<]+)<([^>]+)>\s*$/))) + self.name = m[1].sub(/<.*/, '') + self.email = m[2].sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.') + else + if (Known[str]) + self.email = Known[str] + self.name = str + else + self.email = str.sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.').gsub(/^<|>$/, '') + m = self.email.match(/([^@]+)@/) + self.name = m ? m[1] : nil + if !(self.email and self.email.index('@')) + self.name = self.email + self.email = '' + end + end + end + + self.name.strip! if self.name + + return true + end + + # + # Sets the name of the author and updates the email if it's a known author. + # + def name=(name) + self.email = Known[name] if (Known[name]) + @name = name + end + + attr_accessor :email + attr_reader :name +end diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 1185c05da1..d903151455 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -13,7 +13,6 @@ module Msf ### class Module autoload :Arch, 'msf/core/module/arch' - autoload :Author, 'msf/core/module/author' autoload :AuxiliaryAction, 'msf/core/module/auxiliary_action' autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' @@ -103,7 +102,7 @@ class Module info_fixups # Transform some of the fields to arrays as necessary - self.author = Author.transform(module_info['Author']) + self.author = Msf::Author.transform(module_info['Author']) self.arch = Rex::Transformer.transform(module_info['Arch'], Array, [ String ], 'Arch') self.platform = PlatformList.transform(module_info['Platform']) self.references = Rex::Transformer.transform(module_info['References'], Array, [ SiteReference, Reference ], 'Ref') diff --git a/lib/msf/core/module/author.rb b/lib/msf/core/module/author.rb deleted file mode 100644 index 38c5021695..0000000000 --- a/lib/msf/core/module/author.rb +++ /dev/null @@ -1,149 +0,0 @@ -# -*- coding: binary -*- -require 'msf/core' - -### -# -# This data type represents an author of a piece of code in either -# the framework, a module, a script, or something entirely unrelated. -# -### -class Msf::Module::Author - - # A hash of known author names - Known = - { - 'amaloteaux' => 'alex_maloteaux' + 0x40.chr + 'metasploit.com', - 'anonymous' => 'Unknown', - 'bannedit' => 'bannedit' + 0x40.chr + 'metasploit.com', - 'Carlos Perez' => 'carlos_perez' + 0x40.chr + 'darkoperator.com', - 'cazz' => 'bmc' + 0x40.chr + 'shmoo.com', - 'CG' => 'cg' + 0x40.chr + 'carnal0wnage.com', - 'ddz' => 'ddz' + 0x40.chr + 'theta44.org', - 'egypt' => 'egypt' + 0x40.chr + 'metasploit.com', - 'et' => 'et' + 0x40.chr + 'metasploit.com', - 'Christian Mehlmauer' => 'FireFart' + 0x40.chr + 'gmail.com', - 'hdm' => 'hdm' + 0x40.chr + 'metasploit.com', - 'I)ruid' => 'druid' + 0x40.chr + 'caughq.org', - 'jcran' => 'jcran' + 0x40.chr + 'metasploit.com', - 'jduck' => 'jduck' + 0x40.chr + 'metasploit.com', - 'joev' => 'joev' + 0x40.chr + 'metasploit.com', - 'juan vazquez' => 'juan.vazquez' + 0x40.chr + 'metasploit.com', - 'kf' => 'kf_list' + 0x40.chr + 'digitalmunition.com', - 'kris katterjohn' => 'katterjohn' + 0x40.chr + 'gmail.com', - 'MC' => 'mc' + 0x40.chr + 'metasploit.com', - 'Ben Campbell' => 'eat_meatballs' + 0x40.chr + 'hotmail.co.uk', - 'msmith' => 'msmith' + 0x40.chr + 'metasploit.com', - 'mubix' => 'mubix' + 0x40.chr + 'hak5.org', - 'natron' => 'natron' + 0x40.chr + 'metasploit.com', - 'optyx' => 'optyx' + 0x40.chr + 'no$email.com', - 'patrick' => 'patrick' + 0x40.chr + 'osisecurity.com.au', - 'pusscat' => 'pusscat' + 0x40.chr + 'metasploit.com', - 'Ramon de C Valle' => 'rcvalle' + 0x40.chr + 'metasploit.com', - 'sf' => 'stephen_fewer' + 0x40.chr + 'harmonysecurity.com', - 'sinn3r' => 'sinn3r' + 0x40.chr + 'metasploit.com', - 'skape' => 'mmiller' + 0x40.chr + 'hick.org', - 'skylined' => 'skylined' + 0x40.chr + 'edup.tudelft.nl', - 'spoonm' => 'spoonm' + 0x40.chr + 'no$email.com', - 'stinko' => 'vinnie' + 0x40.chr + 'metasploit.com', - 'theLightCosine' => 'theLightCosine' + 0x40.chr + 'metasploit.com', - 'todb' => 'todb' + 0x40.chr + 'metasploit.com', - 'vlad902' => 'vlad902' + 0x40.chr + 'gmail.com', - 'wvu' => 'wvu' + 0x40.chr + 'metasploit.com' - } - - # - # Class method that translates a string to an instance of the Author class, - # if it's of the right format, and returns the Author class instance - # - def self.from_s(str) - instance = self.new - - # If the serialization fails... - if (instance.from_s(str) == false) - return nil - end - - return instance - end - - # - # Transforms the supplied source into an array of authors - # - def self.transform(src) - Rex::Transformer.transform(src, Array, [ self ], 'Author') - end - - def initialize(name = nil, email = nil) - self.name = name - self.email = email || Known[name] - end - - # - # Compares authors - # - def ==(tgt) - return (tgt.to_s == to_s) - end - - # - # Serialize the author object to a string in form: - # - # name - # - def to_s - str = "#{name}" - - if (email and not email.empty?) - str += " <#{email}>" - end - - return str - end - - # - # Translate the author from the supplied string which may - # have either just a name or also an email address - # - def from_s(str) - - - # Supported formats: - # known_name - # user [at/@] host [dot/.] tld - # Name - - - if ((m = str.match(/^\s*([^<]+)<([^>]+)>\s*$/))) - self.name = m[1].sub(/<.*/, '') - self.email = m[2].sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.') - else - if (Known[str]) - self.email = Known[str] - self.name = str - else - self.email = str.sub(/\s*\[at\]\s*/, '@').sub(/\s*\[dot\]\s*/, '.').gsub(/^<|>$/, '') - m = self.email.match(/([^@]+)@/) - self.name = m ? m[1] : nil - if !(self.email and self.email.index('@')) - self.name = self.email - self.email = '' - end - end - end - - self.name.strip! if self.name - - return true - end - - # - # Sets the name of the author and updates the email if it's a known author. - # - def name=(name) - self.email = Known[name] if (Known[name]) - @name = name - end - - attr_accessor :email - attr_reader :name -end diff --git a/spec/lib/msf/core/author_spec.rb b/spec/lib/msf/core/author_spec.rb index edb794971f..2165c74e3c 100644 --- a/spec/lib/msf/core/author_spec.rb +++ b/spec/lib/msf/core/author_spec.rb @@ -1,7 +1,28 @@ require 'spec_helper' describe Msf::Author do - it 'is an alias for Msf::Module::Author' do - expect(described_class.name).to eq('Msf::Module::Author') + context 'Known' do + subject(:known) { + described_class::Known + } + + it { is_expected.to be_a Hash } + end + + it { is_expected.to respond_to :== } + it { is_expected.to respond_to :email } + it { is_expected.to respond_to :email= } + it { is_expected.to respond_to :from_s } + it { is_expected.to respond_to :name } + it { is_expected.to respond_to :name= } + it { is_expected.to respond_to :to_s } + + context 'class' do + subject { + described_class + } + + it { is_expected.to respond_to :from_s } + it { is_expected.to respond_to :transform } end end \ No newline at end of file diff --git a/spec/lib/msf/core/module/author_spec.rb b/spec/lib/msf/core/module/author_spec.rb deleted file mode 100644 index 07256e06ef..0000000000 --- a/spec/lib/msf/core/module/author_spec.rb +++ /dev/null @@ -1,28 +0,0 @@ -require 'spec_helper' - -describe Msf::Module::Author do - context 'Known' do - subject(:known) { - described_class::Known - } - - it { is_expected.to be_a Hash } - end - - it { is_expected.to respond_to :== } - it { is_expected.to respond_to :email } - it { is_expected.to respond_to :email= } - it { is_expected.to respond_to :from_s } - it { is_expected.to respond_to :name } - it { is_expected.to respond_to :name= } - it { is_expected.to respond_to :to_s } - - context 'class' do - subject { - described_class - } - - it { is_expected.to respond_to :from_s } - it { is_expected.to respond_to :transform } - end -end \ No newline at end of file From a59e63591390774cdaa3ac7168dc5f5068c407fa Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 09:02:12 -0500 Subject: [PATCH 39/51] Extract Msf::Module::Author MSP-11126 --- lib/msf/core/module.rb | 23 +++----------------- lib/msf/core/module/author.rb | 36 ++++++++++++++++++++++++++++++++ spec/lib/msf/core/module_spec.rb | 1 + 3 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 lib/msf/core/module/author.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index d903151455..79419ec00d 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -13,6 +13,7 @@ module Msf ### class Module autoload :Arch, 'msf/core/module/arch' + autoload :Author, 'msf/core/module/author' autoload :AuxiliaryAction, 'msf/core/module/auxiliary_action' autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' @@ -34,6 +35,7 @@ class Module autoload :UI, 'msf/core/module/ui' include Msf::Module::Arch + include Msf::Module::Author include Msf::Module::Compatibility include Msf::Module::DataStore include Msf::Module::FullName @@ -214,20 +216,6 @@ class Module self.datastore['ParentUUID'] = ref.uuid.dup end - # - # Return a comma separated list of author for this module. - # - def author_to_s - author.collect { |author| author.to_s }.join(", ") - end - - # - # Enumerate each author. - # - def each_author(&block) - author.each(&block) - end - # # Return a comma separated list of supported platforms, if any. # @@ -277,11 +265,6 @@ class Module false end - # - # The array of zero or more authors. - # - attr_reader :author - # # The array of zero or more platforms. # @@ -348,7 +331,7 @@ protected (self.method(method_name).to_s.match(/#{parent}[^:]/)) ? false : true end - attr_writer :author, :platform, :references # :nodoc: + attr_writer :platform, :references # :nodoc: attr_writer :privileged # :nodoc: attr_writer :license # :nodoc: diff --git a/lib/msf/core/module/author.rb b/lib/msf/core/module/author.rb new file mode 100644 index 0000000000..5c390ae229 --- /dev/null +++ b/lib/msf/core/module/author.rb @@ -0,0 +1,36 @@ +module Msf::Module::Author + # + # Attributes + # + + # @!attribute author + # The array of zero or more authors. + attr_reader :author + + # + # Instance Methods + # + + # + # Return a comma separated list of author for this module. + # + def author_to_s + author.collect { |author| author.to_s }.join(", ") + end + + # + # Enumerate each author. + # + def each_author(&block) + author.each(&block) + end + + protected + + # + # Attributes + # + + # @!attribute [w] author + attr_writer :author +end diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 77df432560..c639f83b20 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' require 'msf/core/module' describe Msf::Module do + it { is_expected.to respond_to :author } it { is_expected.to respond_to :author_to_s } it { is_expected.to respond_to :check } it { is_expected.to respond_to :debugging? } From d86eda5f1d3778f77a911cc6d382855d533d94d7 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 11:20:23 -0500 Subject: [PATCH 40/51] Extract Msf::Module::Author shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 3 --- spec/support/shared/examples/msf/module/author.rb | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/author.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index c639f83b20..176e4c4b28 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -3,12 +3,9 @@ require 'spec_helper' require 'msf/core/module' describe Msf::Module do - it { is_expected.to respond_to :author } - it { is_expected.to respond_to :author_to_s } it { is_expected.to respond_to :check } it { is_expected.to respond_to :debugging? } it { is_expected.to respond_to :derived_implementor? } - it { is_expected.to respond_to :each_author } it { is_expected.to respond_to :fail_with } it { is_expected.to respond_to :file_path } it { is_expected.to respond_to :framework } diff --git a/spec/support/shared/examples/msf/module/author.rb b/spec/support/shared/examples/msf/module/author.rb new file mode 100644 index 0000000000..f1f6ab707c --- /dev/null +++ b/spec/support/shared/examples/msf/module/author.rb @@ -0,0 +1,5 @@ +shared_examples_for 'Msf::Module::Author' do + it { is_expected.to respond_to :author } + it { is_expected.to respond_to :author_to_s } + it { is_expected.to respond_to :each_author } +end From cbae9be5b5ee6a9d3a129c08a2931a9ffc588db0 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 11:31:56 -0500 Subject: [PATCH 41/51] Extract Msf::Module::UUID MSP-11126 --- lib/msf/core/module.rb | 13 +++---------- lib/msf/core/module/uuid.rb | 27 +++++++++++++++++++++++++++ spec/lib/msf/core/module_spec.rb | 1 + 3 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 lib/msf/core/module/uuid.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 79419ec00d..9bd86d6800 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -33,6 +33,7 @@ class Module autoload :Target, 'msf/core/module/target' autoload :Type, 'msf/core/module/type' autoload :UI, 'msf/core/module/ui' + autoload :UUID, 'msf/core/module/uuid' include Msf::Module::Arch include Msf::Module::Author @@ -47,6 +48,7 @@ class Module include Msf::Module::Search include Msf::Module::Type include Msf::Module::UI + include Msf::Module::UUID # Make include public so we can runtime extend public_class_method :include @@ -293,16 +295,7 @@ class Module # attr_accessor :error - # - # A unique identifier for this module instance - # - attr_reader :uuid - -protected - attr_writer :uuid - def generate_uuid - self.uuid = Rex::Text.rand_text_alphanumeric(8).downcase - end + protected # # Sets the modules unsupplied info fields to their default values. diff --git a/lib/msf/core/module/uuid.rb b/lib/msf/core/module/uuid.rb new file mode 100644 index 0000000000..d985122768 --- /dev/null +++ b/lib/msf/core/module/uuid.rb @@ -0,0 +1,27 @@ +module Msf::Module::UUID + # + # Attributes + # + + # @!attribute [r] uuid + # A unique identifier for this module instance + attr_reader :uuid + + protected + + # + # Attributes + # + + # @!attribute [w] uuid + attr_writer :uuid + + + # + # Instance Methods + # + + def generate_uuid + self.uuid = Rex::Text.rand_text_alphanumeric(8).downcase + end +end \ No newline at end of file diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 176e4c4b28..9b57e43d75 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -18,6 +18,7 @@ describe Msf::Module do it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } it { is_expected.to respond_to :set_defaults } + it { is_expected.to respond_to :uuid } it { is_expected.to respond_to :workspace } it_should_behave_like 'Msf::Module::Arch' From 45302b94031658234fa15ded65f52e28ae41312f Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 11:34:35 -0500 Subject: [PATCH 42/51] Extract Msf::Module::UUID shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 2 +- spec/support/shared/examples/msf/module/uuid.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 spec/support/shared/examples/msf/module/uuid.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 9b57e43d75..5855cc32b1 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -18,7 +18,6 @@ describe Msf::Module do it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } it { is_expected.to respond_to :set_defaults } - it { is_expected.to respond_to :uuid } it { is_expected.to respond_to :workspace } it_should_behave_like 'Msf::Module::Arch' @@ -33,6 +32,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::Search' it_should_behave_like 'Msf::Module::Type' it_should_behave_like 'Msf::Module::UI' + it_should_behave_like 'Msf::Module::UUID' context 'class' do subject { diff --git a/spec/support/shared/examples/msf/module/uuid.rb b/spec/support/shared/examples/msf/module/uuid.rb new file mode 100644 index 0000000000..a40bd133c3 --- /dev/null +++ b/spec/support/shared/examples/msf/module/uuid.rb @@ -0,0 +1,3 @@ +shared_examples_for 'Msf::Module::UUID' do + it { is_expected.to respond_to :uuid } +end From 172afd180a65fbd090a24e11189e37ad4691a3f9 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 11:45:03 -0500 Subject: [PATCH 43/51] Extract Msf::Module::Privileged MSP-11126 --- lib/msf/core/module.rb | 13 ++----------- lib/msf/core/module/privileged.rb | 29 +++++++++++++++++++++++++++++ spec/lib/msf/core/module_spec.rb | 1 + 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 lib/msf/core/module/privileged.rb diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 9bd86d6800..6044b59952 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -26,6 +26,7 @@ class Module autoload :Options, 'msf/core/module/options' autoload :Platform, 'msf/core/module/platform' autoload :PlatformList, 'msf/core/module/platform_list' + autoload :Privileged, 'msf/core/module/privileged' autoload :Rank, 'msf/core/module/rank' autoload :Reference, 'msf/core/module/reference' autoload :Search, 'msf/core/module/search' @@ -44,6 +45,7 @@ class Module include Msf::Module::ModuleStore include Msf::Module::Network include Msf::Module::Options + include Msf::Module::Privileged include Msf::Module::Rank include Msf::Module::Search include Msf::Module::Type @@ -232,13 +234,6 @@ class Module (platform & what).empty? == false end - # - # Returns whether or not the module requires or grants high privileges. - # - def privileged? - privileged == true - end - # # Returns true if this module is being debugged. The debug flag is set # by setting datastore['DEBUG'] to 1|true|yes @@ -276,10 +271,6 @@ class Module # attr_reader :references - # - # Whether or not this module requires privileged access. - # - attr_reader :privileged # # The license under which this module is provided. # diff --git a/lib/msf/core/module/privileged.rb b/lib/msf/core/module/privileged.rb new file mode 100644 index 0000000000..cbf797ab30 --- /dev/null +++ b/lib/msf/core/module/privileged.rb @@ -0,0 +1,29 @@ +module Msf::Module::Privileged + # + # Attributes + # + + # @!attribute [r] privileged + # Whether or not this module requires privileged access. + attr_reader :privileged + + # + # Instance Methods + # + + # + # Returns whether or not the module requires or grants high privileges. + # + def privileged? + privileged == true + end + + protected + + # + # Attributes + # + + # @!attribute [w] privileged + attr_writer :priveli +end \ No newline at end of file diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index 5855cc32b1..e33dd4c165 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -14,6 +14,7 @@ describe Msf::Module do it { is_expected.to respond_to :owner } it { is_expected.to respond_to :platform? } it { is_expected.to respond_to :platform_to_s } + it { is_expected.to respond_to :privileged } it { is_expected.to respond_to :privileged? } it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } From 575717681c54032588ab98d47aed0c300354478e Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 11:48:36 -0500 Subject: [PATCH 44/51] Extract Msf::Module::Privileged shared examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 3 +-- spec/support/shared/examples/msf/module/privileged.rb | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 spec/support/shared/examples/msf/module/privileged.rb diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index e33dd4c165..c2567c420b 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -14,8 +14,6 @@ describe Msf::Module do it { is_expected.to respond_to :owner } it { is_expected.to respond_to :platform? } it { is_expected.to respond_to :platform_to_s } - it { is_expected.to respond_to :privileged } - it { is_expected.to respond_to :privileged? } it { is_expected.to respond_to :register_parent } it { is_expected.to respond_to :replicant } it { is_expected.to respond_to :set_defaults } @@ -29,6 +27,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::ModuleStore' it_should_behave_like 'Msf::Module::Network' it_should_behave_like 'Msf::Module::Options' + it_should_behave_like 'Msf::Module::Privileged' it_should_behave_like 'Msf::Module::Rank' it_should_behave_like 'Msf::Module::Search' it_should_behave_like 'Msf::Module::Type' diff --git a/spec/support/shared/examples/msf/module/privileged.rb b/spec/support/shared/examples/msf/module/privileged.rb new file mode 100644 index 0000000000..d2df732ac3 --- /dev/null +++ b/spec/support/shared/examples/msf/module/privileged.rb @@ -0,0 +1,4 @@ +shared_examples_for 'Msf::Module::Privileged' do + it { is_expected.to respond_to :privileged } + it { is_expected.to respond_to :privileged? } +end \ No newline at end of file From 7ffd07c44db4523ffa623c2f2320279218ad848e Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 11:49:01 -0500 Subject: [PATCH 45/51] Remove protected method from specs examples MSP-11126 --- spec/lib/msf/core/module_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index c2567c420b..b9e6651efb 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -9,7 +9,6 @@ describe Msf::Module do it { is_expected.to respond_to :fail_with } it { is_expected.to respond_to :file_path } it { is_expected.to respond_to :framework } - it { is_expected.to respond_to :generate_uuid } it { is_expected.to respond_to :orig_cls } it { is_expected.to respond_to :owner } it { is_expected.to respond_to :platform? } From 0c00c7cc5099b0ab38ba605a0888394020dbb9d3 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 12:43:40 -0500 Subject: [PATCH 46/51] Fully-qualifiy Msf::MODULE_TYPES constants MSP-11126 Fully-qualify `Msf::MODULE_TYPES`, `Msf::MODULE_ANY`, Msf::MODULE_ENCODER`, `Msf::MODULE_EXPLOIT`, `Msf::MODULE_NOP`, `Msf::MODULE_AUX`, `Msf::MODULE_PAYLOAD`, `Msf::MODULE_POST` so that their usage isn't dependent on nested lexical scoping. --- lib/msf/base/serializer/readable_text.rb | 12 ++++++------ lib/msf/base/simple/framework.rb | 12 ++++++------ lib/msf/core/auxiliary.rb | 4 ++-- lib/msf/core/encoder.rb | 4 ++-- lib/msf/core/exploit.rb | 4 ++-- lib/msf/core/framework.rb | 2 +- lib/msf/core/module/compatibility.rb | 6 +++--- lib/msf/core/module/type.rb | 12 ++++++------ lib/msf/core/nop.rb | 4 ++-- lib/msf/core/payload.rb | 4 ++-- lib/msf/core/payload_set.rb | 2 +- lib/msf/ui/console/command_dispatcher/core.rb | 12 ++++++------ 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/msf/base/serializer/readable_text.rb b/lib/msf/base/serializer/readable_text.rb index c558a0117c..b3d30a125c 100644 --- a/lib/msf/base/serializer/readable_text.rb +++ b/lib/msf/base/serializer/readable_text.rb @@ -20,17 +20,17 @@ class ReadableText # @return [String] formatted text output of the dump. def self.dump_module(mod, indent = " ") case mod.type - when MODULE_PAYLOAD + when Msf::MODULE_PAYLOAD return dump_payload_module(mod, indent) - when MODULE_NOP + when Msf::MODULE_NOP return dump_basic_module(mod, indent) - when MODULE_ENCODER + when Msf::MODULE_ENCODER return dump_basic_module(mod, indent) - when MODULE_EXPLOIT + when Msf::MODULE_EXPLOIT return dump_exploit_module(mod, indent) - when MODULE_AUX + when Msf::MODULE_AUX return dump_auxiliary_module(mod, indent) - when MODULE_POST + when Msf::MODULE_POST return dump_post_module(mod, indent) else return dump_generic_module(mod, indent) diff --git a/lib/msf/base/simple/framework.rb b/lib/msf/base/simple/framework.rb index ff45da2aa2..b67b285d22 100644 --- a/lib/msf/base/simple/framework.rb +++ b/lib/msf/base/simple/framework.rb @@ -54,12 +54,12 @@ module Framework ModuleSimplifiers = { - MODULE_ENCODER => Msf::Simple::Encoder, - MODULE_EXPLOIT => Msf::Simple::Exploit, - MODULE_NOP => Msf::Simple::Nop, - MODULE_PAYLOAD => Msf::Simple::Payload, - MODULE_AUX => Msf::Simple::Auxiliary, - MODULE_POST => Msf::Simple::Post, + Msf::MODULE_ENCODER => Msf::Simple::Encoder, + Msf::MODULE_EXPLOIT => Msf::Simple::Exploit, + Msf::MODULE_NOP => Msf::Simple::Nop, + Msf::MODULE_PAYLOAD => Msf::Simple::Payload, + Msf::MODULE_AUX => Msf::Simple::Auxiliary, + Msf::MODULE_POST => Msf::Simple::Post, } # diff --git a/lib/msf/core/auxiliary.rb b/lib/msf/core/auxiliary.rb index 44aa6329c3..c244724fd3 100644 --- a/lib/msf/core/auxiliary.rb +++ b/lib/msf/core/auxiliary.rb @@ -21,14 +21,14 @@ class Auxiliary < Msf::Module # Returns MODULE_AUX to indicate that this is an auxiliary module. # def self.type - MODULE_AUX + Msf::MODULE_AUX end # # Returns MODULE_AUX to indicate that this is an auxiliary module. # def type - MODULE_AUX + Msf::MODULE_AUX end # diff --git a/lib/msf/core/encoder.rb b/lib/msf/core/encoder.rb index 78cc094b84..5106ef184d 100644 --- a/lib/msf/core/encoder.rb +++ b/lib/msf/core/encoder.rb @@ -150,14 +150,14 @@ class Encoder < Module # Returns MODULE_ENCODER to indicate that this is an encoder module. # def self.type - return MODULE_ENCODER + return Msf::MODULE_ENCODER end # # Returns MODULE_ENCODER to indicate that this is an encoder module. # def type - return MODULE_ENCODER + return Msf::MODULE_ENCODER end # diff --git a/lib/msf/core/exploit.rb b/lib/msf/core/exploit.rb index e5b070d546..363d6c4a9c 100644 --- a/lib/msf/core/exploit.rb +++ b/lib/msf/core/exploit.rb @@ -621,14 +621,14 @@ class Exploit < Msf::Module # Returns MODULE_EXPLOIT to indicate that this is an exploit module. # def self.type - MODULE_EXPLOIT + Msf::MODULE_EXPLOIT end # # Returns MODULE_EXPLOIT to indicate that this is an exploit module. # def type - MODULE_EXPLOIT + Msf::MODULE_EXPLOIT end # diff --git a/lib/msf/core/framework.rb b/lib/msf/core/framework.rb index 70c7ae6883..55fc46e557 100644 --- a/lib/msf/core/framework.rb +++ b/lib/msf/core/framework.rb @@ -69,7 +69,7 @@ class Framework def initialize(opts={}) # Allow specific module types to be loaded - types = opts[:module_types] || MODULE_TYPES + types = opts[:module_types] || Msf::MODULE_TYPES self.threads = ThreadManager.new(self) self.events = EventDispatcher.new(self) diff --git a/lib/msf/core/module/compatibility.rb b/lib/msf/core/module/compatibility.rb index e1e7ca300a..72cdf143cf 100644 --- a/lib/msf/core/module/compatibility.rb +++ b/lib/msf/core/module/compatibility.rb @@ -17,11 +17,11 @@ module Msf::Module::Compatibility return true if (mod == nil) # Determine which hash to used based on the supplied module type - if (mod.type == MODULE_ENCODER) + if (mod.type == Msf::MODULE_ENCODER) ch = self.compat['Encoder'] - elsif (mod.type == MODULE_NOP) + elsif (mod.type == Msf::MODULE_NOP) ch = self.compat['Nop'] - elsif (mod.type == MODULE_PAYLOAD) + elsif (mod.type == Msf::MODULE_PAYLOAD) ch = self.compat['Payload'] if self.respond_to?("target") and self.target and self.target['Payload'] and self.target['Payload']['Compat'] ch = ch.merge(self.target['Payload']['Compat']) diff --git a/lib/msf/core/module/type.rb b/lib/msf/core/module/type.rb index 14b4c6be77..1b0505df86 100644 --- a/lib/msf/core/module/type.rb +++ b/lib/msf/core/module/type.rb @@ -18,42 +18,42 @@ module Msf::Module::Type # Returns true if this module is an auxiliary module. # def auxiliary? - (type == MODULE_AUX) + (type == Msf::MODULE_AUX) end # # Returns true if this module is an encoder module. # def encoder? - (type == MODULE_ENCODER) + (type == Msf::MODULE_ENCODER) end # # Returns true if this module is an exploit module. # def exploit? - (type == MODULE_EXPLOIT) + (type == Msf::MODULE_EXPLOIT) end # # Returns true if this module is a nop module. # def nop? - (type == MODULE_NOP) + (type == Msf::MODULE_NOP) end # # Returns true if this module is a payload module. # def payload? - (type == MODULE_PAYLOAD) + (type == Msf::MODULE_PAYLOAD) end # # Returns true if this module is an post-exploitation module. # def post? - (type == MODULE_POST) + (type == Msf::MODULE_POST) end # diff --git a/lib/msf/core/nop.rb b/lib/msf/core/nop.rb index 763c76f8a7..3f52876c98 100644 --- a/lib/msf/core/nop.rb +++ b/lib/msf/core/nop.rb @@ -14,14 +14,14 @@ class Nop < Msf::Module # Returns MODULE_NOP to indicate that this is a NOP module. # def self.type - return MODULE_NOP + return Msf::MODULE_NOP end # # Returns MODULE_NOP to indicate that this is a NOP module. # def type - return MODULE_NOP + return Msf::MODULE_NOP end # diff --git a/lib/msf/core/payload.rb b/lib/msf/core/payload.rb index a712034020..34bdeac9ef 100644 --- a/lib/msf/core/payload.rb +++ b/lib/msf/core/payload.rb @@ -102,14 +102,14 @@ class Payload < Msf::Module # Returns MODULE_PAYLOAD to indicate that this is a payload module. # def self.type - return MODULE_PAYLOAD + return Msf::MODULE_PAYLOAD end # # Returns MODULE_PAYLOAD to indicate that this is a payload module. # def type - return MODULE_PAYLOAD + return Msf::MODULE_PAYLOAD end # diff --git a/lib/msf/core/payload_set.rb b/lib/msf/core/payload_set.rb index 97b5b4c7a2..9a202d936a 100644 --- a/lib/msf/core/payload_set.rb +++ b/lib/msf/core/payload_set.rb @@ -21,7 +21,7 @@ class PayloadSet < ModuleSet # set class that has custom handling for payloads. # def initialize - super(MODULE_PAYLOAD) + super(Msf::MODULE_PAYLOAD) # A hash of each of the payload types that holds an array # for all of the associated modules diff --git a/lib/msf/ui/console/command_dispatcher/core.rb b/lib/msf/ui/console/command_dispatcher/core.rb index 20a6de64de..1906582b6c 100644 --- a/lib/msf/ui/console/command_dispatcher/core.rb +++ b/lib/msf/ui/console/command_dispatcher/core.rb @@ -2364,17 +2364,17 @@ class Core dispatcher = nil case mod.type - when MODULE_ENCODER + when Msf::MODULE_ENCODER dispatcher = Msf::Ui::Console::CommandDispatcher::Encoder - when MODULE_EXPLOIT + when Msf::MODULE_EXPLOIT dispatcher = Msf::Ui::Console::CommandDispatcher::Exploit - when MODULE_NOP + when Msf::MODULE_NOP dispatcher = Msf::Ui::Console::CommandDispatcher::Nop - when MODULE_PAYLOAD + when Msf::MODULE_PAYLOAD dispatcher = Msf::Ui::Console::CommandDispatcher::Payload - when MODULE_AUX + when Msf::MODULE_AUX dispatcher = Msf::Ui::Console::CommandDispatcher::Auxiliary - when MODULE_POST + when Msf::MODULE_POST dispatcher = Msf::Ui::Console::CommandDispatcher::Post else print_error("Unsupported module type: #{mod.type}") From 112b5988f29a0f6bc45d82a583b7e4d41c6967b7 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 13:05:59 -0500 Subject: [PATCH 47/51] Add missing autoload to fix loading on travis-ci MSP-11126 `Msf::Module::Failure` fails to load on travis-ci probably due to a load order difference, so add `:Failure` to autoloads in `Msf::Module`. --- lib/msf/core/module.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 6044b59952..e0448cb675 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -18,6 +18,7 @@ class Module autoload :Compatibility, 'msf/core/module/compatibility' autoload :DataStore, 'msf/core/module/data_store' autoload :Deprecated, 'msf/core/module/deprecated' + autoload :Failure, 'msf/core/module/failure' autoload :FullName, 'msf/core/module/full_name' autoload :HasActions, 'msf/core/module/has_actions' autoload :ModuleInfo, 'msf/core/module/module_info' From a6a2886faa29d50df299cdc71dfb129352ee8d18 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 13:09:27 -0500 Subject: [PATCH 48/51] Fully-qualify Msf::OptionContainer references MSP-11126 --- lib/msf/core/module.rb | 2 +- lib/msf/core/module/module_info.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index e0448cb675..7313ff5d34 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -115,7 +115,7 @@ class Module self.references = Rex::Transformer.transform(module_info['References'], Array, [ SiteReference, Reference ], 'Ref') # Create and initialize the option container for this module - self.options = OptionContainer.new + self.options = Msf::OptionContainer.new self.options.add_options(info['Options'], self.class) self.options.add_advanced_options(info['AdvancedOptions'], self.class) self.options.add_evasion_options(info['EvasionOptions'], self.class) diff --git a/lib/msf/core/module/module_info.rb b/lib/msf/core/module/module_info.rb index a341b91bc5..e59423b9df 100644 --- a/lib/msf/core/module/module_info.rb +++ b/lib/msf/core/module/module_info.rb @@ -159,9 +159,9 @@ module Msf::Module::ModuleInfo key_name = ((advanced) ? 'Advanced' : (evasion) ? 'Evasion' : '') + 'Options' - new_cont = OptionContainer.new + new_cont = Msf::OptionContainer.new new_cont.add_options(val, advanced, evasion) - cur_cont = OptionContainer.new + cur_cont = Msf::OptionContainer.new cur_cont.add_options(info[key_name] || [], advanced, evasion) new_cont.each_option { |name, option| From ae45c1b9d337f936c632c31bafbef5e3cce3ef2f Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 13:39:53 -0500 Subject: [PATCH 49/51] Msf::Module::Rank -> Msf::Module::Ranking MSP-11126 So that mixin module won't appear as Rank constant that Msf::Module subclasses are supposed to define. --- lib/msf/core/module.rb | 4 ++-- lib/msf/core/module/{rank.rb => ranking.rb} | 2 +- spec/lib/msf/core/module_spec.rb | 2 +- .../shared/examples/msf/module/{rank.rb => ranking.rb} | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) rename lib/msf/core/module/{rank.rb => ranking.rb} (96%) rename spec/support/shared/examples/msf/module/{rank.rb => ranking.rb} (87%) diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index 7313ff5d34..0c1a775501 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -28,7 +28,7 @@ class Module autoload :Platform, 'msf/core/module/platform' autoload :PlatformList, 'msf/core/module/platform_list' autoload :Privileged, 'msf/core/module/privileged' - autoload :Rank, 'msf/core/module/rank' + autoload :Ranking, 'msf/core/module/ranking' autoload :Reference, 'msf/core/module/reference' autoload :Search, 'msf/core/module/search' autoload :SiteReference, 'msf/core/module/reference' @@ -47,7 +47,7 @@ class Module include Msf::Module::Network include Msf::Module::Options include Msf::Module::Privileged - include Msf::Module::Rank + include Msf::Module::Ranking include Msf::Module::Search include Msf::Module::Type include Msf::Module::UI diff --git a/lib/msf/core/module/rank.rb b/lib/msf/core/module/ranking.rb similarity index 96% rename from lib/msf/core/module/rank.rb rename to lib/msf/core/module/ranking.rb index c671764c96..e6c7ee2d38 100644 --- a/lib/msf/core/module/rank.rb +++ b/lib/msf/core/module/ranking.rb @@ -1,4 +1,4 @@ -module Msf::Module::Rank +module Msf::Module::Ranking extend ActiveSupport::Concern module ClassMethods diff --git a/spec/lib/msf/core/module_spec.rb b/spec/lib/msf/core/module_spec.rb index b9e6651efb..2105974962 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -27,7 +27,7 @@ describe Msf::Module do it_should_behave_like 'Msf::Module::Network' it_should_behave_like 'Msf::Module::Options' it_should_behave_like 'Msf::Module::Privileged' - it_should_behave_like 'Msf::Module::Rank' + it_should_behave_like 'Msf::Module::Ranking' it_should_behave_like 'Msf::Module::Search' it_should_behave_like 'Msf::Module::Type' it_should_behave_like 'Msf::Module::UI' diff --git a/spec/support/shared/examples/msf/module/rank.rb b/spec/support/shared/examples/msf/module/ranking.rb similarity index 87% rename from spec/support/shared/examples/msf/module/rank.rb rename to spec/support/shared/examples/msf/module/ranking.rb index 823aa2a81a..0f17760847 100644 --- a/spec/support/shared/examples/msf/module/rank.rb +++ b/spec/support/shared/examples/msf/module/ranking.rb @@ -1,4 +1,4 @@ -shared_examples_for 'Msf::Module::Rank' do +shared_examples_for 'Msf::Module::Ranking' do it { is_expected.to respond_to :rank } it { is_expected.to respond_to :rank_to_h } it { is_expected.to respond_to :rank_to_s } From 43354774e18f7d7f0dd53b95def9f7075e6f9e3e Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 13:43:51 -0500 Subject: [PATCH 50/51] Fully qualified Msf::RankingName in Msf::Module::Ranking MSP-11126 To compensate for loss of `Msf` lexical scope. --- lib/msf/core/module/ranking.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msf/core/module/ranking.rb b/lib/msf/core/module/ranking.rb index e6c7ee2d38..2a8f9ccb07 100644 --- a/lib/msf/core/module/ranking.rb +++ b/lib/msf/core/module/ranking.rb @@ -20,7 +20,7 @@ module Msf::Module::Ranking # Returns this module's ranking as a string representation. # def rank_to_s - RankingName[rank] + Msf::RankingName[rank] end end From 06fbbf7001556796adf35ad23d3b161183c822d0 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Fri, 17 Oct 2014 13:58:57 -0500 Subject: [PATCH 51/51] Fully-qualified Msf::NormalRanking in Msf::Module::Ranking MSP-11126 Needed due to loss of `Msf` lexical scope. --- lib/msf/core/module/ranking.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msf/core/module/ranking.rb b/lib/msf/core/module/ranking.rb index 2a8f9ccb07..ca9b2f45e8 100644 --- a/lib/msf/core/module/ranking.rb +++ b/lib/msf/core/module/ranking.rb @@ -6,7 +6,7 @@ module Msf::Module::Ranking # Returns this module's ranking. # def rank - (const_defined?('Rank')) ? const_get('Rank') : NormalRanking + (const_defined?('Rank')) ? const_get('Rank') : Msf::NormalRanking end #