class Mihari::Analyzers::Censys

Public Instance Methods

artifacts() click to toggle source
# File lib/mihari/analyzers/censys.rb, line 13
def artifacts
  search
end

Private Instance Methods

api() click to toggle source
# File lib/mihari/analyzers/censys.rb, line 84
def api
  @api ||= ::Censys::API.new(Mihari.config.censys_id, Mihari.config.censys_secret)
end
build_artifact(hit) click to toggle source

Build an artifact from a Shodan search API response

@param [Structs::Censys::Hit] hit

@return [Artifact]

# File lib/mihari/analyzers/censys.rb, line 59
def build_artifact(hit)
  as = AutonomousSystem.new(asn: normalize_asn(hit.autonomous_system.asn))

  # sometimes Censys overlooks country
  # then set geolocation as nil
  geolocation = nil
  unless hit.location.country.nil?
    geolocation = Geolocation.new(
      country: hit.location.country,
      country_code: hit.location.country_code
    )
  end

  Artifact.new(
    data: hit.ip,
    source: source,
    autonomous_system: as,
    geolocation: geolocation
  )
end
configuration_keys() click to toggle source
# File lib/mihari/analyzers/censys.rb, line 80
def configuration_keys
  %w[censys_id censys_secret]
end
response_to_artifacts(response) click to toggle source

Extract IPv4s from Censys search API response

@param [Structs::Censys::Response] response

@return [Array<String>]

# File lib/mihari/analyzers/censys.rb, line 48
def response_to_artifacts(response)
  response.result.hits.map { |hit| build_artifact(hit) }
end