Module: Msf::ModuleManager::ModulePaths

Extended by:
ActiveSupport::Concern
Included in:
Msf::ModuleManager
Defined in:
lib/msf/core/module_manager/module_paths.rb

Overview

Deals with module paths in the Msf::ModuleManager

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#module_pathsObject (protected)

:nodoc:


63
64
65
# File 'lib/msf/core/module_manager/module_paths.rb', line 63

def module_paths
  @module_paths
end

Instance Method Details

#add_module_path(path, opts = {}) ⇒ Hash{String => Integer}

Adds a path to be searched for new modules.

Parameters:

  • path (String)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • whitelist (Array)

    An array of regex patterns to search for specific modules

Returns:

  • (Hash{String => Integer})

    Maps module type to number of modules loaded


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/msf/core/module_manager/module_paths.rb', line 19

def add_module_path(path, opts={})
  nested_paths = []

  # remove trailing file separator
  path_without_trailing_file_separator = path.sub(/#{File::SEPARATOR}$/, '')

  # Make the path completely canonical
  pathname = Pathname.new(path_without_trailing_file_separator).expand_path

  # Make sure the path is a valid directory
  unless pathname.directory?
    raise ArgumentError, "The path supplied is not a valid directory.", caller
  end

  nested_paths << pathname.to_s

  # Update the module paths appropriately
  self.module_paths = (module_paths + nested_paths).flatten.uniq

  # Load all of the modules from the nested paths
  count_by_type = {}
  nested_paths.each { |path|
    path_count_by_type = load_modules(path, opts.merge({:force => false}))

    # merge hashes
    path_count_by_type.each do |type, path_count|
      accumulated_count = count_by_type.fetch(type, 0)
      count_by_type[type] = accumulated_count + path_count
    end
  }

  return count_by_type
end

#remove_module_path(path) ⇒ Object

Removes a path from which to search for modules.


56
57
58
59
# File 'lib/msf/core/module_manager/module_paths.rb', line 56

def remove_module_path(path)
  module_paths.delete(path)
  module_paths.delete(::File.expand_path(path))
end