mihari 7.6.4 → 8.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12856ce5fee6e623a5579cab99a03629c611db1f65e087b04167cae69f870647
4
- data.tar.gz: 28577ad798c7033ead6aaeced545a9401f17d0a31d29551950c3be583bc107ea
3
+ metadata.gz: 29091282748973618fb309a3584d0e24ea27f7e18f284feeb57dbb0f10138f33
4
+ data.tar.gz: c8079484f9241000479f543785c7d97f892b9a182401047ecf752090fe5bf37b
5
5
  SHA512:
6
- metadata.gz: 68d780eca473d2b081c3c9bb7a60c9c5bfa371a0c6e08a307ceaa3138f5097b70606902e657aab22d1013a5033904bd7135595812d76a0554bde38f3b75917b6
7
- data.tar.gz: 6b0ab8b458109b4c496298560772bd44e845a96c97ab89ec3191416855a66c4de92277d66d63607b17a857d35be10343adbdd71183616f64e7b984b617cde32a
6
+ metadata.gz: 4892f605f6dc1169ca22859eb6ddac36b42828575790c2cd7f6ecdf73a158bbdd80704f3c1a0fcba2fd1af3972270131c7df7e657ee30e9cdc7675bbb0aaca3c
7
+ data.tar.gz: 9fdd385288a708f900518c348a8a7ba2b0fd2ac7c0fb81e51c0b71a6e6b313fa8df87e8829539db52ecfc267481229bf2daee21c6bac3ab9ad313a7ee5c2451b
data/lib/mihari/actor.rb CHANGED
@@ -63,7 +63,7 @@ module Mihari
63
63
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
64
64
  end
65
65
 
66
- def result(...)
66
+ def get_result(...)
67
67
  Try[StandardError] do
68
68
  retry_on_error(times: retry_times, interval: retry_interval, exponential_backoff: retry_exponential_backoff) do
69
69
  call(...)
@@ -77,7 +77,7 @@ module Mihari
77
77
  normalized_artifacts
78
78
  end
79
79
 
80
- def result(...)
80
+ def get_result(...)
81
81
  result = Try[StandardError] do
82
82
  retry_on_error(
83
83
  times: retry_times,
@@ -22,7 +22,7 @@ module Mihari
22
22
  #
23
23
  def _search(q, page: 1, limit: 10)
24
24
  filter = Structs::Filters::Search.new(q:, page:, limit:)
25
- Services::AlertSearcher.result(filter).value!
25
+ Services::AlertSearcher.call filter
26
26
  end
27
27
  end
28
28
 
@@ -33,15 +33,14 @@ module Mihari
33
33
  #
34
34
  def create(path)
35
35
  # @type [Mihari::Models::Alert]
36
- alert = Dry::Monads::Try[StandardError] do
37
- raise ArgumentError, "#{path} not found" unless Pathname(path).exist?
36
+ raise ArgumentError, "#{path} not found" unless Pathname(path).exist?
37
+
38
+ params = YAML.safe_load(
39
+ ERB.new(File.read(path)).result,
40
+ permitted_classes: [Date, Symbol]
41
+ )
42
+ alert = Services::AlertCreator.call(params)
38
43
 
39
- params = YAML.safe_load(
40
- ERB.new(File.read(path)).result,
41
- permitted_classes: [Date, Symbol]
42
- )
43
- Services::AlertCreator.call params
44
- end.value!
45
44
  data = Entities::Alert.represent(alert)
46
45
  puts JSON.pretty_generate(data.as_json)
47
46
  end
@@ -92,7 +91,7 @@ module Mihari
92
91
  # @param [Integer] id
93
92
  #
94
93
  def get(id)
95
- value = Services::AlertGetter.result(id).value!
94
+ value = Services::AlertGetter.get_result(id).value!
96
95
  data = Entities::Alert.represent(value)
97
96
  puts JSON.pretty_generate(data.as_json)
98
97
  end
@@ -103,7 +102,7 @@ module Mihari
103
102
  # @param [Integer] id
104
103
  #
105
104
  def delete(id)
106
- Services::AlertDestroyer.result(id).value!
105
+ Services::AlertDestroyer.call id
107
106
  end
108
107
  end
109
108
  end
@@ -21,7 +21,7 @@ module Mihari
21
21
  #
22
22
  def _search(q, page: 1, limit: 10)
23
23
  filter = Structs::Filters::Search.new(q:, page:, limit:)
24
- Services::ArtifactSearcher.result(filter).value!
24
+ Services::ArtifactSearcher.call filter
25
25
  end
26
26
  end
27
27
 
@@ -71,7 +71,7 @@ module Mihari
71
71
  # @param [Integer] id
72
72
  #
73
73
  def get(id)
74
- value = Services::ArtifactGetter.result(id).value!
74
+ value = Services::ArtifactGetter.get_result(id).value!
75
75
  data = Entities::Artifact.represent(value)
76
76
  puts JSON.pretty_generate(data.as_json)
77
77
  end
@@ -82,7 +82,7 @@ module Mihari
82
82
  # @param [Integer] id
83
83
  #
84
84
  def enrich(id)
85
- Services::ArtifactEnricher.result(id).value!
85
+ Services::ArtifactEnricher.call id
86
86
  end
87
87
 
88
88
  desc "delete ID", "Delete an artifact"
@@ -91,7 +91,7 @@ module Mihari
91
91
  # @param [Integer] id
92
92
  #
93
93
  def delete(id)
94
- Services::ArtifactDestroyer.result(id).value!
94
+ Services::ArtifactDestroyer.call id
95
95
  end
96
96
  end
97
97
  end
@@ -22,7 +22,7 @@ module Mihari
22
22
  #
23
23
  def _search(q, page: 1, limit: 10)
24
24
  filter = Structs::Filters::Search.new(q:, page:, limit:)
25
- Services::RuleSearcher.result(filter).value!
25
+ Services::RuleSearcher.call filter
26
26
  end
27
27
  end
28
28
 
@@ -70,7 +70,7 @@ module Mihari
70
70
  warning = "Do you want to overwrite it? (y/n)"
71
71
  return if Pathname(path).exist? && !(yes? warning)
72
72
 
73
- Services::RuleInitializer.call(path)
73
+ Services::RuleInitializer.call path
74
74
  end
75
75
 
76
76
  desc "list QUERY", "List/search rules"
@@ -116,7 +116,7 @@ module Mihari
116
116
  desc "get ID", "Get a rule"
117
117
  around :with_db_connection
118
118
  def get(id)
119
- value = Services::RuleGetter.result(id).value!
119
+ value = Services::RuleGetter.get_result(id).value!
120
120
  data = Entities::Rule.represent(value)
121
121
  puts JSON.pretty_generate(data.as_json)
122
122
  end
@@ -127,7 +127,7 @@ module Mihari
127
127
  # @param [String] id
128
128
  #
129
129
  def delete(id)
130
- Services::RuleDestroyer.result(id).value!
130
+ Services::RuleDestroyer.call id
131
131
  end
132
132
  end
133
133
  end
@@ -24,16 +24,13 @@ module Mihari
24
24
  force_overwrite = options["force_overwrite"] || false
25
25
  message = "Are you sure you want to overwrite this rule? (y/n)"
26
26
 
27
- # @type [Mihari::Models::Alert]
28
- alert = Dry::Monads::Try[StandardError] do
29
- # @type [Mihari::Rule]
30
- rule = Services::RuleBuilder.call(path_or_id)
27
+ # @type [Mihari::Rule]
28
+ rule = Services::RuleBuilder.call(path_or_id)
29
+ exit 0 if rule.diff? && !force_overwrite && !yes?(message)
31
30
 
32
- exit 0 if rule.diff? && !force_overwrite && !yes?(message)
31
+ rule.update_or_create
32
+ alert = rule.call
33
33
 
34
- rule.update_or_create
35
- rule.call
36
- end.value!
37
34
  data = Entities::Alert.represent(alert)
38
35
  puts JSON.pretty_generate(data.as_json)
39
36
  end
@@ -21,7 +21,7 @@ module Mihari
21
21
  #
22
22
  def _search(q, page: 1, limit: 10)
23
23
  filter = Structs::Filters::Search.new(q:, page:, limit:)
24
- Services::TagSearcher.result(filter).value!
24
+ Services::TagSearcher.call filter
25
25
  end
26
26
  end
27
27
 
@@ -71,7 +71,7 @@ module Mihari
71
71
  # @param [Integer] id
72
72
  #
73
73
  def delete(id)
74
- Services::TagDestroyer.result(id).value!
74
+ Services::TagDestroyer.call id
75
75
  end
76
76
  end
77
77
  end
@@ -6,7 +6,7 @@ ActiveSupport::Inflector.inflections(:en) { |inflect| inflect.acronym "CPE" }
6
6
  #
7
7
  # Mihari v7 DB schema
8
8
  #
9
- class V7Schema < ActiveRecord::Migration[7.2]
9
+ class V7Schema < ActiveRecord::Migration[8.0]
10
10
  def change
11
11
  create_table :rules, id: :string, if_not_exists: true do |t|
12
12
  t.string :title, null: false
@@ -44,7 +44,7 @@ module Mihari
44
44
  #
45
45
  # @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
46
46
  #
47
- def result(artifacts)
47
+ def get_result(artifacts)
48
48
  result = Try[StandardError] do
49
49
  retry_on_error(
50
50
  times: retry_times,
@@ -29,7 +29,7 @@ module Mihari
29
29
  #
30
30
  # @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
31
31
  #
32
- def result(artifact)
32
+ def get_result(artifact)
33
33
  return unless callable?(artifact)
34
34
 
35
35
  result = Try[StandardError] do
@@ -191,7 +191,7 @@ module Mihari
191
191
  # NOTE: doing parallel with ActiveRecord objects is troublesome (e.g. connection issue, etc.)
192
192
  # so converting the object to an OpenStruct object
193
193
  s = struct
194
- results = Parallel.map(enrichers) { |enricher| enricher.result s }
194
+ results = Parallel.map(enrichers) { |enricher| enricher.get_result s }
195
195
  enriched = results.compact.map { |result| result.value_or(nil) }.compact
196
196
 
197
197
  self.dns_records = enriched.map(&:dns_records).flatten.compact
@@ -18,7 +18,7 @@ module Mihari
18
18
  # @return [Array<Mihari::Port>]
19
19
  #
20
20
  def build_by_ip(ip, enricher: Enrichers::Shodan.new)
21
- enricher.result(ip).fmap do |res|
21
+ enricher.get_result(ip).fmap do |res|
22
22
  (res&.ports || []).map { |port| new(port:) }
23
23
  end.value_or []
24
24
  end
data/lib/mihari/rule.rb CHANGED
@@ -191,8 +191,8 @@ module Mihari
191
191
  return [] if enriched_artifacts.empty?
192
192
 
193
193
  [].tap do |out|
194
- out << serial_emitters.map { |emitter| emitter.result(enriched_artifacts).value_or(nil) }
195
- out << Parallel.map(parallel_emitters) { |emitter| emitter.result(enriched_artifacts).value_or(nil) }
194
+ out << serial_emitters.map { |emitter| emitter.get_result(enriched_artifacts).value_or(nil) }
195
+ out << Parallel.map(parallel_emitters) { |emitter| emitter.get_result(enriched_artifacts).value_or(nil) }
196
196
  end.flatten.compact
197
197
  end
198
198
 
@@ -349,8 +349,8 @@ module Mihari
349
349
  # @return [Array<Dry::Monads::Result::Success<Array<Mihari::Models::Artifact>>, Dry::Monads::Result::Failure>]
350
350
  def analyzer_results
351
351
  [].tap do |out|
352
- out << Parallel.map(parallel_analyzers, &:result)
353
- out << serial_analyzers.map(&:result)
352
+ out << Parallel.map(parallel_analyzers, &:get_result)
353
+ out << serial_analyzers.map(&:get_result)
354
354
  end.flatten
355
355
  end
356
356
 
@@ -11,7 +11,7 @@ module Mihari
11
11
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
12
12
  end
13
13
 
14
- def result(...)
14
+ def get_result(...)
15
15
  Try[StandardError] { call(...) }.to_result
16
16
  end
17
17
 
@@ -20,8 +20,8 @@ module Mihari
20
20
  new.call(...)
21
21
  end
22
22
 
23
- def result(...)
24
- new.result(...)
23
+ def get_result(...)
24
+ new.get_result(...)
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "7.6.4"
4
+ VERSION = "8.0.1"
5
5
  end
@@ -41,7 +41,7 @@ module Mihari
41
41
  end
42
42
  get "/:id" do
43
43
  id = params[:id].to_i
44
- result = Services::AlertGetter.result(id)
44
+ result = Services::AlertGetter.get_result(id)
45
45
  return present(result.value!, with: Entities::Alert) if result.success?
46
46
 
47
47
  case result.failure
@@ -61,7 +61,7 @@ module Mihari
61
61
  end
62
62
  delete "/:id" do
63
63
  id = params["id"].to_i
64
- result = Services::AlertDestroyer.result(id)
64
+ result = Services::AlertDestroyer.get_result(id)
65
65
  return if result.success?
66
66
 
67
67
  case result.failure
@@ -86,7 +86,7 @@ module Mihari
86
86
  post "/" do
87
87
  status 201
88
88
 
89
- result = Services::AlertCreator.result(params)
89
+ result = Services::AlertCreator.get_result(params)
90
90
  return present(result.value!, with: Entities::Alert) if result.success?
91
91
 
92
92
  case result.failure
@@ -41,7 +41,7 @@ module Mihari
41
41
  end
42
42
  get "/:id" do
43
43
  id = params[:id].to_i
44
- result = Services::ArtifactGetter.result(id)
44
+ result = Services::ArtifactGetter.get_result(id)
45
45
  return present(result.value!, with: Entities::Artifact) if result.success?
46
46
 
47
47
  case result.failure
@@ -98,7 +98,7 @@ module Mihari
98
98
  status 204
99
99
 
100
100
  id = params["id"].to_i
101
- result = Services::ArtifactDestroyer.result(id)
101
+ result = Services::ArtifactDestroyer.get_result(id)
102
102
  return if result.success?
103
103
 
104
104
  case result.failure
@@ -21,7 +21,7 @@ module Mihari
21
21
  end
22
22
  get "/:ip", requirements: {ip: %r{[^/]+}} do
23
23
  ip = params[:ip].to_s
24
- result = Services::IPGetter.result(ip)
24
+ result = Services::IPGetter.get_result(ip)
25
25
  if result.success?
26
26
  value = result.value!
27
27
  return present(
@@ -59,7 +59,7 @@ module Mihari
59
59
  end
60
60
  get "/:id" do
61
61
  id = params[:id].to_s
62
- result = Services::RuleGetter.result(params[:id].to_s)
62
+ result = Services::RuleGetter.get_result(params[:id].to_s)
63
63
  return present(result.value!, with: Entities::Rule) if result.success?
64
64
 
65
65
  case result.failure
@@ -120,7 +120,7 @@ module Mihari
120
120
 
121
121
  yaml = params[:yaml].to_s
122
122
 
123
- result = RuleCreateUpdater.result(yaml, overwrite: false)
123
+ result = RuleCreateUpdater.get_result(yaml, overwrite: false)
124
124
  return present(result.value!.model, with: Entities::Rule) if result.success?
125
125
 
126
126
  failure = result.failure
@@ -151,7 +151,7 @@ module Mihari
151
151
 
152
152
  yaml = params[:yaml].to_s
153
153
 
154
- result = RuleCreateUpdater.result(yaml, overwrite: true)
154
+ result = RuleCreateUpdater.get_result(yaml, overwrite: true)
155
155
  return present(result.value!.model, with: Entities::Rule) if result.success?
156
156
 
157
157
  failure = result.failure
@@ -178,7 +178,7 @@ module Mihari
178
178
  status 204
179
179
 
180
180
  id = params[:id].to_s
181
- result = Services::RuleDestroyer.result(id)
181
+ result = Services::RuleDestroyer.get_result(id)
182
182
  return if result.success?
183
183
 
184
184
  case result.failure
@@ -43,7 +43,7 @@ module Mihari
43
43
  status 204
44
44
 
45
45
  id = params[:id].to_i
46
- result = Services::TagDestroyer.result(id)
46
+ result = Services::TagDestroyer.get_result(id)
47
47
  return if result.success?
48
48
 
49
49
  case result.failure