Skip to content

Commit

Permalink
Land rapid7#18580, Allow external modules to specify default options
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 authored Nov 30, 2023
2 parents 15bf3cb + 6f1fa8d commit b900964
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 17 deletions.
14 changes: 6 additions & 8 deletions lib/msf/core/modules/external/shim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/msf/core/modules/external/templates/common_metadata.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
],
'License' => <%= meta[:license] %>,
'Notes' => <%= meta[:notes] %>,
'DefaultOptions' => {
<%= meta[:default_options].map { |name, value| "#{name.dump} => #{value.inspect}" }.join(",\n#{' ' * 8}") %>
},
6 changes: 1 addition & 5 deletions lib/msf/core/modules/external/templates/evasion.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ class MetasploitModule < Msf::Evasion
'Targets' =>
[
<%= meta[:targets] %>
],
'DefaultOptions' =>
{
<%= meta[:default_options] %>
}
]
})

register_options([
Expand Down
3 changes: 1 addition & 2 deletions lib/msf/core/modules/external/templates/remote_exploit.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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] %>
Expand All @@ -22,7 +22,6 @@ class MetasploitModule < Msf::Exploit::Remote
<%= meta[:targets] %>
],
'DefaultTarget' => 0,
'DefaultOptions' => { 'WfsDelay' => <%= meta[:wfsdelay] %> },
))

register_options([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] %>
Expand All @@ -23,7 +23,6 @@ class MetasploitModule < Msf::Exploit::Remote
<%= meta[:targets] %>
],
'DefaultTarget' => 0,
'DefaultOptions' => { 'WfsDelay' => <%= meta[:wfsdelay] %> },
))

register_options([
Expand Down

0 comments on commit b900964

Please sign in to comment.