Module: Msf::Modules::Metadata::Search

Included in:
Cache
Defined in:
lib/msf/core/modules/metadata/search.rb

Overview

Provides search operations on the module metadata cache.

Constant Summary collapse

VALID_PARAMS =
%w[aka author authors arch cve bid edb check date disclosure_date description fullname fullname mod_time
name os platform path port rport rank ref ref_name reference references target targets text type]
MODULE_TYPE_SHORTHANDS =

Module Type Shorthands

{
  "aux" => Msf::MODULE_AUX
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_search_string(search_string) ⇒ Object

Parses command line search string into a hash. A param prefixed with '-' indicates “not”, and will omit results matching that keyword. This hash can be used with the find command.

Resulting Hash Example: href=""android"">platform”=>[, []] will match modules targeting the android platform href="">platform”=>[, [“android”]] will exclude modules targeting the android platform


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
52
53
54
55
56
57
58
59
60
61
# File 'lib/msf/core/modules/metadata/search.rb', line 27

def self.parse_search_string(search_string)
  search_string ||= ''
  search_string += ' '

  # Split search terms by space, but allow quoted strings
  terms = search_string.split(/\"/).collect{|term| term.strip==term ? term : term.split(' ')}.flatten
  terms.delete('')

  # All terms are either included or excluded
  res = {}

  terms.each do |term|
    keyword, search_term = term.split(":", 2)
    unless search_term
      search_term = keyword
      keyword = 'text'
    end
    next if search_term.length == 0
    keyword.downcase!
    search_term.downcase!

    if keyword == "type"
      search_term = MODULE_TYPE_SHORTHANDS[search_term] if MODULE_TYPE_SHORTHANDS.key?(search_term)
    end

    res[keyword] ||=[   [],    []   ]
    if search_term[0,1] == "-"
      next if search_term.length == 1
      res[keyword][1] << search_term[1,search_term.length-1]
    else
      res[keyword][0] << search_term
    end
  end
  res
end

Instance Method Details

#find(params, fields = {}) ⇒ Object

Searches the module metadata using the passed hash of search params

Raises:

  • (ArgumentError)

66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/msf/core/modules/metadata/search.rb', line 66

def find(params, fields={})
  raise ArgumentError if params.any? && VALID_PARAMS.none? { |k| params.key?(k) }
  search_results = []

  .each { ||
    if is_match(params, )
      unless fields.empty?
         = get_fields(, fields)
      end
      search_results << 
    end
  }
  return search_results
end