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[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
-
.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
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 62 63 64 65 66 67 |
# File 'lib/msf/core/modules/metadata/search.rb', line 33 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][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
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/msf/core/modules/metadata/search.rb', line 72 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 |