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 +4 -4
- data/lib/mihari/actor.rb +1 -1
- data/lib/mihari/analyzers/base.rb +1 -1
- data/lib/mihari/commands/alert.rb +10 -11
- data/lib/mihari/commands/artifact.rb +4 -4
- data/lib/mihari/commands/rule.rb +4 -4
- data/lib/mihari/commands/search.rb +5 -8
- data/lib/mihari/commands/tag.rb +2 -2
- data/lib/mihari/database.rb +1 -1
- data/lib/mihari/emitters/base.rb +1 -1
- data/lib/mihari/enrichers/base.rb +1 -1
- data/lib/mihari/models/artifact.rb +1 -1
- data/lib/mihari/models/port.rb +1 -1
- data/lib/mihari/rule.rb +4 -4
- data/lib/mihari/service.rb +3 -3
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/endpoints/alerts.rb +3 -3
- data/lib/mihari/web/endpoints/artifacts.rb +2 -2
- data/lib/mihari/web/endpoints/ip_addresses.rb +1 -1
- data/lib/mihari/web/endpoints/rules.rb +4 -4
- data/lib/mihari/web/endpoints/tags.rb +1 -1
- data/lib/mihari/web/public/assets/index-BfEMNMrz.js +1586 -0
- data/lib/mihari/web/public/index.html +2 -2
- data/lib/mihari/web/public/redoc-static.html +15 -15
- data/mihari.gemspec +24 -23
- data/requirements.txt +2 -2
- metadata +62 -48
- data/lib/mihari/web/public/assets/index-HxkDEHGe.js +0 -1577
- /data/lib/mihari/web/public/assets/{index-BgJUBUyh.css → index-oiGfMI5B.css} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29091282748973618fb309a3584d0e24ea27f7e18f284feeb57dbb0f10138f33
|
4
|
+
data.tar.gz: c8079484f9241000479f543785c7d97f892b9a182401047ecf752090fe5bf37b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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(...)
|
@@ -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.
|
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
|
-
|
37
|
-
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
94
|
+
Services::ArtifactDestroyer.call id
|
95
95
|
end
|
96
96
|
end
|
97
97
|
end
|
data/lib/mihari/commands/rule.rb
CHANGED
@@ -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.
|
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
|
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.
|
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.
|
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::
|
28
|
-
|
29
|
-
|
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
|
-
|
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
|
data/lib/mihari/commands/tag.rb
CHANGED
@@ -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.
|
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.
|
74
|
+
Services::TagDestroyer.call id
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
data/lib/mihari/database.rb
CHANGED
@@ -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[
|
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
|
data/lib/mihari/emitters/base.rb
CHANGED
@@ -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.
|
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
|
data/lib/mihari/models/port.rb
CHANGED
@@ -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.
|
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.
|
195
|
-
out << Parallel.map(parallel_emitters) { |emitter| emitter.
|
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, &:
|
353
|
-
out << serial_analyzers.map(&:
|
352
|
+
out << Parallel.map(parallel_analyzers, &:get_result)
|
353
|
+
out << serial_analyzers.map(&:get_result)
|
354
354
|
end.flatten
|
355
355
|
end
|
356
356
|
|
data/lib/mihari/service.rb
CHANGED
@@ -11,7 +11,7 @@ module Mihari
|
|
11
11
|
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
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
|
24
|
-
new.
|
23
|
+
def get_result(...)
|
24
|
+
new.get_result(...)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
data/lib/mihari/version.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
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.
|
101
|
+
result = Services::ArtifactDestroyer.get_result(id)
|
102
102
|
return if result.success?
|
103
103
|
|
104
104
|
case result.failure
|
@@ -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.
|
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.
|
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.
|
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.
|
181
|
+
result = Services::RuleDestroyer.get_result(id)
|
182
182
|
return if result.success?
|
183
183
|
|
184
184
|
case result.failure
|