Class: Mihari::Analyzers::Censys

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

Constant Summary collapse

CENSYS_ID_KEY =
"CENSYS_ID"
CENSYS_SECRET_KEY =
"CENSYS_SECRET"

Instance Attribute Summary collapse

Attributes inherited from Base

#the_hive

Instance Method Summary collapse

Methods inherited from Base

#run, #run_emitter

Constructor Details

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

Returns a new instance of Censys.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mihari/analyzers/censys.rb', line 17

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

  raise ArgumentError, "#{CENSYS_ID_KEY} and #{CENSYS_SECRET_KEY} are required" unless valid?

  @api = ::Censys::API.new
  @query = query
  @title = title || "Censys lookup"
  @description = description || "query = #{query}"
  @tags = tags
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



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

def api
  @api
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#queryObject (readonly)

Returns the value of attribute query.



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

def query
  @query
end

#tagsObject (readonly)

Returns the value of attribute tags.



12
13
14
# File 'lib/mihari/analyzers/censys.rb', line 12

def tags
  @tags
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

#artifactsObject



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

def artifacts
  ipv4s = []
  res = api.ipv4.search(query: query)
  res.each_page do |page|
    page.each { |result| ipv4s << result.ip }
  end

  ipv4s
end

#censys_id?true, false

Returns:

  • (true, false)


40
41
42
# File 'lib/mihari/analyzers/censys.rb', line 40

def censys_id?
  ENV.key? CENSYS_ID_KEY
end

#censys_secret?true, false

Returns:

  • (true, false)


45
46
47
# File 'lib/mihari/analyzers/censys.rb', line 45

def censys_secret?
  ENV.key? CENSYS_SECRET_KEY
end

#valid?true, false

Returns:

  • (true, false)


50
51
52
# File 'lib/mihari/analyzers/censys.rb', line 50

def valid?
  censys_id? && censys_secret?
end