class Mihari::Analyzers::ZoomEye
Constants
- PAGE_SIZE
Public Instance Methods
artifacts()
click to toggle source
# File lib/mihari/analyzers/zoomeye.rb, line 14 def artifacts case type when "host" host_search when "web" web_search else raise InvalidInputError, "#{type} type is not supported." unless valid_type? end end
Private Instance Methods
_host_search(query, page: 1)
click to toggle source
Host search
@param [String] query @param [Integer] page
@return [Hash, nil]
# File lib/mihari/analyzers/zoomeye.rb, line 70 def _host_search(query, page: 1) api.host.search(query, page: page) rescue ::ZoomEye::Error => _e nil end
_web_search(query, page: 1)
click to toggle source
Web search
@param [String] query @param [Integer] page
@return [Hash, nil]
# File lib/mihari/analyzers/zoomeye.rb, line 102 def _web_search(query, page: 1) api.web.search(query, page: page) rescue ::ZoomEye::Error => _e nil end
api()
click to toggle source
# File lib/mihari/analyzers/zoomeye.rb, line 42 def api @api ||= ::ZoomEye::API.new(api_key: Mihari.config.zoomeye_api_key) end
configuration_keys()
click to toggle source
# File lib/mihari/analyzers/zoomeye.rb, line 38 def configuration_keys %w[zoomeye_api_key] end
convert_responses(responses)
click to toggle source
Convert responses into an array of String
@param [Array<Hash>] responses
@return [Array<String>]
# File lib/mihari/analyzers/zoomeye.rb, line 53 def convert_responses(responses) responses.map do |res| matches = res["matches"] || [] matches.map do |match| match["ip"] end end.flatten.compact.uniq end
host_search()
click to toggle source
Host search
@return [Array<String>]
# File lib/mihari/analyzers/zoomeye.rb, line 81 def host_search responses = [] (1..Float::INFINITY).each do |page| res = _host_search(query, page: page) break unless res total = res["total"].to_i responses << res break if total <= page * PAGE_SIZE end convert_responses responses.compact end
valid_type?()
click to toggle source
Check whether a type is valid or not
@return [Boolean]
# File lib/mihari/analyzers/zoomeye.rb, line 34 def valid_type? %w[host web].include? type end
web_search()
click to toggle source
Web search
@return [Array<String>]
# File lib/mihari/analyzers/zoomeye.rb, line 113 def web_search responses = [] (1..Float::INFINITY).each do |page| res = _web_search(query, page: page) break unless res total = res["total"].to_i responses << res break if total <= page * PAGE_SIZE end convert_responses responses.compact end