Class: Mihari::Analyzers::Urlscan

Inherits:
Base
  • Object
show all
Defined in:
lib/mihari/analyzers/urlscan.rb

Constant Summary collapse

SUPPORTED_DATA_TYPES =
%w[url domain ip].freeze
SIZE =
1000

Constants included from Mixins::Retriable

Mixins::Retriable::DEFAULT_ON

Instance Attribute Summary collapse

Attributes inherited from Base

#rule

Instance Method Summary collapse

Methods inherited from Base

inherited, #normalized_artifacts, #run, #run_emitter, #source

Methods included from Mixins::Retriable

#retry_on_error

Methods included from Mixins::Configurable

#configuration_values, #configured?

Methods included from Mixins::AutonomousSystem

#normalize_asn

Constructor Details

#initialize(*args, **kwargs) ⇒ Urlscan

Returns a new instance of Urlscan.

Raises:



20
21
22
23
24
25
26
# File 'lib/mihari/analyzers/urlscan.rb', line 20

def initialize(*args, **kwargs)
  super

  raise InvalidInputError, "allowed_data_types should be any of url, domain and ip." unless valid_alllowed_data_types?

  @api_key = kwargs[:api_key] || Mihari.config.urlscan_api_key
end

Instance Attribute Details

#api_keyString? (readonly)

Returns:

  • (String, nil)


18
19
20
# File 'lib/mihari/analyzers/urlscan.rb', line 18

def api_key
  @api_key
end

Instance Method Details

#artifactsObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mihari/analyzers/urlscan.rb', line 28

def artifacts
  responses = search
  results = responses.map(&:results).flatten

  allowed_data_types.map do |type|
    results.filter_map do |result|
      page = result.page
      data = page.send(type.to_sym)
      data.nil? ? nil : Artifact.new(data: data, source: source, metadata: result)
    end
  end.flatten
end