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.
Defined Under Namespace
Modules: SearchMode
Constant Summary collapse
- VALID_PARAMS =
%w[ action adapter aka arch author authors bid check cve date description disclosure_date edb fullname mod_time name os path platform port rank ref ref_name reference references rport session_type stage stager target targets text type ]
- MODULE_TYPE_SHORTHANDS =
Module Type Shorthands
{ "aux" => Msf::MODULE_AUX }
Class Method Summary collapse
-
.parse_search_string(search_string) ⇒ Object
Parses command line search string into a hash.
Instance Method Summary collapse
-
#find(params, fields = {}) ⇒ Object
Searches the module metadata using the passed hash of search params.
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
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/msf/core/modules/metadata/search.rb', line 66 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| # Split it on the `:`, with the part before the first `:` going into keyword, the part after first `:` # but before any later instances of `:` going into search_term, and the characters after the second # `:` or later in the string going into _excess to be ignored. # # Example is `use exploit/linux/local/nested_namespace_idmap_limit_priv_esc::a` # which would make keyword become `exploit/linux/local/nested_namespace_idmap_limit_priv_esc`, # search_term become blank, and _excess become "a". keyword, search_term, _excess = term.split(":", 3) if search_term.blank? 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][SearchMode::EXCLUDE] << search_term[1,search_term.length-1] else res[keyword][SearchMode::INCLUDE] << search_term end end res end |
Instance Method Details
#find(params, fields = {}) ⇒ Object
Searches the module metadata using the passed hash of search params
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/msf/core/modules/metadata/search.rb', line 112 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 |