diff --git a/lib/msf/core/modules/external/shim.rb b/lib/msf/core/modules/external/shim.rb index ed2b55a967..2c26a5a668 100644 --- a/lib/msf/core/modules/external/shim.rb +++ b/lib/msf/core/modules/external/shim.rb @@ -13,6 +13,8 @@ class Msf::Modules::External::Shim capture_server(mod) when 'dos' dos(mod) + when 'scanner.single' + single_scanner(mod) when 'scanner.multi' multi_scanner(mod) else @@ -30,13 +32,19 @@ class Msf::Modules::External::Shim render_template('common_metadata.erb', meta) end - def self.mod_meta_common(mod, meta = {}) + def self.mod_meta_common(mod, meta = {}, drop_rhost: true) meta[:path] = mod.path.dump meta[:name] = mod.meta['name'].dump meta[:description] = mod.meta['description'].dump meta[:authors] = mod.meta['authors'].map(&:dump).join(",\n ") - meta[:options] = mod.meta['options'].map do |n, o| + options = if drop_rhost + mod.meta['options'].reject {|n, o| n == 'rhost'} + else + mod.meta['options'] + end + + meta[:options] = options.map do |n, o| "Opt#{o['type'].camelize}.new(#{n.dump}, [#{o['required']}, #{o['description'].dump}, #{o['default'].inspect}])" end.join(",\n ") @@ -71,6 +79,16 @@ class Msf::Modules::External::Shim render_template('capture_server.erb', meta) end + def self.single_scanner(mod) + meta = mod_meta_common(mod, drop_rhost: true) + meta[:date] = mod.meta['date'].dump + meta[:references] = mod.meta['references'].map do |r| + "[#{r['type'].upcase.dump}, #{r['ref'].dump}]" + end.join(",\n ") + + render_template('single_scanner.erb', meta) + end + def self.multi_scanner(mod) meta = mod_meta_common(mod) meta[:date] = mod.meta['date'].dump diff --git a/lib/msf/core/modules/external/templates/single_scanner.erb b/lib/msf/core/modules/external/templates/single_scanner.erb new file mode 100644 index 0000000000..1ecdce5230 --- /dev/null +++ b/lib/msf/core/modules/external/templates/single_scanner.erb @@ -0,0 +1,31 @@ +require 'msf/core/modules/external/bridge' +require 'msf/core/module/external' + +class MetasploitModule < Msf::Auxiliary + include Msf::Auxiliary::Scanner + include Msf::Module::External + + def initialize + super({ + <%= common_metadata meta %> + 'References' => + [ + <%= meta[:references] %> + ], + 'DisclosureDate' => <%= meta[:date] %>, + }) + + register_options([ + <%= meta[:options] %> + ]) + end + + def run_host(ip) + print_status("Running for #{ip}...") + mod = Msf::Modules::External::Bridge.open(<%= meta[:path] %>) + rhost = datastore.delete('RHOST') + datastore['rhost'] = rhost + mod.run(datastore) + wait_status(mod) + end +end