diff --git a/lib/msf/core/modules/external/shim.rb b/lib/msf/core/modules/external/shim.rb index ddf5542b58e4..e506ef42b36b 100644 --- a/lib/msf/core/modules/external/shim.rb +++ b/lib/msf/core/modules/external/shim.rb @@ -35,8 +35,10 @@ def self.render_template(name, meta = {}) ERB.new(File.read(template)).result(binding) end - def self.common_metadata(meta = {}) - render_template('common_metadata.erb', meta) + def self.common_metadata(meta = {}, default_options: {}) + # Combine any template defaults with the defaults specified within the external module's metadata + default_options = default_options.merge(meta[:default_options]) + render_template('common_metadata.erb', meta.merge(default_options: default_options)) end def self.common_check(meta = {}) @@ -54,12 +56,8 @@ def self.mod_meta_common(mod, meta = {}, ignore_options: []) meta[:capabilities] = mod.meta['capabilities'] meta[:notes] = transform_notes(mod.meta['notes']) - if mod.meta['describe_payload_options'].nil? - mod.meta['describe_payload_options'] = {} - end - meta[:default_options] = mod.meta['describe_payload_options'].map do |name, value| - "#{name.dump} => #{value.inspect}" - end.join(",\n ") + # Additionally check the 'describe_payload_options' key for backwards compatibility + meta[:default_options] = (mod.meta['default_options'] || mod.meta['describe_payload_options'] || {}) meta end diff --git a/lib/msf/core/modules/external/templates/common_metadata.erb b/lib/msf/core/modules/external/templates/common_metadata.erb index 934423225cf1..c861ec4063b3 100644 --- a/lib/msf/core/modules/external/templates/common_metadata.erb +++ b/lib/msf/core/modules/external/templates/common_metadata.erb @@ -6,3 +6,6 @@ ], 'License' => <%= meta[:license] %>, 'Notes' => <%= meta[:notes] %>, + 'DefaultOptions' => { + <%= meta[:default_options].map { |name, value| "#{name.dump} => #{value.inspect}" }.join(",\n#{' ' * 8}") %> + }, diff --git a/lib/msf/core/modules/external/templates/evasion.erb b/lib/msf/core/modules/external/templates/evasion.erb index 832ecc7eec5a..ca966c291194 100644 --- a/lib/msf/core/modules/external/templates/evasion.erb +++ b/lib/msf/core/modules/external/templates/evasion.erb @@ -16,11 +16,7 @@ class MetasploitModule < Msf::Evasion 'Targets' => [ <%= meta[:targets] %> - ], - 'DefaultOptions' => - { - <%= meta[:default_options] %> - } + ] }) register_options([ diff --git a/lib/msf/core/modules/external/templates/remote_exploit.erb b/lib/msf/core/modules/external/templates/remote_exploit.erb index 72e2bea2c71a..d29ed3e5011d 100644 --- a/lib/msf/core/modules/external/templates/remote_exploit.erb +++ b/lib/msf/core/modules/external/templates/remote_exploit.erb @@ -8,7 +8,7 @@ class MetasploitModule < Msf::Exploit::Remote def initialize(info = {}) super(update_info(info, - <%= common_metadata meta %> + <%= common_metadata meta, default_options: { 'WfsDelay' => meta[:wfsdelay] } %> 'References' => [ <%= meta[:references] %> @@ -22,7 +22,6 @@ class MetasploitModule < Msf::Exploit::Remote <%= meta[:targets] %> ], 'DefaultTarget' => 0, - 'DefaultOptions' => { 'WfsDelay' => <%= meta[:wfsdelay] %> }, )) register_options([ 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 4f54e956c0d4..4e6407013680 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 @@ -9,7 +9,7 @@ class MetasploitModule < Msf::Exploit::Remote def initialize(info = {}) super(update_info(info, - <%= common_metadata meta %> + <%= common_metadata meta, default_options: { 'WfsDelay' => meta[:wfsdelay] } %> 'References' => [ <%= meta[:references] %> @@ -23,7 +23,6 @@ class MetasploitModule < Msf::Exploit::Remote <%= meta[:targets] %> ], 'DefaultTarget' => 0, - 'DefaultOptions' => { 'WfsDelay' => <%= meta[:wfsdelay] %> }, )) register_options([