mihari 0.13.0 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c45276dc9bbc108475c4db517d7bf0e7e809c85de3ee3e7f6141df444e1890db
4
- data.tar.gz: 90f9bc7cfa1d25a1186b98b3418069b0c8e30bde28bdb2ebd3ded6930e48b015
3
+ metadata.gz: df5ec8a92b6bf1622274b5b488aa544520d15f0360e5274ba466f324f49d0e0e
4
+ data.tar.gz: eb6149534d02b0ee551f37b7f01a65e3c936851fdb589bf21b1b938cb2f9d963
5
5
  SHA512:
6
- metadata.gz: fa740d55a2fad831f1bf18aeae5aa2695b00c8cc92f09512ebd1c178eaa66083cb65309c4ccd6b2e2e81db450fb21c213d556ad6d5974f7e9037eb814fe75a20
7
- data.tar.gz: 03edf15c5fe58fe9b237829510eda124fc91507a6f9903a5f2ecccef275e29ceb94d30a73a4cfc9485a3ca1905c406b58fd87655c4d0ec4d05514755ca768e22
6
+ metadata.gz: 51bd37cf056ad05ba6c5abd499b045ef963de6bb30414168229826a390ff0ee66a751204d6210336e668092a397f4d879c3a0ad39fcd84b381f11c77b42d7c74
7
+ data.tar.gz: c1ad6709246b86ede8a204b2db51af678149fd5bccfec2701c6562cf52123b1215c18a644091e49f23f352e8d248bc40e1fc84523491c5893670b9bb8f3ee7d8
@@ -27,6 +27,7 @@ require "mihari/cache"
27
27
  require "mihari/type_checker"
28
28
 
29
29
  require "mihari/configurable"
30
+ require "mihari/retriable"
30
31
 
31
32
  require "mihari/the_hive/base"
32
33
  require "mihari/the_hive/alert"
@@ -6,6 +6,7 @@ module Mihari
6
6
  module Analyzers
7
7
  class Base
8
8
  include Configurable
9
+ include Retriable
9
10
 
10
11
  # @return [Array<String>, Array<Mihari::Artifact>]
11
12
  def artifacts
@@ -30,16 +31,13 @@ module Mihari
30
31
  def run
31
32
  set_unique_artifacts
32
33
 
33
- Parallel.each(Mihari.emitters) do |emitter_class|
34
- emitter = emitter_class.new
35
- next unless emitter.valid?
36
-
34
+ Parallel.each(valid_emitters) do |emitter|
37
35
  run_emitter emitter
38
36
  end
39
37
  end
40
38
 
41
39
  def run_emitter(emitter)
42
- emitter.emit(title: title, description: description, artifacts: unique_artifacts, tags: tags)
40
+ emitter.run(title: title, description: description, artifacts: unique_artifacts, tags: tags)
43
41
  rescue StandardError => e
44
42
  puts "Emission by #{emitter.class} is failed: #{e}"
45
43
  end
@@ -60,7 +58,7 @@ module Mihari
60
58
 
61
59
  # @return [Array<Mihari::Artifact>]
62
60
  def normalized_artifacts
63
- @normalized_artifacts ||= artifacts.compact.uniq.map do |artifact|
61
+ @normalized_artifacts ||= artifacts.compact.uniq.sort.map do |artifact|
64
62
  artifact.is_a?(Artifact) ? artifact : Artifact.new(artifact)
65
63
  end.select(&:valid?)
66
64
  end
@@ -79,11 +77,18 @@ module Mihari
79
77
  end
80
78
 
81
79
  def set_unique_artifacts
82
- unique_artifacts
80
+ retry_on_timeout { unique_artifacts }
83
81
  rescue ArgumentError => _e
84
82
  klass = self.class.to_s.split("::").last.to_s
85
83
  raise Error, "Please configure #{klass} API settings properly"
86
84
  end
85
+
86
+ def valid_emitters
87
+ @valid_emitters ||= Mihari.emitters.map do |klass|
88
+ emitter = klass.new
89
+ emitter.valid? ? emitter : nil
90
+ end.compact
91
+ end
87
92
  end
88
93
  end
89
94
  end
@@ -30,7 +30,7 @@ module Mihari
30
30
  when "certificates"
31
31
  certificates_lookup
32
32
  else
33
- raise TypeError, "#{type} type is not supported." unless valid_type?
33
+ raise InvalidInputError, "#{type} type is not supported." unless valid_type?
34
34
  end
35
35
  end
36
36
 
@@ -41,7 +41,7 @@ module Mihari
41
41
  when "hash"
42
42
  passive_ssl_lookup
43
43
  else
44
- raise TypeError, "#{@query}(type: #{@type || 'unknown'}) is not supported."
44
+ raise InvalidInputError, "#{@query}(type: #{@type || 'unknown'}) is not supported."
45
45
  end
46
46
  rescue ::PassiveCIRCL::Error => _e
47
47
  nil
@@ -52,7 +52,7 @@ module Mihari
52
52
  when "hash"
53
53
  ssl_lookup
54
54
  else
55
- raise TypeError, "#{query}(type: #{type || 'unknown'}) is not supported." unless valid_type?
55
+ raise InvalidInputError, "#{query}(type: #{type || 'unknown'}) is not supported." unless valid_type?
56
56
  end
57
57
  rescue ::PassiveTotal::Error => _e
58
58
  nil
@@ -50,7 +50,7 @@ module Mihari
50
50
  when "mail"
51
51
  mail_lookup
52
52
  else
53
- raise TypeError, "#{query}(type: #{type || 'unknown'}) is not supported." unless valid_type?
53
+ raise InvalidInputError, "#{query}(type: #{type || 'unknown'}) is not supported." unless valid_type?
54
54
  end
55
55
  rescue ::SecurityTrails::Error => _e
56
56
  nil
@@ -17,8 +17,8 @@ module Mihari
17
17
  @_regexp = regexp
18
18
  @type = type
19
19
 
20
- raise TypeError, "#{@_regexp} is not a valid regexp" unless regexp
21
- raise TypeError, "#{type} is not a valid type" unless valid_type?
20
+ raise InvalidInputError, "#{@_regexp} is not a valid regexp" unless regexp
21
+ raise InvalidInputError, "#{type} is not a valid type" unless valid_type?
22
22
 
23
23
  @title = title || "SecurityTrails domain feed lookup"
24
24
  @description = description || "Regexp = /#{@_regexp}/"
@@ -45,7 +45,7 @@ module Mihari
45
45
 
46
46
  def regexp
47
47
  @regexp ||= Regexp.compile(@_regexp)
48
- rescue TypeError => _e
48
+ rescue InvalidInputError => _e
49
49
  nil
50
50
  end
51
51
 
@@ -20,7 +20,7 @@ module Mihari
20
20
  @tags = tags
21
21
  @target_type = target_type
22
22
 
23
- raise TypeError, "type should be url, domain or ip." unless valid_target_type?
23
+ raise InvalidInputError, "type should be url, domain or ip." unless valid_target_type?
24
24
  end
25
25
 
26
26
  def artifacts
@@ -48,7 +48,7 @@ module Mihari
48
48
  when "ip"
49
49
  ip_lookup
50
50
  else
51
- raise TypeError, "#{indicator}(type: #{type || 'unknown'}) is not supported." unless valid_type?
51
+ raise InvalidInputError, "#{indicator}(type: #{type || 'unknown'}) is not supported." unless valid_type?
52
52
  end
53
53
  rescue ::VirusTotal::Error => _e
54
54
  nil
@@ -28,7 +28,7 @@ module Mihari
28
28
  when "web"
29
29
  web_lookup
30
30
  else
31
- raise TypeError, "#{type} type is not supported." unless valid_type?
31
+ raise InvalidInputError, "#{type} type is not supported." unless valid_type?
32
32
  end
33
33
  end
34
34
 
@@ -4,6 +4,7 @@ module Mihari
4
4
  module Emitters
5
5
  class Base
6
6
  include Configurable
7
+ include Retriable
7
8
 
8
9
  def self.inherited(child)
9
10
  Mihari.emitters << child
@@ -14,6 +15,10 @@ module Mihari
14
15
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
15
16
  end
16
17
 
18
+ def run(**params)
19
+ retry_on_timeout { emit(params) }
20
+ end
21
+
17
22
  def emit(*)
18
23
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
19
24
  end
@@ -2,4 +2,5 @@
2
2
 
3
3
  module Mihari
4
4
  class Error < StandardError; end
5
+ class InvalidInputError < Error; end
5
6
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Retriable
5
+ def retry_on_timeout(times: 3, interval: 10)
6
+ try = 0
7
+ begin
8
+ try += 1
9
+ yield
10
+ rescue Timeout::Error => _e
11
+ sleep interval
12
+ retry if try < times
13
+ raise
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "0.13.0"
4
+ VERSION = "0.13.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mihari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -494,6 +494,7 @@ files:
494
494
  - lib/mihari/notifiers/base.rb
495
495
  - lib/mihari/notifiers/exception_notifier.rb
496
496
  - lib/mihari/notifiers/slack.rb
497
+ - lib/mihari/retriable.rb
497
498
  - lib/mihari/status.rb
498
499
  - lib/mihari/the_hive.rb
499
500
  - lib/mihari/the_hive/alert.rb