mihari 5.6.1 → 5.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/README.md +1 -0
- data/config.ru +1 -1
- data/docs/analyzers/fofa.md +31 -0
- data/docs/analyzers/index.md +1 -0
- data/frontend/package-lock.json +183 -186
- data/frontend/package.json +10 -10
- data/frontend/src/components/alert/Form.vue +1 -14
- data/frontend/src/components/artifact/AS.vue +2 -8
- data/frontend/src/components/artifact/DnsRecords.vue +2 -8
- data/frontend/src/components/artifact/ReverseDnsNames.vue +2 -10
- data/frontend/src/components/artifact/WhoisRecord.vue +1 -1
- data/lib/mihari/{base.rb → actor.rb} +27 -3
- data/lib/mihari/analyzers/base.rb +16 -20
- data/lib/mihari/analyzers/binaryedge.rb +4 -1
- data/lib/mihari/analyzers/censys.rb +5 -3
- data/lib/mihari/analyzers/circl.rb +4 -1
- data/lib/mihari/analyzers/crtsh.rb +4 -1
- data/lib/mihari/analyzers/dnstwister.rb +4 -1
- data/lib/mihari/analyzers/feed.rb +3 -0
- data/lib/mihari/analyzers/fofa.rb +65 -0
- data/lib/mihari/analyzers/greynoise.rb +4 -1
- data/lib/mihari/analyzers/hunterhow.rb +7 -2
- data/lib/mihari/analyzers/onyphe.rb +4 -1
- data/lib/mihari/analyzers/otx.rb +4 -1
- data/lib/mihari/analyzers/passivetotal.rb +5 -2
- data/lib/mihari/analyzers/pulsedive.rb +4 -1
- data/lib/mihari/analyzers/securitytrails.rb +5 -2
- data/lib/mihari/analyzers/shodan.rb +4 -1
- data/lib/mihari/analyzers/urlscan.rb +5 -2
- data/lib/mihari/analyzers/virustotal.rb +9 -6
- data/lib/mihari/analyzers/virustotal_intelligence.rb +4 -1
- data/lib/mihari/analyzers/zoomeye.rb +8 -5
- data/lib/mihari/cli/alert.rb +3 -0
- data/lib/mihari/cli/base.rb +3 -0
- data/lib/mihari/cli/database.rb +3 -0
- data/lib/mihari/cli/main.rb +3 -0
- data/lib/mihari/cli/rule.rb +3 -0
- data/lib/mihari/clients/base.rb +3 -0
- data/lib/mihari/clients/binaryedge.rb +5 -2
- data/lib/mihari/clients/censys.rb +7 -4
- data/lib/mihari/clients/circl.rb +3 -0
- data/lib/mihari/clients/crtsh.rb +5 -2
- data/lib/mihari/clients/dnstwister.rb +3 -0
- data/lib/mihari/clients/fofa.rb +83 -0
- data/lib/mihari/clients/greynoise.rb +5 -2
- data/lib/mihari/clients/hunterhow.rb +5 -2
- data/lib/mihari/clients/misp.rb +3 -0
- data/lib/mihari/clients/onyphe.rb +5 -2
- data/lib/mihari/clients/otx.rb +3 -0
- data/lib/mihari/clients/passivetotal.rb +7 -4
- data/lib/mihari/clients/publsedive.rb +4 -1
- data/lib/mihari/clients/securitytrails.rb +6 -3
- data/lib/mihari/clients/shodan.rb +5 -2
- data/lib/mihari/clients/the_hive.rb +3 -0
- data/lib/mihari/clients/urlscan.rb +7 -4
- data/lib/mihari/clients/virustotal.rb +5 -2
- data/lib/mihari/clients/zoomeye.rb +3 -0
- data/lib/mihari/commands/alert.rb +5 -14
- data/lib/mihari/commands/database.rb +3 -0
- data/lib/mihari/commands/rule.rb +11 -11
- data/lib/mihari/commands/search.rb +9 -6
- data/lib/mihari/commands/version.rb +3 -0
- data/lib/mihari/commands/web.rb +4 -1
- data/lib/mihari/config.rb +139 -150
- data/lib/mihari/constants.rb +1 -1
- data/lib/mihari/database.rb +6 -0
- data/lib/mihari/emitters/base.rb +16 -25
- data/lib/mihari/emitters/database.rb +10 -9
- data/lib/mihari/emitters/misp.rb +20 -41
- data/lib/mihari/emitters/slack.rb +16 -13
- data/lib/mihari/emitters/the_hive.rb +18 -46
- data/lib/mihari/emitters/webhook.rb +34 -23
- data/lib/mihari/enrichers/base.rb +16 -15
- data/lib/mihari/enrichers/google_public_dns.rb +6 -5
- data/lib/mihari/enrichers/ipinfo.rb +10 -8
- data/lib/mihari/enrichers/shodan.rb +4 -6
- data/lib/mihari/enrichers/whois.rb +13 -10
- data/lib/mihari/errors.rb +6 -0
- data/lib/mihari/feed/parser.rb +3 -0
- data/lib/mihari/feed/reader.rb +3 -0
- data/lib/mihari/http.rb +6 -0
- data/lib/mihari/mixins/autonomous_system.rb +3 -0
- data/lib/mihari/mixins/configurable.rb +3 -0
- data/lib/mihari/mixins/error_notification.rb +3 -0
- data/lib/mihari/mixins/falsepositive.rb +3 -0
- data/lib/mihari/mixins/refang.rb +3 -0
- data/lib/mihari/mixins/retriable.rb +6 -2
- data/lib/mihari/models/alert.rb +78 -73
- data/lib/mihari/models/artifact.rb +186 -178
- data/lib/mihari/models/autonomous_system.rb +25 -20
- data/lib/mihari/models/cpe.rb +24 -19
- data/lib/mihari/models/dns.rb +27 -22
- data/lib/mihari/models/geolocation.rb +25 -20
- data/lib/mihari/models/port.rb +24 -19
- data/lib/mihari/models/reverse_dns.rb +24 -19
- data/lib/mihari/models/rule.rb +71 -66
- data/lib/mihari/models/tag.rb +8 -3
- data/lib/mihari/models/tagging.rb +8 -3
- data/lib/mihari/models/whois.rb +20 -17
- data/lib/mihari/rule.rb +357 -0
- data/lib/mihari/schemas/alert.rb +3 -0
- data/lib/mihari/schemas/analyzer.rb +105 -87
- data/lib/mihari/schemas/emitter.rb +12 -5
- data/lib/mihari/schemas/enricher.rb +11 -4
- data/lib/mihari/schemas/macros.rb +4 -0
- data/lib/mihari/schemas/mixins.rb +20 -0
- data/lib/mihari/schemas/rule.rb +6 -10
- data/lib/mihari/service.rb +16 -0
- data/lib/mihari/services/alert_builder.rb +8 -5
- data/lib/mihari/services/alert_proxy.rb +16 -7
- data/lib/mihari/services/alert_runner.rb +10 -14
- data/lib/mihari/services/rule_builder.rb +10 -7
- data/lib/mihari/services/rule_runner.rb +11 -13
- data/lib/mihari/structs/binaryedge.rb +14 -29
- data/lib/mihari/structs/censys.rb +54 -133
- data/lib/mihari/structs/config.rb +20 -31
- data/lib/mihari/structs/filters.rb +38 -0
- data/lib/mihari/structs/fofa.rb +44 -0
- data/lib/mihari/structs/google_public_dns.rb +10 -28
- data/lib/mihari/structs/greynoise.rb +38 -89
- data/lib/mihari/structs/hunterhow.rb +27 -25
- data/lib/mihari/structs/ipinfo.rb +14 -35
- data/lib/mihari/structs/onyphe.rb +36 -81
- data/lib/mihari/structs/shodan.rb +53 -118
- data/lib/mihari/structs/urlscan.rb +27 -66
- data/lib/mihari/structs/virustotal_intelligence.rb +23 -59
- data/lib/mihari/type_checker.rb +4 -0
- data/lib/mihari/types.rb +3 -0
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/api.rb +15 -10
- data/lib/mihari/web/app.rb +59 -54
- data/lib/mihari/web/endpoints/alerts.rb +94 -89
- data/lib/mihari/web/endpoints/artifacts.rb +115 -110
- data/lib/mihari/web/endpoints/configs.rb +18 -13
- data/lib/mihari/web/endpoints/ip_addresses.rb +21 -16
- data/lib/mihari/web/endpoints/rules.rb +202 -204
- data/lib/mihari/web/endpoints/tags.rb +41 -36
- data/lib/mihari/web/middleware/connection_adapter.rb +16 -9
- data/lib/mihari/web/middleware/error_notification_adapter.rb +17 -10
- data/lib/mihari/web/public/assets/{index-9cc489e6.js → index-821134e2.js} +54 -54
- data/lib/mihari/web/public/assets/mode-yaml-24faa242.js +8 -0
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari.rb +30 -13
- data/mihari.gemspec +9 -3
- data/mkdocs.yml +3 -2
- data/requirements.txt +1 -1
- metadata +44 -26
- data/lib/mihari/analyzers/rule.rb +0 -232
- data/lib/mihari/services/rule_proxy.rb +0 -182
- data/lib/mihari/templates/rule.yml.erb +0 -5
- data/lib/mihari/web/public/assets/mode-yaml-a21faa53.js +0 -8
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Clients
|
5
|
+
#
|
6
|
+
# VirusTotal API client
|
7
|
+
#
|
5
8
|
class VirusTotal < Base
|
6
9
|
#
|
7
10
|
# @param [String] base_url
|
@@ -46,7 +49,7 @@ module Mihari
|
|
46
49
|
# @param [String] query
|
47
50
|
# @param [String, nil] cursor
|
48
51
|
#
|
49
|
-
# @return [Structs::VirusTotalIntelligence::Response]
|
52
|
+
# @return [Mihari::Structs::VirusTotalIntelligence::Response]
|
50
53
|
#
|
51
54
|
def intel_search(query, cursor: nil)
|
52
55
|
params = { query: query, cursor: cursor }.compact
|
@@ -58,7 +61,7 @@ module Mihari
|
|
58
61
|
# @param [String] query
|
59
62
|
# @param [Integer] pagination_limit
|
60
63
|
#
|
61
|
-
# @return [Enumerable<Structs::VirusTotalIntelligence::Response>]
|
64
|
+
# @return [Enumerable<Mihari::Structs::VirusTotalIntelligence::Response>]
|
62
65
|
#
|
63
66
|
def intel_search_with_pagination(query, pagination_limit: Mihari.config.pagination_limit)
|
64
67
|
cursor = nil
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Commands
|
5
|
+
#
|
6
|
+
# Alert sub-commands
|
7
|
+
#
|
5
8
|
module Alert
|
6
9
|
class << self
|
7
10
|
def included(thor)
|
@@ -16,26 +19,14 @@ module Mihari
|
|
16
19
|
Mihari::Database.with_db_connection do
|
17
20
|
builder = Services::AlertBuilder.new(path)
|
18
21
|
|
19
|
-
|
20
|
-
result = builder.result.bind(
|
22
|
+
runner_result_l = ->(proxy) { Services::AlertRunner.new(proxy).result }
|
23
|
+
result = builder.result.bind(runner_result_l)
|
21
24
|
|
22
25
|
alert = result.value!
|
23
26
|
data = Entities::Alert.represent(alert)
|
24
27
|
puts JSON.pretty_generate(data.as_json)
|
25
28
|
end
|
26
29
|
end
|
27
|
-
|
28
|
-
no_commands do
|
29
|
-
#
|
30
|
-
# @param [Mihari::Services::AlertProxy] proxy
|
31
|
-
#
|
32
|
-
def run_proxy(proxy)
|
33
|
-
Dry::Monads::Try[StandardError] do
|
34
|
-
runner = Services::AlertRunner.new(proxy)
|
35
|
-
runner.run
|
36
|
-
end.to_result
|
37
|
-
end
|
38
|
-
end
|
39
30
|
end
|
40
31
|
end
|
41
32
|
end
|
data/lib/mihari/commands/rule.rb
CHANGED
@@ -4,6 +4,9 @@ require "pathname"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Commands
|
7
|
+
#
|
8
|
+
# Rule sub-commands
|
9
|
+
#
|
7
10
|
module Rule
|
8
11
|
class << self
|
9
12
|
def included(thor)
|
@@ -17,10 +20,7 @@ module Mihari
|
|
17
20
|
# @param [String] path
|
18
21
|
#
|
19
22
|
def validate(path)
|
20
|
-
res = Dry::Monads::Try[ValidationError]
|
21
|
-
Services::RuleProxy.from_yaml File.read(path)
|
22
|
-
end
|
23
|
-
|
23
|
+
res = Dry::Monads::Try[ValidationError] { Mihari::Rule.from_yaml File.read(path) }
|
24
24
|
rule = res.value!
|
25
25
|
puts rule.data.to_yaml
|
26
26
|
end
|
@@ -42,13 +42,6 @@ module Mihari
|
|
42
42
|
end
|
43
43
|
|
44
44
|
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
45
|
#
|
53
46
|
# Create a new rule
|
54
47
|
#
|
@@ -58,6 +51,13 @@ module Mihari
|
|
58
51
|
# @return [nil]
|
59
52
|
#
|
60
53
|
def initialize_rule(path, files = Dry::Files.new)
|
54
|
+
rule = Mihari::Rule.new(
|
55
|
+
id: SecureRandom.uuid,
|
56
|
+
title: "Title goes here",
|
57
|
+
description: "Description goes here",
|
58
|
+
created_on: Date.today,
|
59
|
+
queries: []
|
60
|
+
)
|
61
61
|
files.write(path, rule.yaml)
|
62
62
|
end
|
63
63
|
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Commands
|
5
|
+
#
|
6
|
+
# Search sub-commands
|
7
|
+
#
|
5
8
|
module Search
|
6
9
|
class << self
|
7
10
|
def included(thor)
|
@@ -20,9 +23,9 @@ module Mihari
|
|
20
23
|
builder = Services::RuleBuilder.new(path_or_id)
|
21
24
|
|
22
25
|
check_diff_l = ->(rule) { check_diff rule }
|
23
|
-
|
26
|
+
update_and_call_l = ->(runner) { update_and_call runner }
|
24
27
|
|
25
|
-
result = builder.result.bind(check_diff_l).bind(
|
28
|
+
result = builder.result.bind(check_diff_l).bind(update_and_call_l)
|
26
29
|
|
27
30
|
alert = result.value!
|
28
31
|
data = Entities::Alert.represent(alert)
|
@@ -32,7 +35,7 @@ module Mihari
|
|
32
35
|
|
33
36
|
no_commands do
|
34
37
|
#
|
35
|
-
# @param [Mihari::
|
38
|
+
# @param [Mihari::RuleRunner] rule
|
36
39
|
#
|
37
40
|
def check_diff(rule)
|
38
41
|
force_overwrite = options["force_overwrite"] || false
|
@@ -45,12 +48,12 @@ module Mihari
|
|
45
48
|
end
|
46
49
|
|
47
50
|
#
|
48
|
-
# @param [Mihari::
|
51
|
+
# @param [Mihari::RuleRunner] runner
|
49
52
|
#
|
50
|
-
def
|
53
|
+
def update_and_call(runner)
|
51
54
|
Dry::Monads::Try[StandardError] do
|
52
55
|
runner.update_or_create
|
53
|
-
runner.
|
56
|
+
runner.call
|
54
57
|
end.to_result
|
55
58
|
end
|
56
59
|
end
|
data/lib/mihari/commands/web.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Commands
|
5
|
+
#
|
6
|
+
# Web sub-commands
|
7
|
+
#
|
5
8
|
module Web
|
6
9
|
class << self
|
7
10
|
def included(thor)
|
@@ -20,7 +23,7 @@ module Mihari
|
|
20
23
|
Mihari.config.hide_config_values = options["hide_config_values"]
|
21
24
|
# set rack env as production
|
22
25
|
ENV["RACK_ENV"] ||= options["rack_env"]
|
23
|
-
Mihari::App.run!(
|
26
|
+
Mihari::Web::App.run!(
|
24
27
|
port: options["port"],
|
25
28
|
host: options["host"],
|
26
29
|
threads: options["threads"],
|
data/lib/mihari/config.rb
CHANGED
@@ -1,178 +1,167 @@
|
|
1
|
-
|
2
|
-
class Config
|
3
|
-
# @return [String, nil]
|
4
|
-
attr_reader :binaryedge_api_key
|
5
|
-
|
6
|
-
# @return [String, nil]
|
7
|
-
attr_reader :censys_id
|
8
|
-
|
9
|
-
# @return [String, nil]
|
10
|
-
attr_reader :censys_secret
|
11
|
-
|
12
|
-
# @return [String, nil]
|
13
|
-
attr_reader :circl_passive_password
|
14
|
-
|
15
|
-
# @return [String, nil]
|
16
|
-
attr_reader :circl_passive_username
|
17
|
-
|
18
|
-
# @return [URI]
|
19
|
-
attr_reader :database_url
|
20
|
-
|
21
|
-
# @return [String, nil]
|
22
|
-
attr_reader :greynoise_api_key
|
23
|
-
|
24
|
-
# @return [String, nil]
|
25
|
-
attr_reader :hunterhow_api_key
|
26
|
-
|
27
|
-
# @return [String, nil]
|
28
|
-
attr_reader :ipinfo_api_key
|
29
|
-
|
30
|
-
# @return [String, nil]
|
31
|
-
attr_reader :misp_url
|
32
|
-
|
33
|
-
# @return [String, nil]
|
34
|
-
attr_reader :misp_api_key
|
35
|
-
|
36
|
-
# @return [String, nil]
|
37
|
-
attr_reader :onyphe_api_key
|
38
|
-
|
39
|
-
# @return [String, nil]
|
40
|
-
attr_reader :otx_api_key
|
41
|
-
|
42
|
-
# @return [String, nil]
|
43
|
-
attr_reader :passivetotal_api_key
|
44
|
-
|
45
|
-
# @return [String, nil]
|
46
|
-
attr_reader :passivetotal_username
|
47
|
-
|
48
|
-
# @return [String, nil]
|
49
|
-
attr_reader :pulsedive_api_key
|
50
|
-
|
51
|
-
# @return [String, nil]
|
52
|
-
attr_reader :securitytrails_api_key
|
53
|
-
|
54
|
-
# @return [String, nil]
|
55
|
-
attr_reader :shodan_api_key
|
56
|
-
|
57
|
-
# @return [String, nil]
|
58
|
-
attr_reader :slack_channel
|
59
|
-
|
60
|
-
# @return [String, nil]
|
61
|
-
attr_reader :slack_webhook_url
|
62
|
-
|
63
|
-
# @return [String, nil]
|
64
|
-
attr_reader :thehive_url
|
1
|
+
# frozen_string_literal: true
|
65
2
|
|
66
|
-
|
67
|
-
attr_reader :thehive_api_key
|
3
|
+
require "anyway_config"
|
68
4
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
@greynoise_api_key = ENV.fetch("GREYNOISE_API_KEY", nil)
|
121
|
-
|
122
|
-
@ipinfo_api_key = ENV.fetch("IPINFO_API_KEY", nil)
|
123
|
-
|
124
|
-
@hunterhow_api_key = ENV.fetch("HUNTERHOW_API_KEY", nil)
|
5
|
+
module Mihari
|
6
|
+
class Config < Anyway::Config
|
7
|
+
config_name :mihari
|
8
|
+
env_prefix ""
|
9
|
+
|
10
|
+
attr_config(
|
11
|
+
# analyzers, emitters & enrichers
|
12
|
+
binaryedge_api_key: nil,
|
13
|
+
censys_id: nil,
|
14
|
+
censys_secret: nil,
|
15
|
+
circl_passive_password: nil,
|
16
|
+
circl_passive_username: nil,
|
17
|
+
database_url: URI("sqlite3:///mihari.db"),
|
18
|
+
fofa_api_key: nil,
|
19
|
+
fofa_email: nil,
|
20
|
+
greynoise_api_key: nil,
|
21
|
+
hunterhow_api_key: nil,
|
22
|
+
ipinfo_api_key: nil,
|
23
|
+
misp_api_key: nil,
|
24
|
+
misp_url: nil,
|
25
|
+
onyphe_api_key: nil,
|
26
|
+
otx_api_key: nil,
|
27
|
+
passivetotal_api_key: nil,
|
28
|
+
passivetotal_username: nil,
|
29
|
+
pulsedive_api_key: nil,
|
30
|
+
securitytrails_api_key: nil,
|
31
|
+
shodan_api_key: nil,
|
32
|
+
slack_channel: nil,
|
33
|
+
slack_webhook_url: nil,
|
34
|
+
thehive_api_key: nil,
|
35
|
+
thehive_api_version: nil,
|
36
|
+
thehive_url: nil,
|
37
|
+
urlscan_api_key: nil,
|
38
|
+
virustotal_api_key: nil,
|
39
|
+
zoomeye_api_key: nil,
|
40
|
+
# others
|
41
|
+
hide_config_values: true,
|
42
|
+
ignore_error: false,
|
43
|
+
pagination_interval: 0,
|
44
|
+
pagination_limit: 100,
|
45
|
+
retry_exponential_backoff: true,
|
46
|
+
retry_interval: 5,
|
47
|
+
retry_times: 3,
|
48
|
+
sentry_dsn: nil
|
49
|
+
)
|
50
|
+
|
51
|
+
# @!attribute [r] binaryedge_api_key
|
52
|
+
# @return [String, nil]
|
53
|
+
|
54
|
+
# @!attribute [r] censys_id
|
55
|
+
# @return [String, nil]
|
125
56
|
|
126
|
-
|
127
|
-
|
57
|
+
# @!attribute [r] circl_passive_password
|
58
|
+
# @return [String, nil]
|
59
|
+
|
60
|
+
# @!attribute [r] circl_passive_username
|
61
|
+
# @return [String, nil]
|
62
|
+
|
63
|
+
# @!attribute [r] database_url
|
64
|
+
# @return [String, nil]
|
65
|
+
|
66
|
+
# @!attribute [r] fofa_api_key
|
67
|
+
# @return [String, nil]
|
68
|
+
|
69
|
+
# @!attribute [r] fofa_email
|
70
|
+
# @return [String, nil]
|
71
|
+
|
72
|
+
# @!attribute [r] greynoise_api_key
|
73
|
+
# @return [String, nil]
|
74
|
+
|
75
|
+
# @!attribute [r] hunterhow_api_key
|
76
|
+
# @return [String, nil]
|
77
|
+
|
78
|
+
# @!attribute [r] ipinfo_api_key
|
79
|
+
# @return [String, nil]
|
80
|
+
|
81
|
+
# @!attribute [r] misp_url
|
82
|
+
# @return [String, nil]
|
83
|
+
|
84
|
+
# @!attribute [r] misp_api_key
|
85
|
+
# @return [String, nil]
|
86
|
+
|
87
|
+
# @!attribute [r] onyphe_api_key
|
88
|
+
# @return [String, nil]
|
89
|
+
|
90
|
+
# @!attribute [r] otx_api_key
|
91
|
+
# @return [String, nil]
|
92
|
+
|
93
|
+
# @!attribute [r] passivetotal_api_key
|
94
|
+
# @return [String, nil]
|
95
|
+
|
96
|
+
# @!attribute [r] passivetotal_username
|
97
|
+
# @return [String, nil]
|
98
|
+
|
99
|
+
# @!attribute [r] pulsedive_api_key
|
100
|
+
# @return [String, nil]
|
101
|
+
|
102
|
+
# @!attribute [r] securitytrails_api_key
|
103
|
+
# @return [String, nil]
|
104
|
+
|
105
|
+
# @!attribute [r] shodan_api_key
|
106
|
+
# @return [String, nil]
|
128
107
|
|
129
|
-
|
108
|
+
# @!attribute [r] slack_channel
|
109
|
+
# @return [String, nil]
|
110
|
+
|
111
|
+
# @!attribute [r] slack_webhook_url
|
112
|
+
# @return [String, nil]
|
130
113
|
|
131
|
-
|
114
|
+
# @!attribute [r] thehive_url
|
115
|
+
# @return [String, nil]
|
132
116
|
|
133
|
-
|
134
|
-
|
117
|
+
# @!attribute [r] thehive_api_key
|
118
|
+
# @return [String, nil]
|
135
119
|
|
136
|
-
|
120
|
+
# @!attribute [r] thehive_api_version
|
121
|
+
# @return [String, nil]
|
137
122
|
|
138
|
-
|
123
|
+
# @!attribute [r] urlscan_api_key
|
124
|
+
# @return [String, nil]
|
139
125
|
|
140
|
-
|
126
|
+
# @!attribute [r] virustotal_api_key
|
127
|
+
# @return [String, nil]
|
141
128
|
|
142
|
-
|
143
|
-
|
129
|
+
# @!attribute [r] zoomeye_api_key
|
130
|
+
# @return [String, nil]
|
144
131
|
|
145
|
-
|
146
|
-
|
147
|
-
@thehive_api_version = ENV.fetch("THEHIVE_API_VERSION", nil)
|
132
|
+
# @!attribute [r] sentry_dsn
|
133
|
+
# @return [String, nil]
|
148
134
|
|
149
|
-
|
135
|
+
# @!attribute [r] retry_interval
|
136
|
+
# @return [Integer]
|
150
137
|
|
151
|
-
|
138
|
+
# @!attribute [r] retry_times
|
139
|
+
# @return [Integer]
|
152
140
|
|
153
|
-
|
141
|
+
# @!attribute [r] retry_exponential_backoff
|
142
|
+
# @return [Boolean]
|
154
143
|
|
155
|
-
|
144
|
+
# @!attribute [r] pagination_interval
|
145
|
+
# @return [Integer]
|
156
146
|
|
157
|
-
|
147
|
+
# @!attribute [r] pagination_limit
|
148
|
+
# @return [Integer]
|
158
149
|
|
159
|
-
|
160
|
-
|
161
|
-
@retry_exponential_backoff = ENV.fetch("RETRY_EXPONENTIAL_BACKOFF", true).to_s.downcase == "true"
|
150
|
+
# @!attribute [r] ignore_error
|
151
|
+
# @return [Boolean]
|
162
152
|
|
163
|
-
|
164
|
-
|
153
|
+
# @!attribute [rw] hide_config_values
|
154
|
+
# @return [Boolean]
|
165
155
|
|
166
|
-
|
156
|
+
def database_url=(val)
|
157
|
+
super URI(val.to_s)
|
167
158
|
end
|
168
159
|
|
169
160
|
#
|
170
161
|
# @return [Array<String>]
|
171
162
|
#
|
172
163
|
def keys
|
173
|
-
|
174
|
-
key[1..].to_s.upcase
|
175
|
-
end
|
164
|
+
to_h.keys.map(&:to_s).map(&:upcase)
|
176
165
|
end
|
177
166
|
end
|
178
167
|
end
|
data/lib/mihari/constants.rb
CHANGED
@@ -5,7 +5,7 @@ module Mihari
|
|
5
5
|
DEFAULT_DATA_TYPES = Types::DataTypes.values.freeze
|
6
6
|
|
7
7
|
# @return [Array<Hash>]
|
8
|
-
DEFAULT_EMITTERS =
|
8
|
+
DEFAULT_EMITTERS = Emitters::Database.class_keys.map { |name| { emitter: name } }.freeze
|
9
9
|
|
10
10
|
# @return [Array<Hash>]
|
11
11
|
DEFAULT_ENRICHERS = Mihari.enricher_to_class.keys.map { |name| { enricher: name.downcase } }.freeze
|
data/lib/mihari/database.rb
CHANGED
@@ -13,6 +13,9 @@ def development_env?
|
|
13
13
|
env == "development"
|
14
14
|
end
|
15
15
|
|
16
|
+
#
|
17
|
+
# Mihari v5 DB schema
|
18
|
+
#
|
16
19
|
class V5Schema < ActiveRecord::Migration[7.1]
|
17
20
|
def change
|
18
21
|
create_table :rules, id: :string, if_not_exists: true do |t|
|
@@ -125,6 +128,9 @@ def schemas
|
|
125
128
|
end
|
126
129
|
|
127
130
|
module Mihari
|
131
|
+
#
|
132
|
+
# Database
|
133
|
+
#
|
128
134
|
class Database
|
129
135
|
class << self
|
130
136
|
#
|
data/lib/mihari/emitters/base.rb
CHANGED
@@ -2,52 +2,43 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# @return [Array<Mihari::Artifact>]
|
12
|
-
attr_reader :artifacts
|
13
|
-
|
14
|
-
# @return [Mihari::Services::Rule]
|
5
|
+
#
|
6
|
+
# Base class for emitters
|
7
|
+
#
|
8
|
+
class Base < Actor
|
9
|
+
# @return [Mihari::Rule]
|
15
10
|
attr_reader :rule
|
16
11
|
|
17
12
|
#
|
18
|
-
# @param [
|
19
|
-
# @param [Mihari::Services::RuleProxy] rule
|
13
|
+
# @param [Mihari::Rule] rule
|
20
14
|
# @param [Hash, nil] options
|
21
|
-
# @param [Hash] **_params
|
22
15
|
#
|
23
|
-
def initialize(
|
16
|
+
def initialize(rule:, options: nil)
|
24
17
|
super(options: options)
|
25
18
|
|
26
|
-
@artifacts = artifacts
|
27
19
|
@rule = rule
|
28
20
|
end
|
29
21
|
|
30
|
-
#
|
31
|
-
|
22
|
+
#
|
23
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
24
|
+
#
|
25
|
+
def call(artifacts)
|
32
26
|
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
33
27
|
end
|
34
28
|
|
35
|
-
|
29
|
+
#
|
30
|
+
# @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
|
31
|
+
#
|
32
|
+
def result(artifacts)
|
36
33
|
Try[StandardError] do
|
37
34
|
retry_on_error(
|
38
35
|
times: retry_times,
|
39
36
|
interval: retry_interval,
|
40
37
|
exponential_backoff: retry_exponential_backoff
|
41
|
-
)
|
42
|
-
emit
|
43
|
-
end
|
38
|
+
) { call(artifacts) }
|
44
39
|
end.to_result
|
45
40
|
end
|
46
41
|
|
47
|
-
def emit
|
48
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
49
|
-
end
|
50
|
-
|
51
42
|
class << self
|
52
43
|
def inherited(child)
|
53
44
|
super
|
@@ -2,23 +2,24 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
+
#
|
6
|
+
# Database emitter
|
7
|
+
#
|
5
8
|
class Database < Base
|
6
|
-
def valid?
|
7
|
-
configured?
|
8
|
-
end
|
9
|
-
|
10
9
|
#
|
11
10
|
# Create an alert
|
12
11
|
#
|
13
|
-
# @
|
12
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
13
|
+
#
|
14
|
+
# @return [Mihari::Models::Alert, nil]
|
14
15
|
#
|
15
|
-
def
|
16
|
+
def call(artifacts)
|
16
17
|
return if artifacts.empty?
|
17
18
|
|
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) }
|
19
|
+
tags = rule.tags.filter_map { |name| Models::Tag.find_or_create_by(name: name) }.uniq
|
20
|
+
taggings = tags.map { |tag| Models::Tagging.new(tag_id: tag.id) }
|
20
21
|
|
21
|
-
alert = Alert.new(artifacts: artifacts, taggings: taggings, rule_id: rule.id)
|
22
|
+
alert = Models::Alert.new(artifacts: artifacts, taggings: taggings, rule_id: rule.id)
|
22
23
|
alert.save
|
23
24
|
alert
|
24
25
|
end
|