From ac03a0723aaf6b575fc37cc60e4d0b0edec6b4e5 Mon Sep 17 00:00:00 2001 From: Adam Cammack Date: Mon, 14 May 2018 11:32:22 -0500 Subject: [PATCH] Factor external check shim into common template --- lib/msf/core/modules/external/shim.rb | 4 ++++ lib/msf/core/modules/external/templates/common_check.erb | 7 +++++++ .../external/templates/remote_exploit_cmd_stager.erb | 7 +------ 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 lib/msf/core/modules/external/templates/common_check.erb diff --git a/lib/msf/core/modules/external/shim.rb b/lib/msf/core/modules/external/shim.rb index 271e93c163..9c55d2efc8 100644 --- a/lib/msf/core/modules/external/shim.rb +++ b/lib/msf/core/modules/external/shim.rb @@ -32,6 +32,10 @@ class Msf::Modules::External::Shim render_template('common_metadata.erb', meta) end + def self.common_check(meta = {}) + render_template('common_check.erb', meta) + end + def self.mod_meta_common(mod, meta = {}, drop_rhost: false) meta[:path] = mod.path.dump meta[:name] = mod.meta['name'].dump diff --git a/lib/msf/core/modules/external/templates/common_check.erb b/lib/msf/core/modules/external/templates/common_check.erb new file mode 100644 index 0000000000..93964b3498 --- /dev/null +++ b/lib/msf/core/modules/external/templates/common_check.erb @@ -0,0 +1,7 @@ +<% if meta[:capabilities].include? 'soft_check' %> +def check + code = execute_module(<%= meta[:path] %>, method: :soft_check, fail_on_exit: false) || 'unknown' + return Msf::Exploit::CheckCode::Codes[code] +end +<% end %> + diff --git a/lib/msf/core/modules/external/templates/remote_exploit_cmd_stager.erb b/lib/msf/core/modules/external/templates/remote_exploit_cmd_stager.erb index b0450c47a8..3368291e9d 100644 --- a/lib/msf/core/modules/external/templates/remote_exploit_cmd_stager.erb +++ b/lib/msf/core/modules/external/templates/remote_exploit_cmd_stager.erb @@ -34,12 +34,7 @@ class MetasploitModule < Msf::Exploit::Remote ]) end - <% if meta[:capabilities].include? 'soft_check' %> - def check - code = execute_module(<%= meta[:path] %>, method: :soft_check, fail_on_exit: false) || 'unknown' - return Msf::Exploit::CheckCode::Codes[code] - end - <% end %> + <%= common_check meta %> def execute_command(cmd, opts) execute_module(<%= meta[:path] %>, args: datastore.merge(command: cmd))