mihari 7.3.0 → 7.3.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: 328a34edf637c36456cc7de39fccabdaaf75937b449b5e8a8e0434e71b9328c2
4
- data.tar.gz: 8483c669cfb3e715c86b4a3878961885e4cd4f93611e487c4360cb3030267c18
3
+ metadata.gz: ed9b24457d01edc4d1643e6c31c654ad7c13bf71fc849b10bb02276abf45852c
4
+ data.tar.gz: 1be36d2083e0b0209ad16475a8f20eb4d2ee9bfcb37eae43fa76091207526def
5
5
  SHA512:
6
- metadata.gz: 9858608c1ceb30f846a27b487e4bcbbad463aba56a401991fdade512bf6a7a7f028e5facecd764b200d94795a1da1a2b631b85540dfe1bbf002c756100b6627f
7
- data.tar.gz: c050fdafab0e7855eb610ad3d50762583ca931d31afeeb57fc654a2dc65ff381f20cb31eb28d0a61b5888c0a19df02320b09a529830fe332389b59f739721aba
6
+ metadata.gz: 4482938e33386e24054cb215f78f065e3190ba32269872aea6a9f543745a2c71777bb609120dcaa3872dba9b6ebd307651f80239342d6ac9427db205f03c80e0
7
+ data.tar.gz: 5723cbca9f18c519fc4cf91775d751f417a85161add0c0c6d499fd03075c7985c1cb73ef68e24b4913b1d8d3a9652a0e4e1025a32b83c987d3e9e22886923e38
data/lib/mihari/actor.rb CHANGED
@@ -50,13 +50,6 @@ module Mihari
50
50
  options[:timeout]
51
51
  end
52
52
 
53
- #
54
- # @return [Boolean]
55
- #
56
- def parallel?
57
- options[:parallel] || Mihari.config.parallel
58
- end
59
-
60
53
  def validate_configuration!
61
54
  return if configured?
62
55
 
@@ -40,6 +40,13 @@ module Mihari
40
40
  options[:ignore_error] || Mihari.config.ignore_error
41
41
  end
42
42
 
43
+ #
44
+ # @return [Boolean]
45
+ #
46
+ def parallel?
47
+ options[:parallel] || Mihari.config.parallel
48
+ end
49
+
43
50
  # @return [Array<String>, Array<Mihari::Models::Artifact>]
44
51
  def artifacts
45
52
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
@@ -19,6 +19,13 @@ module Mihari
19
19
  @rule = rule
20
20
  end
21
21
 
22
+ #
23
+ # @return [Boolean]
24
+ #
25
+ def parallel?
26
+ options[:parallel] || Mihari.config.parallel
27
+ end
28
+
22
29
  # A target to emit the data
23
30
  #
24
31
  # @return [String]
data/lib/mihari/rule.rb CHANGED
@@ -33,9 +33,9 @@ module Mihari
33
33
  # @return [Boolean]
34
34
  #
35
35
  def errors?
36
- return false if @errors.nil?
36
+ return false if errors.nil?
37
37
 
38
- !@errors.empty?
38
+ !errors.empty?
39
39
  end
40
40
 
41
41
  def [](key)
@@ -163,9 +163,7 @@ module Mihari
163
163
  # @return [Array<Mihari::Models::Artifact>]
164
164
  #
165
165
  def unique_artifacts
166
- normalized_artifacts.select do |artifact|
167
- artifact.unique?(base_time: base_time, artifact_ttl: artifact_ttl)
168
- end
166
+ normalized_artifacts.select { |artifact| artifact.unique?(base_time: base_time, artifact_ttl: artifact_ttl) }
169
167
  end
170
168
 
171
169
  #
@@ -174,11 +172,11 @@ module Mihari
174
172
  # @return [Array<Mihari::Models::Artifact>]
175
173
  #
176
174
  def enriched_artifacts
177
- @enriched_artifacts ||= unique_artifacts.map do |artifact|
178
- serial_enrichers.each { |enricher| enricher.result(artifact) }
179
- Parallel.each(parallel_enrichers) { |enricher| enricher.result(artifact) }
180
-
181
- artifact
175
+ @enriched_artifacts ||= Parallel.map(unique_artifacts) do |artifact|
176
+ artifact.tap do |tapped|
177
+ # NOTE: To apply changes correctly, enrichers should be applied to an artifact serially
178
+ enrichers.each { |enricher| enricher.result(tapped) }
179
+ end
182
180
  end
183
181
  end
184
182
 
@@ -337,9 +335,10 @@ module Mihari
337
335
 
338
336
  # @return [Array<Dry::Monads::Result::Success<Array<Mihari::Models::Artifact>>, Dry::Monads::Result::Failure>]
339
337
  def analyzer_results
340
- parallel_results = Parallel.map(parallel_analyzers, &:result)
341
- serial_results = serial_analyzers.map(&:result)
342
- parallel_results + serial_results
338
+ [].tap do |out|
339
+ out << Parallel.map(parallel_analyzers, &:result)
340
+ out << serial_analyzers.map(&:result)
341
+ end.flatten
343
342
  end
344
343
 
345
344
  #
@@ -404,14 +403,6 @@ module Mihari
404
403
  end
405
404
  end
406
405
 
407
- def parallel_enrichers
408
- enrichers.select(&:parallel?)
409
- end
410
-
411
- def serial_enrichers
412
- enrichers.reject(&:parallel?)
413
- end
414
-
415
406
  #
416
407
  # Validate the data format
417
408
  #
@@ -117,6 +117,6 @@ module Mihari
117
117
  end
118
118
  end
119
119
 
120
- Analyzer = Schemas::Analyzers.get_or_composition
120
+ Analyzer = Schemas::Analyzers.compose_by_or
121
121
  end
122
122
  end
@@ -9,7 +9,7 @@ module Mihari
9
9
  module Orrable
10
10
  extend ActiveSupport::Concern
11
11
 
12
- def get_or_composition
12
+ def compose_by_or
13
13
  schemas = constants.map { |sym| const_get sym }
14
14
  return schemas.first if schemas.length <= 1
15
15
 
@@ -10,28 +10,28 @@ module Mihari
10
10
 
11
11
  Database = Dry::Schema.Params do
12
12
  required(:emitter).value(Types::String.enum(*Mihari::Emitters::Database.keys))
13
- optional(:options).hash(Options)
13
+ optional(:options).hash(EmitterOptions)
14
14
  end
15
15
 
16
16
  MISP = Dry::Schema.Params do
17
17
  required(:emitter).value(Types::String.enum(*Mihari::Emitters::MISP.keys))
18
18
  optional(:url).filled(:string)
19
19
  optional(:api_key).filled(:string)
20
- optional(:options).hash(Options)
20
+ optional(:options).hash(EmitterOptions)
21
21
  end
22
22
 
23
23
  TheHive = Dry::Schema.Params do
24
24
  required(:emitter).value(Types::String.enum(*Mihari::Emitters::TheHive.keys))
25
25
  optional(:url).filled(:string)
26
26
  optional(:api_key).filled(:string)
27
- optional(:options).hash(Options)
27
+ optional(:options).hash(EmitterOptions)
28
28
  end
29
29
 
30
30
  Slack = Dry::Schema.Params do
31
31
  required(:emitter).value(Types::String.enum(*Mihari::Emitters::Slack.keys))
32
32
  optional(:webhook_url).filled(:string)
33
33
  optional(:channel).filled(:string)
34
- optional(:options).hash(Options)
34
+ optional(:options).hash(EmitterOptions)
35
35
  end
36
36
 
37
37
  Webhook = Dry::Schema.Params do
@@ -40,10 +40,10 @@ module Mihari
40
40
  optional(:method).value(Types::HTTPRequestMethods).default("POST")
41
41
  optional(:headers).filled(:hash)
42
42
  optional(:template).filled(:string)
43
- optional(:options).hash(Options)
43
+ optional(:options).hash(EmitterOptions)
44
44
  end
45
45
  end
46
46
 
47
- Emitter = Schemas::Emitters.get_or_composition
47
+ Emitter = Schemas::Emitters.compose_by_or
48
48
  end
49
49
  end
@@ -29,6 +29,6 @@ module Mihari
29
29
  end
30
30
  end
31
31
 
32
- Enricher = Schemas::Enrichers.get_or_composition
32
+ Enricher = Schemas::Enrichers.compose_by_or
33
33
  end
34
34
  end
@@ -3,24 +3,29 @@
3
3
  module Mihari
4
4
  module Schemas
5
5
  Options = Dry::Schema.Params do
6
- optional(:retry_times).value(:integer).default(Mihari.config.retry_times)
7
- optional(:retry_interval).value(:integer).default(Mihari.config.retry_interval)
8
- optional(:retry_exponential_backoff).value(:bool).default(Mihari.config.retry_exponential_backoff)
6
+ optional(:retry_times).value(:integer)
7
+ optional(:retry_interval).value(:integer)
8
+ optional(:retry_exponential_backoff).value(:bool)
9
9
  optional(:timeout).value(:integer)
10
- optional(:parallel).value(:bool).default(Mihari.config.parallel)
11
10
  end
12
11
 
13
- IgnoreErrorOptions = Dry::Schema.Params do
14
- optional(:ignore_error).value(:bool).default(Mihari.config.ignore_error)
12
+ ParallelOptions = Dry::Schema.Params do
13
+ optional(:parallel).value(:bool)
15
14
  end
16
15
 
17
- AnalyzerOptions = Options | IgnoreErrorOptions
16
+ IgnoreErrorOptions = Dry::Schema.Params do
17
+ optional(:ignore_error).value(:bool)
18
+ end
18
19
 
19
20
  PaginationOptions = Dry::Schema.Params do
20
- optional(:pagination_interval).value(:integer).default(Mihari.config.pagination_interval)
21
- optional(:pagination_limit).value(:integer).default(Mihari.config.pagination_limit)
21
+ optional(:pagination_interval).value(:integer)
22
+ optional(:pagination_limit).value(:integer)
22
23
  end
23
24
 
24
- AnalyzerPaginationOptions = AnalyzerOptions | PaginationOptions
25
+ AnalyzerOptions = Options & IgnoreErrorOptions & ParallelOptions
26
+
27
+ AnalyzerPaginationOptions = AnalyzerOptions & PaginationOptions
28
+
29
+ EmitterOptions = Options & ParallelOptions
25
30
  end
26
31
  end
@@ -21,9 +21,9 @@ module Mihari
21
21
  optional(:created_on).value(:date)
22
22
  optional(:updated_on).value(:date)
23
23
 
24
- required(:queries).value(:array).each { Analyzer } # rubocop:disable Lint/Void
25
- optional(:emitters).value(:array).each { Emitter }.default(DEFAULT_EMITTERS) # rubocop:disable Lint/Void
26
- optional(:enrichers).value(:array).each { Enricher }.default(DEFAULT_ENRICHERS) # rubocop:disable Lint/Void
24
+ required(:queries).array { Analyzer }
25
+ optional(:emitters).array { Emitter }.default(DEFAULT_EMITTERS)
26
+ optional(:enrichers).array { Enricher }.default(DEFAULT_ENRICHERS)
27
27
 
28
28
  optional(:data_types).filled(array[Types::DataTypes]).default(Mihari::Types::DataTypes.values)
29
29
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "7.3.0"
4
+ VERSION = "7.3.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: 7.3.0
4
+ version: 7.3.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: 2024-01-20 00:00:00.000000000 Z
11
+ date: 2024-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: better_errors