From 5fa1ddf4ebc5bb7fd8d5909eaa2956af69d3b43f Mon Sep 17 00:00:00 2001 From: William Vu Date: Tue, 17 Jul 2018 20:45:49 -0500 Subject: [PATCH 1/7] Remove default check method --- lib/msf/base/simple/auxiliary.rb | 4 ++-- lib/msf/base/simple/exploit.rb | 4 ++-- lib/msf/core/module.rb | 10 ---------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/msf/base/simple/auxiliary.rb b/lib/msf/base/simple/auxiliary.rb index de8930ce02..f2ea3a43a4 100644 --- a/lib/msf/base/simple/auxiliary.rb +++ b/lib/msf/base/simple/auxiliary.rb @@ -115,8 +115,8 @@ module Auxiliary mod.setup - # Run check - mod.check + # Run check if it exists + mod.respond_to?(:check) ? check : Msf::Exploit::CheckCode::Unsupported end # diff --git a/lib/msf/base/simple/exploit.rb b/lib/msf/base/simple/exploit.rb index 1536ef2985..a9a0bdf83c 100644 --- a/lib/msf/base/simple/exploit.rb +++ b/lib/msf/base/simple/exploit.rb @@ -185,8 +185,8 @@ module Exploit mod.setup - # Run check - mod.check + # Run check if it exists + mod.respond_to?(:check) ? check : Msf::Exploit::CheckCode::Unsupported end # diff --git a/lib/msf/core/module.rb b/lib/msf/core/module.rb index cde4d88dc4..366052d93d 100644 --- a/lib/msf/core/module.rb +++ b/lib/msf/core/module.rb @@ -203,16 +203,6 @@ class Module self.class.file_path end - # - # Checks to see if the target is vulnerable, returning unsupported if it's - # not supported. - # - # This method is designed to be overriden by exploit modules. - # - def check - Msf::Exploit::CheckCode::Unsupported - end - # # Returns the current workspace # From 98d6d4cbcda02aa06427a9dea15f6a64d82e2071 Mon Sep 17 00:00:00 2001 From: William Vu Date: Tue, 17 Jul 2018 20:47:40 -0500 Subject: [PATCH 2/7] Add check for check to info command --- lib/msf/base/serializer/readable_text.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/msf/base/serializer/readable_text.rb b/lib/msf/base/serializer/readable_text.rb index 83c30fbab0..52a5aea32e 100644 --- a/lib/msf/base/serializer/readable_text.rb +++ b/lib/msf/base/serializer/readable_text.rb @@ -183,6 +183,10 @@ class ReadableText output << "Available targets:\n" output << dump_exploit_targets(mod, indent) + # Check + output << "Check supported:\n" + output << "#{indent}#{mod.respond_to?(:check) ? 'Yes' : 'No'}\n\n" + # Options if (mod.options.has_options?) output << "Basic options:\n" @@ -241,6 +245,10 @@ class ReadableText output << dump_module_actions(mod, indent) end + # Check + output << "Check supported:\n" + output << "#{indent}#{mod.respond_to?(:check) ? 'Yes' : 'No'}\n\n" + # Options if (mod.options.has_options?) output << "Basic options:\n" From de23559491bc4856097ee336da1b90587b217b68 Mon Sep 17 00:00:00 2001 From: William Vu Date: Tue, 17 Jul 2018 20:51:32 -0500 Subject: [PATCH 3/7] Add check for check to module cache --- lib/msf/core/modules/metadata/obj.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/msf/core/modules/metadata/obj.rb b/lib/msf/core/modules/metadata/obj.rb index 41104697b2..3ac1c2f71b 100644 --- a/lib/msf/core/modules/metadata/obj.rb +++ b/lib/msf/core/modules/metadata/obj.rb @@ -26,6 +26,7 @@ class Obj attr_reader :mod_time attr_reader :is_install_path attr_reader :ref_name + attr_reader :check def initialize(module_instance, obj_hash = nil) unless obj_hash.nil? @@ -49,7 +50,7 @@ class Obj sort_platform_string @arch = module_instance.arch_to_s - @rport = module_instance.datastore['RPORT'].to_s + @rport = module_instance.datastore['RPORT'] @path = module_instance.file_path @mod_time = ::File.mtime(@path) rescue Time.now @ref_name = module_instance.refname @@ -63,6 +64,9 @@ class Obj @targets = module_instance.targets.map{|x| x.name} end + # Store whether a module has a check method + @check = module_instance.respond_to?(:check) ? true : false + # Due to potentially non-standard ASCII we force UTF-8 to ensure no problem with JSON serialization force_encoding(Encoding::UTF_8) end @@ -89,7 +93,8 @@ class Obj 'mod_time' => @mod_time.to_s, 'path' => @path, 'is_install_path' => @is_install_path, - 'ref_name' => @ref_name + 'ref_name' => @ref_name, + 'check' => @check }.to_json(*args) end @@ -135,6 +140,7 @@ class Obj @path = obj_hash['path'] @is_install_path = obj_hash['is_install_path'] @targets = obj_hash['targets'].nil? ? [] : obj_hash['targets'] + @check = obj_hash['check'] ? true : false end def sort_platform_string From 1371fc6daf5ef197328f7b6de1646f9830d00074 Mon Sep 17 00:00:00 2001 From: William Vu Date: Wed, 18 Jul 2018 17:22:24 -0500 Subject: [PATCH 4/7] Fix regexed integer RPORT for module search --- lib/msf/core/modules/metadata/search.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/msf/core/modules/metadata/search.rb b/lib/msf/core/modules/metadata/search.rb index 6c37305d3b..5758d9dd8a 100644 --- a/lib/msf/core/modules/metadata/search.rb +++ b/lib/msf/core/modules/metadata/search.rb @@ -88,7 +88,7 @@ module Msf::Modules::Metadata::Search match = [t,w] if module_metadata.targets.any? { |t| t =~ r } end when 'port' - match = [t,w] if module_metadata.rport =~ r + match = [t,w] if module_metadata.rport.to_s =~ r when 'type' match = [t,w] if Msf::MODULE_TYPES.any? { |modt| w == modt and module_metadata.type == modt } when 'app' From 74b74b89d1bef7d7d159aae043ca930e30677d17 Mon Sep 17 00:00:00 2001 From: William Vu Date: Wed, 18 Jul 2018 17:39:38 -0500 Subject: [PATCH 5/7] Fix spec for modules not defining check It's no longer necessary, and we handle this and return the right thing. --- 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 a888784eb0..c05c95018b 100644 --- a/spec/lib/msf/core/module_spec.rb +++ b/spec/lib/msf/core/module_spec.rb @@ -7,7 +7,6 @@ RSpec.describe Msf::Module do described_class.new } - it { is_expected.to respond_to :check } it { is_expected.to respond_to :debugging? } it { is_expected.to respond_to :fail_with } it { is_expected.to respond_to :file_path } From 58ad718a7d6d2eea1bda2721c2dd79d8f9fb2f02 Mon Sep 17 00:00:00 2001 From: William Vu Date: Fri, 20 Jul 2018 14:07:36 -0500 Subject: [PATCH 6/7] Display check support in module search --- lib/msf/ui/console/command_dispatcher/modules.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/msf/ui/console/command_dispatcher/modules.rb b/lib/msf/ui/console/command_dispatcher/modules.rb index a09996a77b..74ed5d48bf 100644 --- a/lib/msf/ui/console/command_dispatcher/modules.rb +++ b/lib/msf/ui/console/command_dispatcher/modules.rb @@ -385,6 +385,7 @@ module Msf m.full_name, m.disclosure_date.nil? ? '' : m.disclosure_date.strftime("%Y-%m-%d"), RankingName[m.rank].to_s, + m.check ? 'Yes' : 'No', m.name ] end @@ -1101,6 +1102,7 @@ module Msf refname, o.disclosure_date.nil? ? "" : o.disclosure_date.strftime("%Y-%m-%d"), o.rank_to_s, + o.respond_to?(:check) ? 'Yes' : 'No', o.name ] end @@ -1117,7 +1119,7 @@ module Msf 'Header' => type, 'Prefix' => "\n", 'Postfix' => "\n", - 'Columns' => [ 'Name', 'Disclosure Date', 'Rank', 'Description' ], + 'Columns' => [ 'Name', 'Disclosure Date', 'Rank', 'Check', 'Description' ], 'SearchTerm' => search_term ) end From 654cbd198a053bcd2e9882656248f6e25e5130c4 Mon Sep 17 00:00:00 2001 From: William Vu Date: Mon, 23 Jul 2018 14:19:48 -0500 Subject: [PATCH 7/7] Fix missing method when check is run Oops, lost the "mod" when I refactored into ternary. Caught during verification with @wchen-r7. :D --- lib/msf/base/simple/auxiliary.rb | 2 +- lib/msf/base/simple/exploit.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/msf/base/simple/auxiliary.rb b/lib/msf/base/simple/auxiliary.rb index f2ea3a43a4..5a0ea1efa9 100644 --- a/lib/msf/base/simple/auxiliary.rb +++ b/lib/msf/base/simple/auxiliary.rb @@ -116,7 +116,7 @@ module Auxiliary mod.setup # Run check if it exists - mod.respond_to?(:check) ? check : Msf::Exploit::CheckCode::Unsupported + mod.respond_to?(:check) ? mod.check : Msf::Exploit::CheckCode::Unsupported end # diff --git a/lib/msf/base/simple/exploit.rb b/lib/msf/base/simple/exploit.rb index a9a0bdf83c..09e670ffd9 100644 --- a/lib/msf/base/simple/exploit.rb +++ b/lib/msf/base/simple/exploit.rb @@ -186,7 +186,7 @@ module Exploit mod.setup # Run check if it exists - mod.respond_to?(:check) ? check : Msf::Exploit::CheckCode::Unsupported + mod.respond_to?(:check) ? mod.check : Msf::Exploit::CheckCode::Unsupported end #