mihari 5.6.0 → 5.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/analyzers/binaryedge.md +1 -1
- data/docs/analyzers/censys.md +1 -1
- data/docs/analyzers/circl.md +1 -1
- data/docs/analyzers/crtsh.md +1 -1
- data/docs/analyzers/dnstwister.md +1 -1
- data/docs/analyzers/greynoise.md +1 -1
- data/docs/analyzers/hunterhow.md +1 -1
- data/docs/analyzers/index.md +29 -15
- data/docs/analyzers/onyphe.md +1 -1
- data/docs/analyzers/otx.md +2 -2
- data/docs/analyzers/passivetotal.md +2 -2
- data/docs/analyzers/pulsedive.md +2 -2
- data/docs/analyzers/securitytrails.md +2 -2
- data/docs/analyzers/shodan.md +1 -1
- data/docs/analyzers/urlscan.md +3 -3
- data/docs/analyzers/virustotal.md +2 -2
- data/docs/analyzers/virustotal_intelligence.md +4 -4
- data/docs/analyzers/zoomeye.md +5 -0
- data/docs/enrichers/google_public_dns.md +1 -1
- data/docs/enrichers/ipinfo.md +2 -2
- data/docs/enrichers/shodan.md +4 -4
- data/docs/enrichers/whois.md +1 -1
- data/frontend/package-lock.json +176 -179
- data/frontend/package.json +9 -9
- data/lib/mihari/{base.rb → actor.rb} +16 -2
- data/lib/mihari/analyzers/base.rb +5 -10
- data/lib/mihari/analyzers/censys.rb +1 -1
- data/lib/mihari/analyzers/circl.rb +1 -1
- data/lib/mihari/analyzers/crtsh.rb +1 -1
- data/lib/mihari/analyzers/dnstwister.rb +1 -1
- data/lib/mihari/analyzers/hunterhow.rb +1 -1
- data/lib/mihari/analyzers/otx.rb +1 -1
- data/lib/mihari/analyzers/passivetotal.rb +2 -2
- data/lib/mihari/analyzers/pulsedive.rb +2 -2
- data/lib/mihari/analyzers/securitytrails.rb +2 -2
- data/lib/mihari/analyzers/urlscan.rb +1 -1
- data/lib/mihari/analyzers/virustotal.rb +5 -5
- data/lib/mihari/analyzers/zoomeye.rb +3 -3
- data/lib/mihari/clients/base.rb +2 -2
- data/lib/mihari/clients/binaryedge.rb +3 -5
- data/lib/mihari/clients/censys.rb +3 -3
- data/lib/mihari/clients/circl.rb +5 -4
- data/lib/mihari/clients/crtsh.rb +5 -4
- data/lib/mihari/clients/dnstwister.rb +3 -2
- data/lib/mihari/clients/greynoise.rb +2 -2
- data/lib/mihari/clients/hunterhow.rb +2 -2
- data/lib/mihari/clients/misp.rb +1 -1
- data/lib/mihari/clients/onyphe.rb +2 -2
- data/lib/mihari/clients/otx.rb +4 -3
- data/lib/mihari/clients/passivetotal.rb +9 -8
- data/lib/mihari/clients/publsedive.rb +4 -3
- data/lib/mihari/clients/securitytrails.rb +8 -6
- data/lib/mihari/clients/shodan.rb +2 -2
- data/lib/mihari/clients/the_hive.rb +1 -1
- data/lib/mihari/clients/urlscan.rb +4 -4
- data/lib/mihari/clients/virustotal.rb +2 -2
- data/lib/mihari/clients/zoomeye.rb +2 -2
- data/lib/mihari/commands/rule.rb +2 -11
- data/lib/mihari/commands/search.rb +1 -1
- data/lib/mihari/emitters/base.rb +13 -24
- data/lib/mihari/emitters/database.rb +7 -9
- data/lib/mihari/emitters/misp.rb +14 -38
- data/lib/mihari/emitters/slack.rb +14 -11
- data/lib/mihari/emitters/the_hive.rb +16 -44
- data/lib/mihari/emitters/webhook.rb +31 -21
- data/lib/mihari/enrichers/base.rb +1 -6
- data/lib/mihari/enrichers/whois.rb +1 -1
- data/lib/mihari/models/alert.rb +75 -73
- data/lib/mihari/models/artifact.rb +182 -180
- data/lib/mihari/models/autonomous_system.rb +22 -20
- data/lib/mihari/models/cpe.rb +21 -19
- data/lib/mihari/models/dns.rb +24 -22
- data/lib/mihari/models/geolocation.rb +22 -20
- data/lib/mihari/models/port.rb +21 -19
- data/lib/mihari/models/reverse_dns.rb +21 -19
- data/lib/mihari/models/rule.rb +67 -65
- data/lib/mihari/models/tag.rb +5 -3
- data/lib/mihari/models/tagging.rb +5 -3
- data/lib/mihari/models/whois.rb +18 -16
- data/lib/mihari/rule.rb +352 -0
- data/lib/mihari/schemas/analyzer.rb +94 -87
- data/lib/mihari/schemas/emitter.rb +9 -5
- data/lib/mihari/schemas/enricher.rb +8 -4
- data/lib/mihari/schemas/mixins.rb +15 -0
- data/lib/mihari/schemas/rule.rb +3 -10
- data/lib/mihari/services/alert_builder.rb +1 -1
- data/lib/mihari/services/alert_proxy.rb +10 -6
- data/lib/mihari/services/alert_runner.rb +4 -4
- data/lib/mihari/services/rule_builder.rb +3 -3
- data/lib/mihari/services/rule_runner.rb +5 -5
- data/lib/mihari/structs/binaryedge.rb +1 -1
- data/lib/mihari/structs/censys.rb +6 -6
- data/lib/mihari/structs/config.rb +1 -1
- data/lib/mihari/structs/greynoise.rb +5 -5
- data/lib/mihari/structs/hunterhow.rb +3 -3
- data/lib/mihari/structs/onyphe.rb +5 -5
- data/lib/mihari/structs/shodan.rb +6 -6
- data/lib/mihari/structs/urlscan.rb +3 -3
- data/lib/mihari/structs/virustotal_intelligence.rb +3 -3
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/endpoints/alerts.rb +4 -4
- data/lib/mihari/web/endpoints/artifacts.rb +6 -6
- data/lib/mihari/web/endpoints/rules.rb +10 -17
- data/lib/mihari/web/endpoints/tags.rb +2 -2
- data/lib/mihari/web/public/assets/{index-9cc489e6.js → index-28d4c79d.js} +48 -48
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari.rb +6 -8
- data/mihari.gemspec +1 -2
- data/mkdocs.yml +0 -3
- data/requirements.txt +1 -1
- metadata +8 -22
- data/lib/mihari/analyzers/rule.rb +0 -232
- data/lib/mihari/services/rule_proxy.rb +0 -182
@@ -16,7 +16,7 @@ module Mihari
|
|
16
16
|
#
|
17
17
|
# @param [Hash] data
|
18
18
|
#
|
19
|
-
def initialize(data)
|
19
|
+
def initialize(**data)
|
20
20
|
@data = data.deep_symbolize_keys
|
21
21
|
@errors = nil
|
22
22
|
|
@@ -54,21 +54,24 @@ module Mihari
|
|
54
54
|
end
|
55
55
|
|
56
56
|
#
|
57
|
-
# @return [Array<Mihari::Artifact>]
|
57
|
+
# @return [Array<Mihari::Models::Artifact>]
|
58
58
|
#
|
59
59
|
def artifacts
|
60
60
|
@artifacts ||= data[:artifacts].map do |data|
|
61
|
-
artifact = Artifact.new(data: data)
|
61
|
+
artifact = Models::Artifact.new(data: data)
|
62
62
|
artifact.rule_id = rule_id
|
63
63
|
artifact
|
64
64
|
end.uniq(&:data).select(&:valid?)
|
65
65
|
end
|
66
66
|
|
67
67
|
#
|
68
|
-
# @return [Mihari::
|
68
|
+
# @return [Mihari::Rule]
|
69
69
|
#
|
70
70
|
def rule
|
71
|
-
@rule ||=
|
71
|
+
@rule ||= [].tap do |out|
|
72
|
+
data = Mihari::Models::Rule.find(rule_id).data
|
73
|
+
out << Rule.new(**data)
|
74
|
+
end.first
|
72
75
|
end
|
73
76
|
|
74
77
|
class << self
|
@@ -80,7 +83,8 @@ module Mihari
|
|
80
83
|
# @return [Mihari::Services::Alert]
|
81
84
|
#
|
82
85
|
def from_yaml(yaml)
|
83
|
-
|
86
|
+
data = YAML.safe_load(yaml, permitted_classes: [Date, Symbol])
|
87
|
+
new(**data)
|
84
88
|
end
|
85
89
|
end
|
86
90
|
end
|
@@ -13,15 +13,15 @@ module Mihari
|
|
13
13
|
end
|
14
14
|
|
15
15
|
#
|
16
|
-
# @return [Mihari::Alert]
|
16
|
+
# @return [Mihari::Models::Alert]
|
17
17
|
#
|
18
18
|
def run
|
19
|
-
emitter = Emitters::Database.new(
|
20
|
-
emitter.emit
|
19
|
+
emitter = Emitters::Database.new(rule: alert.rule)
|
20
|
+
emitter.emit alert.artifacts
|
21
21
|
end
|
22
22
|
|
23
23
|
#
|
24
|
-
# @return [Dry::Monads::Result::Success<Mihari::Alert, nil>, Dry::Monads::Result::Failure]
|
24
|
+
# @return [Dry::Monads::Result::Success<Mihari::Models::Alert, nil>, Dry::Monads::Result::Failure]
|
25
25
|
#
|
26
26
|
def result
|
27
27
|
Try[StandardError] { run }.to_result
|
@@ -26,8 +26,8 @@ module Mihari
|
|
26
26
|
# @return [Hash]
|
27
27
|
#
|
28
28
|
def data
|
29
|
-
if Mihari::Rule.exists?(path_or_id)
|
30
|
-
rule = Mihari::Rule.find(path_or_id)
|
29
|
+
if Mihari::Models::Rule.exists?(path_or_id)
|
30
|
+
rule = Mihari::Models::Rule.find(path_or_id)
|
31
31
|
return rule.data
|
32
32
|
end
|
33
33
|
|
@@ -40,7 +40,7 @@ module Mihari
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def result
|
43
|
-
Try[StandardError] {
|
43
|
+
Try[StandardError] { Rule.new(**data) }.to_result
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -5,7 +5,7 @@ module Mihari
|
|
5
5
|
class RuleRunner
|
6
6
|
include Dry::Monads[:result, :try]
|
7
7
|
|
8
|
-
# @return [Mihari::
|
8
|
+
# @return [Mihari::Rule]
|
9
9
|
attr_reader :rule
|
10
10
|
|
11
11
|
def initialize(rule)
|
@@ -16,7 +16,7 @@ module Mihari
|
|
16
16
|
# @return [Boolean]
|
17
17
|
#
|
18
18
|
def diff?
|
19
|
-
model = Mihari::Rule.find(rule.id)
|
19
|
+
model = Mihari::Models::Rule.find(rule.id)
|
20
20
|
model.data != rule.data.deep_stringify_keys
|
21
21
|
rescue ActiveRecord::RecordNotFound
|
22
22
|
false
|
@@ -27,14 +27,14 @@ module Mihari
|
|
27
27
|
end
|
28
28
|
|
29
29
|
#
|
30
|
-
# @return [Mihari::Alert, nil]
|
30
|
+
# @return [Mihari::Models::Alert, nil]
|
31
31
|
#
|
32
32
|
def run
|
33
|
-
rule.
|
33
|
+
rule.run
|
34
34
|
end
|
35
35
|
|
36
36
|
#
|
37
|
-
# @return [Dry::Monads::Result::Success<Mihari::Alert, nil>, Dry::Monads::Result::Failure]
|
37
|
+
# @return [Dry::Monads::Result::Success<Mihari::Models::Alert, nil>, Dry::Monads::Result::Failure]
|
38
38
|
#
|
39
39
|
def result
|
40
40
|
Try[StandardError] { run }.to_result
|
@@ -19,7 +19,7 @@ module Mihari
|
|
19
19
|
# @return [Mihari::AutonomousSystem]
|
20
20
|
#
|
21
21
|
def as
|
22
|
-
Mihari::AutonomousSystem.new(asn: normalize_asn(asn))
|
22
|
+
Mihari::Models::AutonomousSystem.new(asn: normalize_asn(asn))
|
23
23
|
end
|
24
24
|
|
25
25
|
class << self
|
@@ -63,7 +63,7 @@ module Mihari
|
|
63
63
|
# then set geolocation as nil
|
64
64
|
return nil if country.nil?
|
65
65
|
|
66
|
-
Mihari::Geolocation.new(
|
66
|
+
Mihari::Models::Geolocation.new(
|
67
67
|
country: country,
|
68
68
|
country_code: country_code
|
69
69
|
)
|
@@ -99,7 +99,7 @@ module Mihari
|
|
99
99
|
# @return [Mihari::Port]
|
100
100
|
#
|
101
101
|
def _port
|
102
|
-
Port.new(port: port)
|
102
|
+
Models::Port.new(port: port)
|
103
103
|
end
|
104
104
|
|
105
105
|
class << self
|
@@ -167,10 +167,10 @@ module Mihari
|
|
167
167
|
end
|
168
168
|
|
169
169
|
#
|
170
|
-
# @return [Mihari::Artifact]
|
170
|
+
# @return [Mihari::Models::Artifact]
|
171
171
|
#
|
172
172
|
def artifact
|
173
|
-
Artifact.new(
|
173
|
+
Models::Artifact.new(
|
174
174
|
data: ip,
|
175
175
|
metadata: metadata,
|
176
176
|
autonomous_system: autonomous_system.as,
|
@@ -267,7 +267,7 @@ module Mihari
|
|
267
267
|
end
|
268
268
|
|
269
269
|
#
|
270
|
-
# @return [Array<Mihari::Artifact>]
|
270
|
+
# @return [Array<Mihari::Models::Artifact>]
|
271
271
|
#
|
272
272
|
def artifacts
|
273
273
|
hits.map(&:artifact)
|
@@ -35,14 +35,14 @@ module Mihari
|
|
35
35
|
# @return [Mihari::AutonomousSystem]
|
36
36
|
#
|
37
37
|
def as
|
38
|
-
Mihari::AutonomousSystem.new(asn: normalize_asn(asn))
|
38
|
+
Mihari::Models::AutonomousSystem.new(asn: normalize_asn(asn))
|
39
39
|
end
|
40
40
|
|
41
41
|
#
|
42
42
|
# @return [Mihari::Geolocation]
|
43
43
|
#
|
44
44
|
def geolocation
|
45
|
-
Mihari::Geolocation.new(
|
45
|
+
Mihari::Models::Geolocation.new(
|
46
46
|
country: country,
|
47
47
|
country_code: country_code
|
48
48
|
)
|
@@ -92,10 +92,10 @@ module Mihari
|
|
92
92
|
end
|
93
93
|
|
94
94
|
#
|
95
|
-
# @return [Mihari::Artifact]
|
95
|
+
# @return [Mihari::Models::Artifact]
|
96
96
|
#
|
97
97
|
def artifact
|
98
|
-
Mihari::Artifact.new(
|
98
|
+
Mihari::Models::Artifact.new(
|
99
99
|
data: ip,
|
100
100
|
metadata: metadata_,
|
101
101
|
autonomous_system: metadata.as,
|
@@ -171,7 +171,7 @@ module Mihari
|
|
171
171
|
end
|
172
172
|
|
173
173
|
#
|
174
|
-
# @return [Array<Mihari::Artifact>]
|
174
|
+
# @return [Array<Mihari::Models::Artifact>]
|
175
175
|
#
|
176
176
|
def artifacts
|
177
177
|
data.map(&:artifact)
|
@@ -14,10 +14,10 @@ module Mihari
|
|
14
14
|
end
|
15
15
|
|
16
16
|
#
|
17
|
-
# @return [Mihari::Artifact]
|
17
|
+
# @return [Mihari::Models::Artifact]
|
18
18
|
#
|
19
19
|
def artifact
|
20
|
-
Artifact.new(data: ip)
|
20
|
+
Models::Artifact.new(data: ip)
|
21
21
|
end
|
22
22
|
|
23
23
|
class << self
|
@@ -49,7 +49,7 @@ module Mihari
|
|
49
49
|
end
|
50
50
|
|
51
51
|
#
|
52
|
-
# @return [Array<Mihari::Artifact>]
|
52
|
+
# @return [Array<Mihari::Models::Artifact>]
|
53
53
|
#
|
54
54
|
def artifacts
|
55
55
|
list.map(&:artifact)
|
@@ -40,10 +40,10 @@ module Mihari
|
|
40
40
|
end
|
41
41
|
|
42
42
|
#
|
43
|
-
# @return [Mihari::Artifact]
|
43
|
+
# @return [Mihari::Models::Artifact]
|
44
44
|
#
|
45
45
|
def artifact
|
46
|
-
Mihari::Artifact.new(
|
46
|
+
Mihari::Models::Artifact.new(
|
47
47
|
data: ip,
|
48
48
|
metadata: metadata,
|
49
49
|
autonomous_system: as,
|
@@ -57,7 +57,7 @@ module Mihari
|
|
57
57
|
def geolocation
|
58
58
|
return nil if country_code.nil?
|
59
59
|
|
60
|
-
Mihari::Geolocation.new(
|
60
|
+
Mihari::Models::Geolocation.new(
|
61
61
|
country: NormalizeCountry(country_code, to: :short),
|
62
62
|
country_code: country_code
|
63
63
|
)
|
@@ -67,7 +67,7 @@ module Mihari
|
|
67
67
|
# @return [Mihari::AutonomousSystem]
|
68
68
|
#
|
69
69
|
def as
|
70
|
-
Mihari::AutonomousSystem.new(asn: normalize_asn(asn))
|
70
|
+
Mihari::Models::AutonomousSystem.new(asn: normalize_asn(asn))
|
71
71
|
end
|
72
72
|
|
73
73
|
class << self
|
@@ -148,7 +148,7 @@ module Mihari
|
|
148
148
|
end
|
149
149
|
|
150
150
|
#
|
151
|
-
# @return [Array<Mihari::Artifact>]
|
151
|
+
# @return [Array<Mihari::Models::Artifact>]
|
152
152
|
#
|
153
153
|
def artifacts
|
154
154
|
results.map(&:artifact)
|
@@ -27,7 +27,7 @@ module Mihari
|
|
27
27
|
def geolocation
|
28
28
|
return nil if country_name.nil? && country_code.nil?
|
29
29
|
|
30
|
-
Mihari::Geolocation.new(
|
30
|
+
Mihari::Models::Geolocation.new(
|
31
31
|
country: country_name,
|
32
32
|
country_code: country_code
|
33
33
|
)
|
@@ -108,7 +108,7 @@ module Mihari
|
|
108
108
|
def _asn
|
109
109
|
return nil if asn.nil?
|
110
110
|
|
111
|
-
Mihari::AutonomousSystem.new(asn: normalize_asn(asn))
|
111
|
+
Mihari::Models::AutonomousSystem.new(asn: normalize_asn(asn))
|
112
112
|
end
|
113
113
|
|
114
114
|
class << self
|
@@ -192,20 +192,20 @@ module Mihari
|
|
192
192
|
end
|
193
193
|
|
194
194
|
#
|
195
|
-
# @return [Array<Mihari::Artifact>]
|
195
|
+
# @return [Array<Mihari::Models::Artifact>]
|
196
196
|
#
|
197
197
|
def artifacts
|
198
198
|
matches.map do |match|
|
199
199
|
metadata = collect_metadata_by_ip(match.ip_str)
|
200
200
|
|
201
201
|
ports = collect_ports_by_ip(match.ip_str).map do |port|
|
202
|
-
Mihari::Port.new(port: port)
|
202
|
+
Mihari::Models::Port.new(port: port)
|
203
203
|
end
|
204
204
|
reverse_dns_names = collect_hostnames_by_ip(match.ip_str).map do |name|
|
205
|
-
Mihari::ReverseDnsName.new(name: name)
|
205
|
+
Mihari::Models::ReverseDnsName.new(name: name)
|
206
206
|
end
|
207
207
|
|
208
|
-
Mihari::Artifact.new(
|
208
|
+
Mihari::Models::Artifact.new(
|
209
209
|
data: match.ip_str,
|
210
210
|
metadata: metadata,
|
211
211
|
autonomous_system: match._asn,
|
@@ -81,11 +81,11 @@ module Mihari
|
|
81
81
|
end
|
82
82
|
|
83
83
|
#
|
84
|
-
# @return [Array<Mihari::Artifact>]
|
84
|
+
# @return [Array<Mihari::Models::Artifact>]
|
85
85
|
#
|
86
86
|
def artifacts
|
87
87
|
values = [page.url, page.domain, page.ip].compact
|
88
|
-
values.map { |value| Mihari::Artifact.new(data: value, metadata: metadata) }
|
88
|
+
values.map { |value| Mihari::Models::Artifact.new(data: value, metadata: metadata) }
|
89
89
|
end
|
90
90
|
|
91
91
|
class << self
|
@@ -125,7 +125,7 @@ module Mihari
|
|
125
125
|
end
|
126
126
|
|
127
127
|
#
|
128
|
-
# @return [Array<Mihari::Artifact>]
|
128
|
+
# @return [Array<Mihari::Models::Artifact>]
|
129
129
|
#
|
130
130
|
def artifacts
|
131
131
|
results.map(&:artifacts).flatten
|
@@ -77,10 +77,10 @@ module Mihari
|
|
77
77
|
end
|
78
78
|
|
79
79
|
#
|
80
|
-
# @return [Mihari::Artifact]
|
80
|
+
# @return [Mihari::Models::Artifact]
|
81
81
|
#
|
82
82
|
def artifact
|
83
|
-
Artifact.new(data: value, metadata: metadata)
|
83
|
+
Models::Artifact.new(data: value, metadata: metadata)
|
84
84
|
end
|
85
85
|
|
86
86
|
class << self
|
@@ -151,7 +151,7 @@ module Mihari
|
|
151
151
|
end
|
152
152
|
|
153
153
|
#
|
154
|
-
# @return [Array<Mihari::Artifact>]
|
154
|
+
# @return [Array<Mihari::Models::Artifact>]
|
155
155
|
#
|
156
156
|
def artifacts
|
157
157
|
data.map(&:artifact)
|
data/lib/mihari/version.rb
CHANGED
@@ -31,8 +31,8 @@ module Mihari
|
|
31
31
|
filter = filter.to_h.symbolize_keys
|
32
32
|
|
33
33
|
search_filter_with_pagination = Structs::Filters::Alert::SearchFilterWithPagination.new(**filter)
|
34
|
-
alerts = Mihari::Alert.search(search_filter_with_pagination)
|
35
|
-
total = Mihari::Alert.count(search_filter_with_pagination.without_pagination)
|
34
|
+
alerts = Mihari::Models::Alert.search(search_filter_with_pagination)
|
35
|
+
total = Mihari::Models::Alert.count(search_filter_with_pagination.without_pagination)
|
36
36
|
|
37
37
|
present(
|
38
38
|
{
|
@@ -59,7 +59,7 @@ module Mihari
|
|
59
59
|
id = params["id"].to_i
|
60
60
|
|
61
61
|
result = Try do
|
62
|
-
alert = Mihari::Alert.find(id)
|
62
|
+
alert = Mihari::Models::Alert.find(id)
|
63
63
|
alert.destroy
|
64
64
|
end.to_result
|
65
65
|
|
@@ -89,7 +89,7 @@ module Mihari
|
|
89
89
|
extend Dry::Monads[:result, :try]
|
90
90
|
|
91
91
|
result = Try do
|
92
|
-
proxy = Services::AlertProxy.new(params.to_snake_keys)
|
92
|
+
proxy = Services::AlertProxy.new(**params.to_snake_keys)
|
93
93
|
runner = Services::AlertRunner.new(proxy)
|
94
94
|
runner.run
|
95
95
|
end.to_result
|
@@ -18,7 +18,7 @@ module Mihari
|
|
18
18
|
id = params[:id].to_i
|
19
19
|
|
20
20
|
result = Try do
|
21
|
-
artifact = Mihari::Artifact.includes(
|
21
|
+
artifact = Mihari::Models::Artifact.includes(
|
22
22
|
:autonomous_system,
|
23
23
|
:geolocation,
|
24
24
|
:whois_record,
|
@@ -26,9 +26,9 @@ module Mihari
|
|
26
26
|
:reverse_dns_names
|
27
27
|
).find(id)
|
28
28
|
# TODO: improve queries
|
29
|
-
alert_ids = Mihari::Artifact.where(data: artifact.data).pluck(:alert_id)
|
30
|
-
tag_ids = Mihari::Tagging.where(alert_id: alert_ids).pluck(:tag_id)
|
31
|
-
tag_names = Mihari::Tag.where(id: tag_ids).distinct.pluck(:name)
|
29
|
+
alert_ids = Mihari::Models::Artifact.where(data: artifact.data).pluck(:alert_id)
|
30
|
+
tag_ids = Mihari::Models::Tagging.where(alert_id: alert_ids).pluck(:tag_id)
|
31
|
+
tag_names = Mihari::Models::Tag.where(id: tag_ids).distinct.pluck(:name)
|
32
32
|
|
33
33
|
artifact.tags = tag_names
|
34
34
|
|
@@ -60,7 +60,7 @@ module Mihari
|
|
60
60
|
id = params["id"].to_i
|
61
61
|
|
62
62
|
result = Try do
|
63
|
-
artifact = Mihari::Artifact.includes(
|
63
|
+
artifact = Mihari::Models::Artifact.includes(
|
64
64
|
:autonomous_system,
|
65
65
|
:geolocation,
|
66
66
|
:whois_record,
|
@@ -102,7 +102,7 @@ module Mihari
|
|
102
102
|
id = params["id"].to_i
|
103
103
|
|
104
104
|
result = Try do
|
105
|
-
alert = Mihari::Artifact.find(id)
|
105
|
+
alert = Mihari::Models::Artifact.find(id)
|
106
106
|
alert.destroy
|
107
107
|
end.to_result
|
108
108
|
|
@@ -10,7 +10,7 @@ module Mihari
|
|
10
10
|
summary: "Get rule IDs"
|
11
11
|
}
|
12
12
|
get "/ids" do
|
13
|
-
rule_ids = Mihari::Rule.distinct.pluck(:id)
|
13
|
+
rule_ids = Mihari::Models::Rule.distinct.pluck(:id)
|
14
14
|
present({ rule_ids: rule_ids }, with: Entities::RuleIDs)
|
15
15
|
end
|
16
16
|
|
@@ -40,8 +40,8 @@ module Mihari
|
|
40
40
|
filter = filter.to_h.symbolize_keys
|
41
41
|
|
42
42
|
search_filter_with_pagenation = Structs::Filters::Rule::SearchFilterWithPagination.new(**filter)
|
43
|
-
rules = Mihari::Rule.search(search_filter_with_pagenation)
|
44
|
-
total = Mihari::Rule.count(search_filter_with_pagenation.without_pagination)
|
43
|
+
rules = Mihari::Models::Rule.search(search_filter_with_pagenation)
|
44
|
+
total = Mihari::Models::Rule.count(search_filter_with_pagenation.without_pagination)
|
45
45
|
|
46
46
|
present(
|
47
47
|
{ rules: rules,
|
@@ -66,7 +66,7 @@ module Mihari
|
|
66
66
|
id = params["id"].to_s
|
67
67
|
|
68
68
|
result = Try do
|
69
|
-
Mihari::Rule.find(id)
|
69
|
+
Mihari::Models::Rule.find(id)
|
70
70
|
end.to_result
|
71
71
|
|
72
72
|
return present(result.value!, with: Entities::Rule) if result.success?
|
@@ -92,10 +92,7 @@ module Mihari
|
|
92
92
|
|
93
93
|
id = params["id"].to_s
|
94
94
|
|
95
|
-
result = Try
|
96
|
-
Mihari::Services::RuleProxy.from_model(Mihari::Rule.find(id))
|
97
|
-
end.to_result
|
98
|
-
|
95
|
+
result = Try { Rule.from_model(Mihari::Models::Rule.find(id)) }.to_result
|
99
96
|
if result.success?
|
100
97
|
result.value!.analyzer.run
|
101
98
|
status 201
|
@@ -122,11 +119,9 @@ module Mihari
|
|
122
119
|
extend Dry::Monads[:result, :try]
|
123
120
|
|
124
121
|
yaml = params[:yaml]
|
125
|
-
result = Try do
|
126
|
-
Services::RuleProxy.from_yaml(yaml)
|
127
|
-
end.to_result.bind do |rule|
|
122
|
+
result = Try { Rule.from_yaml(yaml) }.to_result.bind do |rule|
|
128
123
|
Try do
|
129
|
-
found = Mihari::Rule.find_by_id(rule.id)
|
124
|
+
found = Mihari::Models::Rule.find_by_id(rule.id)
|
130
125
|
error!({ message: "ID:#{rule.id} is already registered" }, 400) unless found.nil?
|
131
126
|
rule
|
132
127
|
end.to_result
|
@@ -168,11 +163,9 @@ module Mihari
|
|
168
163
|
yaml = params[:yaml]
|
169
164
|
|
170
165
|
result = Try do
|
171
|
-
Mihari::Rule.find(id)
|
166
|
+
Mihari::Models::Rule.find(id)
|
172
167
|
end.to_result.bind do |_|
|
173
|
-
Try
|
174
|
-
Services::RuleProxy.from_yaml(yaml)
|
175
|
-
end.to_result
|
168
|
+
Try { Rule.from_yaml(yaml) }.to_result
|
176
169
|
end.bind do |rule|
|
177
170
|
Try do
|
178
171
|
rule.model.save
|
@@ -212,7 +205,7 @@ module Mihari
|
|
212
205
|
id = params["id"].to_s
|
213
206
|
|
214
207
|
result = Try do
|
215
|
-
rule = Mihari::Rule.find(id)
|
208
|
+
rule = Mihari::Models::Rule.find(id)
|
216
209
|
rule.destroy
|
217
210
|
end.to_result
|
218
211
|
|
@@ -10,7 +10,7 @@ module Mihari
|
|
10
10
|
summary: "Get tags"
|
11
11
|
}
|
12
12
|
get "/" do
|
13
|
-
tags = Mihari::Tag.distinct.pluck(:name)
|
13
|
+
tags = Mihari::Models::Tag.distinct.pluck(:name)
|
14
14
|
present({ tags: tags }, with: Entities::Tags)
|
15
15
|
end
|
16
16
|
|
@@ -28,7 +28,7 @@ module Mihari
|
|
28
28
|
name = params[:name].to_s
|
29
29
|
|
30
30
|
result = Try do
|
31
|
-
Mihari::Tag.where(name: name).destroy_all
|
31
|
+
Mihari::Models::Tag.where(name: name).destroy_all
|
32
32
|
end.to_result
|
33
33
|
|
34
34
|
if result.success?
|