class Mihari::Analyzers::Onyphe

Constants

PAGE_SIZE

Public Instance Methods

artifacts() click to toggle source
# File lib/mihari/analyzers/onyphe.rb, line 14
def artifacts
  responses = search
  return [] unless responses

  results = responses.map(&:results).flatten
  results.map do |result|
    build_artifact result
  end
end

Private Instance Methods

api() click to toggle source
# File lib/mihari/analyzers/onyphe.rb, line 32
def api
  @api ||= ::Onyphe::API.new(Mihari.config.onyphe_api_key)
end
build_artifact(result) click to toggle source

Build an artifact from an Onyphe search API result

@param [Structs::Onyphe::Result] result

@return [Artifact]

# File lib/mihari/analyzers/onyphe.rb, line 73
def build_artifact(result)
  as = AutonomousSystem.new(asn: normalize_asn(result.asn))

  geolocation = nil
  unless result.country_code.nil?
    geolocation = Geolocation.new(
      country: NormalizeCountry(result.country_code, to: :short),
      country_code: result.country_code
    )
  end

  Artifact.new(
    data: result.ip,
    source: source,
    autonomous_system: as,
    geolocation: geolocation
  )
end
configuration_keys() click to toggle source
# File lib/mihari/analyzers/onyphe.rb, line 28
def configuration_keys
  %w[onyphe_api_key]
end
search_with_page(query, page: 1) click to toggle source

Search with pagination

@param [String] query @param [Integer] page

@return [Structs::Onyphe::Response]

# File lib/mihari/analyzers/onyphe.rb, line 44
def search_with_page(query, page: 1)
  res = api.simple.datascan(query, page: page)
  Structs::Onyphe::Response.from_dynamic!(res)
end