Class: Mihari::Analyzers::Shodan

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, #run, #run_emitter, #source

Methods included from Retriable

#retry_on_error

Methods included from Configurable

#configuration_status, #configured?

Constructor Details

#initialize(query, title: nil, description: nil, tags: []) ⇒ Shodan

Returns a new instance of Shodan.



13
14
15
16
17
18
19
20
# File 'lib/mihari/analyzers/shodan.rb', line 13

def initialize(query, title: nil, description: nil, tags: [])
  super()

  @query = query
  @title = title || "Shodan lookup"
  @description = description || "query = #{query}"
  @tags = tags
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/mihari/analyzers/shodan.rb', line 9

def description
  @description
end

#queryObject (readonly)

Returns the value of attribute query.



10
11
12
# File 'lib/mihari/analyzers/shodan.rb', line 10

def query
  @query
end

#tagsObject (readonly)

Returns the value of attribute tags.



11
12
13
# File 'lib/mihari/analyzers/shodan.rb', line 11

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/mihari/analyzers/shodan.rb', line 8

def title
  @title
end

Instance Method Details

#artifactsObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mihari/analyzers/shodan.rb', line 22

def artifacts
  results = search
  return [] unless results || results.empty?

  results.map do |result|
    matches = result.dig("matches") || []
    matches.map do |match|
      match.dig "ip_str"
    end.compact
  end.flatten.compact.uniq
end