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
@@ -11,7 +11,7 @@ module Mihari
|
|
11
11
|
# @param [Integer, nil] timeout
|
12
12
|
#
|
13
13
|
def initialize(base_url, api_key:, api_version:, headers: {}, timeout: nil)
|
14
|
-
raise(ArgumentError, "
|
14
|
+
raise(ArgumentError, "api_key is required") unless api_key
|
15
15
|
|
16
16
|
base_url += "/#{api_version}" unless api_version.nil?
|
17
17
|
headers["authorization"] = "Bearer #{api_key}"
|
@@ -7,17 +7,17 @@ module Mihari
|
|
7
7
|
# @param [String] base_url
|
8
8
|
# @param [String, nil] api_key
|
9
9
|
# @param [Hash] headers
|
10
|
-
# @param [
|
11
|
-
# @param [
|
10
|
+
# @param [Integer, nil] interval
|
11
|
+
# @param [Integer, nil] timeout
|
12
12
|
#
|
13
13
|
def initialize(
|
14
14
|
base_url = "https://urlscan.io",
|
15
15
|
api_key:,
|
16
16
|
headers: {},
|
17
|
-
pagination_interval:
|
17
|
+
pagination_interval: Mihari.config.pagination_interval,
|
18
18
|
timeout: nil
|
19
19
|
)
|
20
|
-
raise(ArgumentError, "
|
20
|
+
raise(ArgumentError, "api_key is required") if api_key.nil?
|
21
21
|
|
22
22
|
headers["api-key"] = api_key
|
23
23
|
|
@@ -14,10 +14,10 @@ module Mihari
|
|
14
14
|
base_url = "https://www.virustotal.com",
|
15
15
|
api_key:,
|
16
16
|
headers: {},
|
17
|
-
pagination_interval:
|
17
|
+
pagination_interval: Mihari.config.pagination_interval,
|
18
18
|
timeout: nil
|
19
19
|
)
|
20
|
-
raise(ArgumentError, "
|
20
|
+
raise(ArgumentError, "api_key is required") if api_key.nil?
|
21
21
|
|
22
22
|
headers["x-apikey"] = api_key
|
23
23
|
|
@@ -18,10 +18,10 @@ module Mihari
|
|
18
18
|
base_url = "https://api.zoomeye.org",
|
19
19
|
api_key:,
|
20
20
|
headers: {},
|
21
|
-
pagination_interval:
|
21
|
+
pagination_interval: Mihari.config.pagination_interval,
|
22
22
|
timeout: nil
|
23
23
|
)
|
24
|
-
raise(ArgumentError, "
|
24
|
+
raise(ArgumentError, "api_key is required") unless api_key
|
25
25
|
|
26
26
|
headers["api-key"] = api_key
|
27
27
|
super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout)
|
data/lib/mihari/commands/rule.rb
CHANGED
@@ -17,10 +17,7 @@ module Mihari
|
|
17
17
|
# @param [String] path
|
18
18
|
#
|
19
19
|
def validate(path)
|
20
|
-
res = Dry::Monads::Try[ValidationError]
|
21
|
-
Services::RuleProxy.from_yaml File.read(path)
|
22
|
-
end
|
23
|
-
|
20
|
+
res = Dry::Monads::Try[ValidationError] { Mihari::Rule.from_yaml File.read(path) }
|
24
21
|
rule = res.value!
|
25
22
|
puts rule.data.to_yaml
|
26
23
|
end
|
@@ -42,13 +39,6 @@ module Mihari
|
|
42
39
|
end
|
43
40
|
|
44
41
|
no_commands do
|
45
|
-
#
|
46
|
-
# @return [Mihari::Services::Rule]
|
47
|
-
#
|
48
|
-
def rule
|
49
|
-
Services::RuleProxy.from_yaml File.read(File.expand_path("../templates/rule.yml.erb", __dir__))
|
50
|
-
end
|
51
|
-
|
52
42
|
#
|
53
43
|
# Create a new rule
|
54
44
|
#
|
@@ -58,6 +48,7 @@ module Mihari
|
|
58
48
|
# @return [nil]
|
59
49
|
#
|
60
50
|
def initialize_rule(path, files = Dry::Files.new)
|
51
|
+
rule = Mihari::Rule.from_yaml File.read(File.expand_path("../templates/rule.yml.erb", __dir__))
|
61
52
|
files.write(path, rule.yaml)
|
62
53
|
end
|
63
54
|
end
|
data/lib/mihari/emitters/base.rb
CHANGED
@@ -2,49 +2,38 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
-
class Base <
|
6
|
-
|
7
|
-
|
8
|
-
include Mixins::Configurable
|
9
|
-
include Mixins::Retriable
|
10
|
-
|
11
|
-
# @return [Array<Mihari::Artifact>]
|
12
|
-
attr_reader :artifacts
|
13
|
-
|
14
|
-
# @return [Mihari::Services::Rule]
|
5
|
+
class Base < Actor
|
6
|
+
# @return [Mihari::Rule]
|
15
7
|
attr_reader :rule
|
16
8
|
|
17
9
|
#
|
18
|
-
# @param [
|
19
|
-
# @param [Mihari::Services::RuleProxy] rule
|
10
|
+
# @param [Mihari::Rule] rule
|
20
11
|
# @param [Hash, nil] options
|
21
12
|
# @param [Hash] **_params
|
22
13
|
#
|
23
|
-
def initialize(
|
14
|
+
def initialize(rule:, options: nil, **_params)
|
24
15
|
super(options: options)
|
25
16
|
|
26
|
-
@artifacts = artifacts
|
27
17
|
@rule = rule
|
28
18
|
end
|
29
19
|
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def result
|
20
|
+
#
|
21
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
22
|
+
#
|
23
|
+
def emit_result(artifacts)
|
36
24
|
Try[StandardError] do
|
37
25
|
retry_on_error(
|
38
26
|
times: retry_times,
|
39
27
|
interval: retry_interval,
|
40
28
|
exponential_backoff: retry_exponential_backoff
|
41
|
-
)
|
42
|
-
emit
|
43
|
-
end
|
29
|
+
) { emit artifacts }
|
44
30
|
end.to_result
|
45
31
|
end
|
46
32
|
|
47
|
-
|
33
|
+
#
|
34
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
35
|
+
#
|
36
|
+
def emit(artifacts)
|
48
37
|
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
49
38
|
end
|
50
39
|
|
@@ -3,22 +3,20 @@
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
5
|
class Database < Base
|
6
|
-
def valid?
|
7
|
-
configured?
|
8
|
-
end
|
9
|
-
|
10
6
|
#
|
11
7
|
# Create an alert
|
12
8
|
#
|
13
|
-
# @
|
9
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
10
|
+
#
|
11
|
+
# @return [Mihari::Models::Alert, nil]
|
14
12
|
#
|
15
|
-
def emit
|
13
|
+
def emit(artifacts)
|
16
14
|
return if artifacts.empty?
|
17
15
|
|
18
|
-
tags = rule.tags.filter_map { |name| Tag.find_or_create_by(name: name) }.uniq
|
19
|
-
taggings = tags.map { |tag| Tagging.new(tag_id: tag.id) }
|
16
|
+
tags = rule.tags.filter_map { |name| Models::Tag.find_or_create_by(name: name) }.uniq
|
17
|
+
taggings = tags.map { |tag| Models::Tagging.new(tag_id: tag.id) }
|
20
18
|
|
21
|
-
alert = Alert.new(artifacts: artifacts, taggings: taggings, rule_id: rule.id)
|
19
|
+
alert = Models::Alert.new(artifacts: artifacts, taggings: taggings, rule_id: rule.id)
|
22
20
|
alert.save
|
23
21
|
alert
|
24
22
|
end
|
data/lib/mihari/emitters/misp.rb
CHANGED
@@ -9,50 +9,39 @@ module Mihari
|
|
9
9
|
# @return [String, nil]
|
10
10
|
attr_reader :api_key
|
11
11
|
|
12
|
-
# @return [Array<Mihari::Artifact>]
|
13
|
-
attr_reader :artifacts
|
14
|
-
|
15
12
|
# @return [Mihari::Services::Rule]
|
16
13
|
attr_reader :rule
|
17
14
|
|
15
|
+
# @return [Array<Mihari::Models::Artifact>]
|
16
|
+
attr_accessor :artifacts
|
17
|
+
|
18
18
|
#
|
19
|
-
# @param [Array<Mihari::Artifact>] artifacts
|
20
19
|
# @param [Mihari::Services::Rule] rule
|
21
20
|
# @param [Hash, nil] options
|
22
21
|
# @param [Hash] **params
|
23
22
|
#
|
24
|
-
def initialize(
|
25
|
-
super(
|
23
|
+
def initialize(rule:, options: nil, **params)
|
24
|
+
super(rule: rule, options: options)
|
26
25
|
|
27
26
|
@url = params[:url] || Mihari.config.misp_url
|
28
27
|
@api_key = params[:api_key] || Mihari.config.misp_api_key
|
28
|
+
|
29
|
+
@artifacts = []
|
29
30
|
end
|
30
31
|
|
32
|
+
#
|
31
33
|
# @return [Boolean]
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Mihari.logger.info("MISP API key is not set") unless api_key?
|
36
|
-
return false
|
37
|
-
end
|
38
|
-
|
39
|
-
unless ping?
|
40
|
-
Mihari.logger.info("MISP URL (#{url}) is not reachable")
|
41
|
-
return false
|
42
|
-
end
|
43
|
-
|
44
|
-
true
|
34
|
+
#
|
35
|
+
def configured?
|
36
|
+
api_key? && url?
|
45
37
|
end
|
46
38
|
|
47
39
|
#
|
48
40
|
# Create a MISP event
|
49
41
|
#
|
50
|
-
# @param [
|
51
|
-
# @param [Mihari::Services::Rule] rule
|
52
|
-
#
|
53
|
-
# @return [::MISP::Event]
|
42
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
54
43
|
#
|
55
|
-
def emit
|
44
|
+
def emit(artifacts)
|
56
45
|
return if artifacts.empty?
|
57
46
|
|
58
47
|
client.create_event({
|
@@ -77,7 +66,7 @@ module Mihari
|
|
77
66
|
#
|
78
67
|
# Build a MISP attribute
|
79
68
|
#
|
80
|
-
# @param [Mihari::Artifact] artifact
|
69
|
+
# @param [Mihari::Models::Artifact] artifact
|
81
70
|
#
|
82
71
|
# @return [Hash]
|
83
72
|
#
|
@@ -143,19 +132,6 @@ module Mihari
|
|
143
132
|
def api_key?
|
144
133
|
!api_key.nil? && !api_key.empty?
|
145
134
|
end
|
146
|
-
|
147
|
-
#
|
148
|
-
# Check whether a URL is reachable or not
|
149
|
-
#
|
150
|
-
# @return [Boolean]
|
151
|
-
#
|
152
|
-
def ping?
|
153
|
-
base_url = url.end_with?("/") ? url[0..-2] : url
|
154
|
-
login_url = "#{base_url}/users/login"
|
155
|
-
|
156
|
-
http = Net::Ping::HTTP.new(login_url)
|
157
|
-
http.ping?
|
158
|
-
end
|
159
135
|
end
|
160
136
|
end
|
161
137
|
end
|
@@ -131,18 +131,22 @@ module Mihari
|
|
131
131
|
# @return [String]
|
132
132
|
attr_reader :username
|
133
133
|
|
134
|
+
# @return [Array<Mihari::Models::Artifact>]
|
135
|
+
attr_accessor :artifacts
|
136
|
+
|
134
137
|
#
|
135
|
-
# @param [Array<Mihari::Artifact>] artifacts
|
136
138
|
# @param [Mihari::Services::Rule] rule
|
137
139
|
# @param [Hash, nil] options
|
138
140
|
# @param [Hash] **params
|
139
141
|
#
|
140
|
-
def initialize(
|
141
|
-
super(
|
142
|
+
def initialize(rule:, options: nil, **params)
|
143
|
+
super(rule: rule, options: options)
|
142
144
|
|
143
145
|
@webhook_url = params[:webhook_url] || Mihari.config.slack_webhook_url
|
144
146
|
@channel = params[:channel] || Mihari.config.slack_channel || DEFAULT_CHANNEL
|
145
147
|
@username = DEFAULT_USERNAME
|
148
|
+
|
149
|
+
@artifacts = []
|
146
150
|
end
|
147
151
|
|
148
152
|
#
|
@@ -154,12 +158,10 @@ module Mihari
|
|
154
158
|
!webhook_url.nil?
|
155
159
|
end
|
156
160
|
|
157
|
-
#
|
158
|
-
# Check webhook URL is set. Alias of #webhook_url?
|
159
161
|
#
|
160
162
|
# @return [Boolean]
|
161
163
|
#
|
162
|
-
def
|
164
|
+
def configured?
|
163
165
|
webhook_url?
|
164
166
|
end
|
165
167
|
|
@@ -211,19 +213,20 @@ module Mihari
|
|
211
213
|
].join("\n")
|
212
214
|
end
|
213
215
|
|
214
|
-
|
216
|
+
#
|
217
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
218
|
+
#
|
219
|
+
def emit(artifacts)
|
215
220
|
return if artifacts.empty?
|
216
221
|
|
222
|
+
@artifacts = artifacts
|
223
|
+
|
217
224
|
notifier.post(text: text, attachments: attachments, mrkdwn: true)
|
218
225
|
end
|
219
226
|
|
220
227
|
def configuration_keys
|
221
228
|
%w[slack_webhook_url slack_channel]
|
222
229
|
end
|
223
|
-
|
224
|
-
def configured?
|
225
|
-
valid?
|
226
|
-
end
|
227
230
|
end
|
228
231
|
end
|
229
232
|
end
|
@@ -12,45 +12,42 @@ module Mihari
|
|
12
12
|
# @return [String, nil]
|
13
13
|
attr_reader :api_version
|
14
14
|
|
15
|
+
# @return [Array<Mihari::Models::Artifact>]
|
16
|
+
attr_accessor :artifacts
|
17
|
+
|
15
18
|
#
|
16
|
-
# @param [Array<Mihari::Artifact>] artifacts
|
17
19
|
# @param [Mihari::Services::Rule] rule
|
18
20
|
# @param [Hash, nil] options
|
19
21
|
# @param [Hash] **params
|
20
22
|
#
|
21
|
-
def initialize(
|
22
|
-
super(
|
23
|
+
def initialize(rule:, options: nil, **params)
|
24
|
+
super(rule: rule, options: options)
|
23
25
|
|
24
26
|
@url = params[:url] || Mihari.config.thehive_url
|
25
27
|
@api_key = params[:api_key] || Mihari.config.thehive_api_key
|
26
28
|
@api_version = params[:api_version] || Mihari.config.thehive_api_version
|
29
|
+
|
30
|
+
@artifacts = []
|
27
31
|
end
|
28
32
|
|
33
|
+
#
|
29
34
|
# @return [Boolean]
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
Mihari.logger.info("TheHive API key is not set") unless api_key?
|
34
|
-
return false
|
35
|
-
end
|
36
|
-
|
37
|
-
unless ping?
|
38
|
-
Mihari.logger.info("TheHive URL (#{url}) is not reachable")
|
39
|
-
return false
|
40
|
-
end
|
41
|
-
|
42
|
-
true
|
35
|
+
#
|
36
|
+
def configured?
|
37
|
+
api_key? && url?
|
43
38
|
end
|
44
39
|
|
45
40
|
#
|
46
41
|
# Create a Hive alert
|
47
42
|
#
|
48
|
-
# @
|
43
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
49
44
|
#
|
50
|
-
def emit
|
45
|
+
def emit(artifacts)
|
51
46
|
return if artifacts.empty?
|
52
47
|
|
53
|
-
|
48
|
+
@artifacts = artifacts
|
49
|
+
|
50
|
+
client.alert payload
|
54
51
|
end
|
55
52
|
|
56
53
|
#
|
@@ -146,31 +143,6 @@ module Mihari
|
|
146
143
|
source_ref: "1"
|
147
144
|
}
|
148
145
|
end
|
149
|
-
|
150
|
-
#
|
151
|
-
# Check whether a URL is reachable or not
|
152
|
-
#
|
153
|
-
# @return [Boolean]
|
154
|
-
#
|
155
|
-
def ping?
|
156
|
-
base_url = url.end_with?("/") ? url[0..-2] : url
|
157
|
-
|
158
|
-
if normalized_api_version.nil?
|
159
|
-
# for v4
|
160
|
-
base_url = url.end_with?("/") ? url[0..-2] : url
|
161
|
-
public_url = "#{base_url}/index.html"
|
162
|
-
else
|
163
|
-
# for v5
|
164
|
-
public_url = "#{base_url}/api/v1/status/public"
|
165
|
-
end
|
166
|
-
|
167
|
-
http = Net::Ping::HTTP.new(public_url)
|
168
|
-
|
169
|
-
# use GET for v5
|
170
|
-
http.get_request = true if normalized_api_version
|
171
|
-
|
172
|
-
http.ping?
|
173
|
-
end
|
174
146
|
end
|
175
147
|
end
|
176
148
|
end
|
@@ -57,23 +57,41 @@ module Mihari
|
|
57
57
|
# @return [String, nil]
|
58
58
|
attr_reader :template
|
59
59
|
|
60
|
+
# @return [Array<Mihari::Models::Artifact>]
|
61
|
+
attr_accessor :artifacts
|
62
|
+
|
60
63
|
#
|
61
|
-
# @param [Array<Mihari::Artifact>] artifacts
|
62
64
|
# @param [Mihari::Services::Rule] rule
|
63
65
|
# @param [Hash] **options
|
64
66
|
#
|
65
|
-
def initialize(
|
66
|
-
super(
|
67
|
+
def initialize(rule:, options: nil, **params)
|
68
|
+
super(rule: rule, options: options)
|
67
69
|
|
68
70
|
@url = Addressable::URI.parse(params[:url])
|
69
71
|
@headers = params[:headers] || {}
|
70
72
|
@method = params[:method] || "POST"
|
71
73
|
@template = params[:template]
|
74
|
+
|
75
|
+
@artifacts = []
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# @return [Boolean]
|
80
|
+
#
|
81
|
+
def configured?
|
82
|
+
return false if url.nil?
|
83
|
+
|
84
|
+
%w[http https].include? url.scheme.downcase
|
72
85
|
end
|
73
86
|
|
74
|
-
|
87
|
+
#
|
88
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
89
|
+
#
|
90
|
+
def emit(artifacts)
|
75
91
|
return if artifacts.empty?
|
76
92
|
|
93
|
+
@artifacts = artifacts
|
94
|
+
|
77
95
|
# returns body to prevent Parallel issue (Parallel fails to handle HTTP:Response object)
|
78
96
|
case method
|
79
97
|
when "GET"
|
@@ -83,12 +101,6 @@ module Mihari
|
|
83
101
|
end
|
84
102
|
end
|
85
103
|
|
86
|
-
def valid?
|
87
|
-
return false if url.nil?
|
88
|
-
|
89
|
-
%w[http https].include? url.scheme.downcase
|
90
|
-
end
|
91
|
-
|
92
104
|
private
|
93
105
|
|
94
106
|
def http
|
@@ -101,17 +113,15 @@ module Mihari
|
|
101
113
|
# @return [String]
|
102
114
|
#
|
103
115
|
def rendered_template
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
out << payload_template.result
|
114
|
-
end.first
|
116
|
+
options = {}
|
117
|
+
options[:template] = File.read(template) unless template.nil?
|
118
|
+
|
119
|
+
payload_template = PayloadTemplate.new(
|
120
|
+
artifacts: artifacts,
|
121
|
+
rule: rule,
|
122
|
+
options: options
|
123
|
+
)
|
124
|
+
payload_template.result
|
115
125
|
end
|
116
126
|
|
117
127
|
#
|