mihari 8.0.0 → 8.0.2
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 +1 -1
- data/lib/mihari/commands/artifact.rb +1 -1
- data/lib/mihari/commands/rule.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/structs/censys.rb +6 -4
- 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-BO6YgRrl.js +1586 -0
- data/lib/mihari/web/public/assets/index-Dwa66Ymz.css +1 -0
- data/lib/mihari/web/public/index.html +2 -2
- data/mihari.gemspec +24 -23
- data/requirements.txt +2 -2
- metadata +66 -52
- data/lib/mihari/web/public/assets/index-B1FXFQWK.js +0 -1577
- data/lib/mihari/web/public/assets/index-oiGfMI5B.css +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3d454e8ac560ec2d1b7463dfdc686e69fc033da82e318f9479ba14f72194c49
|
4
|
+
data.tar.gz: d2f191e78eb2180a9062d885fd527f5e55c70fa70a5e9f8f910b15a50d57d6a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 723186046c14e4532c3662280264a51fb7a5966173d7010c50d6537a8b96304b6ff7f7f24d9686d1773fe8f13ceaba09d7d33c0265e286b58c9d18f3849645b8
|
7
|
+
data.tar.gz: 8a9f7001f3edb2a4035178c810ff5a12cf2cf913533f853e778c8d15ef4e74edfaef4d1b9061ab406d824406e7abd9eba94adb2e45da6c9b963a5d029123d322
|
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(...)
|
@@ -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
|
data/lib/mihari/commands/rule.rb
CHANGED
@@ -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
|
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
|
@@ -22,6 +22,8 @@ module Mihari
|
|
22
22
|
# @param [Hash] d
|
23
23
|
#
|
24
24
|
def from_dynamic!(d)
|
25
|
+
return nil if d.nil?
|
26
|
+
|
25
27
|
d = Types::Hash[d]
|
26
28
|
new(
|
27
29
|
asn: d.fetch("asn")
|
@@ -102,8 +104,8 @@ module Mihari
|
|
102
104
|
attribute :location, Location
|
103
105
|
|
104
106
|
# @!attribute [r] autonomous_system
|
105
|
-
# @return [AutonomousSystem]
|
106
|
-
attribute :autonomous_system, AutonomousSystem
|
107
|
+
# @return [AutonomousSystem, nil]
|
108
|
+
attribute :autonomous_system, AutonomousSystem.optional
|
107
109
|
|
108
110
|
# @!attribute [r] metadata
|
109
111
|
# @return [Hash]
|
@@ -127,7 +129,7 @@ module Mihari
|
|
127
129
|
Models::Artifact.new(
|
128
130
|
data: ip,
|
129
131
|
metadata:,
|
130
|
-
autonomous_system: autonomous_system
|
132
|
+
autonomous_system: autonomous_system&.as,
|
131
133
|
geolocation: location.geolocation,
|
132
134
|
ports:
|
133
135
|
)
|
@@ -142,7 +144,7 @@ module Mihari
|
|
142
144
|
new(
|
143
145
|
ip: d.fetch("ip"),
|
144
146
|
location: Location.from_dynamic!(d.fetch("location")),
|
145
|
-
autonomous_system: AutonomousSystem.from_dynamic!(d
|
147
|
+
autonomous_system: AutonomousSystem.from_dynamic!(d["autonomous_system"]),
|
146
148
|
metadata: d,
|
147
149
|
services: d.fetch("services", []).map { |x| Service.from_dynamic!(x) }
|
148
150
|
)
|
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
|