mihari 5.6.2 → 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 +73 -73
- data/frontend/package.json +5 -5
- 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/actor.rb +14 -4
- data/lib/mihari/analyzers/base.rb +13 -12
- data/lib/mihari/analyzers/binaryedge.rb +4 -1
- data/lib/mihari/analyzers/censys.rb +4 -2
- 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 +6 -1
- data/lib/mihari/analyzers/onyphe.rb +4 -1
- data/lib/mihari/analyzers/otx.rb +4 -1
- data/lib/mihari/analyzers/passivetotal.rb +4 -1
- data/lib/mihari/analyzers/pulsedive.rb +3 -0
- data/lib/mihari/analyzers/securitytrails.rb +4 -1
- data/lib/mihari/analyzers/shodan.rb +4 -1
- data/lib/mihari/analyzers/urlscan.rb +4 -1
- data/lib/mihari/analyzers/virustotal.rb +4 -1
- data/lib/mihari/analyzers/virustotal_intelligence.rb +4 -1
- data/lib/mihari/analyzers/zoomeye.rb +5 -2
- 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 +3 -0
- 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 +3 -0
- data/lib/mihari/clients/publsedive.rb +4 -1
- data/lib/mihari/clients/securitytrails.rb +3 -0
- 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 +10 -1
- 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 +13 -11
- data/lib/mihari/emitters/database.rb +4 -1
- data/lib/mihari/emitters/misp.rb +7 -4
- data/lib/mihari/emitters/slack.rb +3 -3
- data/lib/mihari/emitters/the_hive.rb +3 -3
- data/lib/mihari/emitters/webhook.rb +4 -3
- data/lib/mihari/enrichers/base.rb +15 -9
- 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 +12 -9
- 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 +7 -4
- data/lib/mihari/models/artifact.rb +6 -0
- data/lib/mihari/models/autonomous_system.rb +4 -1
- data/lib/mihari/models/cpe.rb +4 -1
- data/lib/mihari/models/dns.rb +4 -1
- data/lib/mihari/models/geolocation.rb +4 -1
- data/lib/mihari/models/port.rb +4 -1
- data/lib/mihari/models/reverse_dns.rb +4 -1
- data/lib/mihari/models/rule.rb +6 -3
- data/lib/mihari/models/tag.rb +3 -0
- data/lib/mihari/models/tagging.rb +3 -0
- data/lib/mihari/models/whois.rb +4 -3
- data/lib/mihari/rule.rb +17 -12
- data/lib/mihari/schemas/alert.rb +3 -0
- data/lib/mihari/schemas/analyzer.rb +11 -0
- data/lib/mihari/schemas/emitter.rb +3 -0
- data/lib/mihari/schemas/enricher.rb +3 -0
- data/lib/mihari/schemas/macros.rb +4 -0
- data/lib/mihari/schemas/mixins.rb +5 -0
- data/lib/mihari/schemas/rule.rb +3 -0
- data/lib/mihari/service.rb +16 -0
- data/lib/mihari/services/alert_builder.rb +8 -5
- data/lib/mihari/services/alert_proxy.rb +6 -1
- data/lib/mihari/services/alert_runner.rb +8 -12
- data/lib/mihari/services/rule_builder.rb +8 -5
- data/lib/mihari/services/rule_runner.rb +8 -10
- data/lib/mihari/structs/binaryedge.rb +13 -28
- data/lib/mihari/structs/censys.rb +48 -127
- data/lib/mihari/structs/config.rb +19 -30
- 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 +33 -84
- data/lib/mihari/structs/hunterhow.rb +24 -22
- data/lib/mihari/structs/ipinfo.rb +14 -35
- data/lib/mihari/structs/onyphe.rb +31 -76
- data/lib/mihari/structs/shodan.rb +47 -112
- data/lib/mihari/structs/urlscan.rb +24 -63
- data/lib/mihari/structs/virustotal_intelligence.rb +20 -56
- 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 +203 -198
- 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-28d4c79d.js → index-821134e2.js} +30 -30
- 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 +24 -5
- data/mihari.gemspec +8 -1
- data/mkdocs.yml +3 -2
- metadata +39 -7
- data/lib/mihari/templates/rule.yml.erb +0 -5
- data/lib/mihari/web/public/assets/mode-yaml-a21faa53.js +0 -8
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,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
+
#
|
6
|
+
# Base class for emitters
|
7
|
+
#
|
5
8
|
class Base < Actor
|
6
9
|
# @return [Mihari::Rule]
|
7
10
|
attr_reader :rule
|
@@ -9,9 +12,8 @@ module Mihari
|
|
9
12
|
#
|
10
13
|
# @param [Mihari::Rule] rule
|
11
14
|
# @param [Hash, nil] options
|
12
|
-
# @param [Hash] **_params
|
13
15
|
#
|
14
|
-
def initialize(rule:, options: nil
|
16
|
+
def initialize(rule:, options: nil)
|
15
17
|
super(options: options)
|
16
18
|
|
17
19
|
@rule = rule
|
@@ -20,23 +22,23 @@ module Mihari
|
|
20
22
|
#
|
21
23
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
22
24
|
#
|
23
|
-
def
|
25
|
+
def call(artifacts)
|
26
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
|
31
|
+
#
|
32
|
+
def result(artifacts)
|
24
33
|
Try[StandardError] do
|
25
34
|
retry_on_error(
|
26
35
|
times: retry_times,
|
27
36
|
interval: retry_interval,
|
28
37
|
exponential_backoff: retry_exponential_backoff
|
29
|
-
) {
|
38
|
+
) { call(artifacts) }
|
30
39
|
end.to_result
|
31
40
|
end
|
32
41
|
|
33
|
-
#
|
34
|
-
# @param [Array<Mihari::Models::Artifact>] artifacts
|
35
|
-
#
|
36
|
-
def emit(artifacts)
|
37
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
38
|
-
end
|
39
|
-
|
40
42
|
class << self
|
41
43
|
def inherited(child)
|
42
44
|
super
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
+
#
|
6
|
+
# Database emitter
|
7
|
+
#
|
5
8
|
class Database < Base
|
6
9
|
#
|
7
10
|
# Create an alert
|
@@ -10,7 +13,7 @@ module Mihari
|
|
10
13
|
#
|
11
14
|
# @return [Mihari::Models::Alert, nil]
|
12
15
|
#
|
13
|
-
def
|
16
|
+
def call(artifacts)
|
14
17
|
return if artifacts.empty?
|
15
18
|
|
16
19
|
tags = rule.tags.filter_map { |name| Models::Tag.find_or_create_by(name: name) }.uniq
|
data/lib/mihari/emitters/misp.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
+
#
|
6
|
+
# MISP emitter
|
7
|
+
#
|
5
8
|
class MISP < Base
|
6
9
|
# @return [String, nil]
|
7
10
|
attr_reader :url
|
@@ -9,16 +12,16 @@ module Mihari
|
|
9
12
|
# @return [String, nil]
|
10
13
|
attr_reader :api_key
|
11
14
|
|
12
|
-
# @return [Mihari::
|
15
|
+
# @return [Mihari::Rule]
|
13
16
|
attr_reader :rule
|
14
17
|
|
15
18
|
# @return [Array<Mihari::Models::Artifact>]
|
16
19
|
attr_accessor :artifacts
|
17
20
|
|
18
21
|
#
|
19
|
-
# @param [Mihari::
|
22
|
+
# @param [Mihari::Rule] rule
|
20
23
|
# @param [Hash, nil] options
|
21
|
-
# @param [Hash]
|
24
|
+
# @param [Hash, nil] params
|
22
25
|
#
|
23
26
|
def initialize(rule:, options: nil, **params)
|
24
27
|
super(rule: rule, options: options)
|
@@ -41,7 +44,7 @@ module Mihari
|
|
41
44
|
#
|
42
45
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
43
46
|
#
|
44
|
-
def
|
47
|
+
def call(artifacts)
|
45
48
|
return if artifacts.empty?
|
46
49
|
|
47
50
|
client.create_event({
|
@@ -135,9 +135,9 @@ module Mihari
|
|
135
135
|
attr_accessor :artifacts
|
136
136
|
|
137
137
|
#
|
138
|
-
# @param [Mihari::
|
138
|
+
# @param [Mihari::Rule] rule
|
139
139
|
# @param [Hash, nil] options
|
140
|
-
# @param [Hash]
|
140
|
+
# @param [Hash, nil] params
|
141
141
|
#
|
142
142
|
def initialize(rule:, options: nil, **params)
|
143
143
|
super(rule: rule, options: options)
|
@@ -216,7 +216,7 @@ module Mihari
|
|
216
216
|
#
|
217
217
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
218
218
|
#
|
219
|
-
def
|
219
|
+
def call(artifacts)
|
220
220
|
return if artifacts.empty?
|
221
221
|
|
222
222
|
@artifacts = artifacts
|
@@ -16,9 +16,9 @@ module Mihari
|
|
16
16
|
attr_accessor :artifacts
|
17
17
|
|
18
18
|
#
|
19
|
-
# @param [Mihari::
|
19
|
+
# @param [Mihari::Rule] rule
|
20
20
|
# @param [Hash, nil] options
|
21
|
-
# @param [Hash]
|
21
|
+
# @param [Hash] params
|
22
22
|
#
|
23
23
|
def initialize(rule:, options: nil, **params)
|
24
24
|
super(rule: rule, options: options)
|
@@ -42,7 +42,7 @@ module Mihari
|
|
42
42
|
#
|
43
43
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
44
44
|
#
|
45
|
-
def
|
45
|
+
def call(artifacts)
|
46
46
|
return if artifacts.empty?
|
47
47
|
|
48
48
|
@artifacts = artifacts
|
@@ -61,8 +61,9 @@ module Mihari
|
|
61
61
|
attr_accessor :artifacts
|
62
62
|
|
63
63
|
#
|
64
|
-
# @param [Mihari::
|
65
|
-
# @param [Hash]
|
64
|
+
# @param [Mihari::Rule] rule
|
65
|
+
# @param [Hash, nil] options
|
66
|
+
# @param [Hash, nil] params
|
66
67
|
#
|
67
68
|
def initialize(rule:, options: nil, **params)
|
68
69
|
super(rule: rule, options: options)
|
@@ -87,7 +88,7 @@ module Mihari
|
|
87
88
|
#
|
88
89
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
89
90
|
#
|
90
|
-
def
|
91
|
+
def call(artifacts)
|
91
92
|
return if artifacts.empty?
|
92
93
|
|
93
94
|
@artifacts = artifacts
|
@@ -2,28 +2,34 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Enrichers
|
5
|
+
#
|
6
|
+
# Base class for enrichers
|
7
|
+
#
|
5
8
|
class Base < Actor
|
6
9
|
def initialize(options: nil)
|
7
10
|
super(options: options)
|
8
11
|
end
|
9
12
|
|
10
|
-
|
13
|
+
#
|
14
|
+
# @param [String] value
|
15
|
+
#
|
16
|
+
def call(value)
|
17
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
|
22
|
+
#
|
23
|
+
def result(value)
|
11
24
|
Try[StandardError] do
|
12
25
|
retry_on_error(
|
13
26
|
times: retry_times,
|
14
27
|
interval: retry_interval,
|
15
28
|
exponential_backoff: retry_exponential_backoff
|
16
|
-
) {
|
29
|
+
) { call value }
|
17
30
|
end.to_result
|
18
31
|
end
|
19
32
|
|
20
|
-
#
|
21
|
-
# @param [String] value
|
22
|
-
#
|
23
|
-
def query(value)
|
24
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
25
|
-
end
|
26
|
-
|
27
33
|
class << self
|
28
34
|
def inherited(child)
|
29
35
|
super
|
@@ -1,18 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "net/https"
|
4
|
-
|
5
3
|
module Mihari
|
6
4
|
module Enrichers
|
5
|
+
#
|
6
|
+
# Google Public DNS enricher
|
7
|
+
#
|
7
8
|
class GooglePublicDNS < Base
|
8
9
|
#
|
9
10
|
# Query Google Public DNS
|
10
11
|
#
|
11
12
|
# @param [String] name
|
12
13
|
#
|
13
|
-
# @return [Array<Mihari::Structs::
|
14
|
+
# @return [Array<Mihari::Structs::GooglePublicDNS::Response>]
|
14
15
|
#
|
15
|
-
def
|
16
|
+
def call(name)
|
16
17
|
%w[A AAAA CNAME TXT NS].filter_map do |resource_type|
|
17
18
|
query_by_type(name, resource_type)
|
18
19
|
end
|
@@ -24,7 +25,7 @@ module Mihari
|
|
24
25
|
# @param [String] name
|
25
26
|
# @param [String] resource_type
|
26
27
|
#
|
27
|
-
# @return [Mihari::Structs::
|
28
|
+
# @return [Mihari::Structs::GooglePublicDNS::Response, nil]
|
28
29
|
#
|
29
30
|
def query_by_type(name, resource_type)
|
30
31
|
url = "https://dns.google/resolve"
|
@@ -1,23 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "net/https"
|
4
|
-
|
5
3
|
module Mihari
|
6
4
|
module Enrichers
|
5
|
+
#
|
6
|
+
# IPInfo enricher
|
7
|
+
#
|
7
8
|
class IPInfo < Base
|
8
|
-
include Memist::Memoizable
|
9
|
-
|
10
9
|
# @return [String, nil]
|
11
10
|
attr_reader :api_key
|
12
11
|
|
12
|
+
#
|
13
|
+
# @param [Hash, nil] options
|
14
|
+
# @param [String, nil] api_key
|
15
|
+
#
|
13
16
|
def initialize(options: nil, api_key: nil)
|
14
17
|
@api_key = api_key || Mihari.config.ipinfo_api_key
|
15
18
|
|
16
19
|
super(options: options)
|
17
20
|
end
|
18
21
|
|
19
|
-
private
|
20
|
-
|
21
22
|
def configuration_keys
|
22
23
|
%w[ipinfo_api_key]
|
23
24
|
end
|
@@ -29,14 +30,15 @@ module Mihari
|
|
29
30
|
#
|
30
31
|
# @return [Mihari::Structs::IPInfo::Response, nil]
|
31
32
|
#
|
32
|
-
def
|
33
|
+
def call(ip)
|
33
34
|
url = "https://ipinfo.io/#{ip}/json"
|
34
35
|
res = http.get(url)
|
35
36
|
data = JSON.parse(res.body.to_s)
|
36
37
|
|
37
38
|
Structs::IPInfo::Response.from_dynamic! data
|
38
39
|
end
|
39
|
-
|
40
|
+
|
41
|
+
private
|
40
42
|
|
41
43
|
def headers
|
42
44
|
authorization = api_key.nil? ? nil : "Bearer #{api_key}"
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "net/https"
|
4
|
-
|
5
3
|
module Mihari
|
6
4
|
module Enrichers
|
5
|
+
#
|
6
|
+
# Shodan enricher
|
7
|
+
#
|
7
8
|
class Shodan < Base
|
8
|
-
include Memist::Memoizable
|
9
|
-
|
10
9
|
#
|
11
10
|
# Query Shodan Internet DB
|
12
11
|
#
|
@@ -14,14 +13,13 @@ module Mihari
|
|
14
13
|
#
|
15
14
|
# @return [Mihari::Structs::Shodan::InternetDBResponse, nil]
|
16
15
|
#
|
17
|
-
def
|
16
|
+
def call(ip)
|
18
17
|
url = "https://internetdb.shodan.io/#{ip}"
|
19
18
|
res = http.get(url)
|
20
19
|
data = JSON.parse(res.body.to_s)
|
21
20
|
|
22
21
|
Structs::Shodan::InternetDBResponse.from_dynamic! data
|
23
22
|
end
|
24
|
-
memoize :query
|
25
23
|
|
26
24
|
private
|
27
25
|
|
@@ -4,6 +4,9 @@ require "whois-parser"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Enrichers
|
7
|
+
#
|
8
|
+
# Whois enricher
|
9
|
+
#
|
7
10
|
class Whois < Base
|
8
11
|
# @return [Hash]
|
9
12
|
attr_accessor :memo
|
@@ -20,11 +23,11 @@ module Mihari
|
|
20
23
|
#
|
21
24
|
# Query IAIA Whois API
|
22
25
|
#
|
23
|
-
# @param [String]
|
26
|
+
# @param [String] domain
|
24
27
|
#
|
25
|
-
# @return [Mihari::WhoisRecord, nil]
|
28
|
+
# @return [Mihari::Models::WhoisRecord, nil]
|
26
29
|
#
|
27
|
-
def
|
30
|
+
def call(domain)
|
28
31
|
domain = PublicSuffix.domain(domain)
|
29
32
|
|
30
33
|
# check memo
|
@@ -71,7 +74,7 @@ module Mihari
|
|
71
74
|
#
|
72
75
|
# Get created_on
|
73
76
|
#
|
74
|
-
# @param [::Whois::Parser
|
77
|
+
# @param [::Whois::Parser] parser
|
75
78
|
#
|
76
79
|
# @return [Date, nil]
|
77
80
|
#
|
@@ -84,7 +87,7 @@ module Mihari
|
|
84
87
|
#
|
85
88
|
# Get updated_on
|
86
89
|
#
|
87
|
-
# @param [::Whois::Parser
|
90
|
+
# @param [::Whois::Parser] parser
|
88
91
|
#
|
89
92
|
# @return [Date, nil]
|
90
93
|
#
|
@@ -97,7 +100,7 @@ module Mihari
|
|
97
100
|
#
|
98
101
|
# Get expires_on
|
99
102
|
#
|
100
|
-
# @param [::Whois::Parser
|
103
|
+
# @param [::Whois::Parser] parser
|
101
104
|
#
|
102
105
|
# @return [Date, nil]
|
103
106
|
#
|
@@ -110,7 +113,7 @@ module Mihari
|
|
110
113
|
#
|
111
114
|
# Get registrar
|
112
115
|
#
|
113
|
-
# @param [::Whois::Parser
|
116
|
+
# @param [::Whois::Parser] parser
|
114
117
|
#
|
115
118
|
# @return [Hash, nil]
|
116
119
|
#
|
@@ -123,9 +126,9 @@ module Mihari
|
|
123
126
|
#
|
124
127
|
# Get contacts
|
125
128
|
#
|
126
|
-
# @param [::Whois::Parser
|
129
|
+
# @param [::Whois::Parser] parser
|
127
130
|
#
|
128
|
-
# @return [Array
|
131
|
+
# @return [Array<Hash>, nil]
|
129
132
|
#
|
130
133
|
def get_contacts(parser)
|
131
134
|
parser.contacts.map(&:to_h)
|
data/lib/mihari/errors.rb
CHANGED
@@ -20,6 +20,9 @@ module Mihari
|
|
20
20
|
|
21
21
|
class TimeoutError < HTTPError; end
|
22
22
|
|
23
|
+
#
|
24
|
+
# HTTP status code error
|
25
|
+
#
|
23
26
|
class StatusCodeError < HTTPError
|
24
27
|
# @return [Integer]
|
25
28
|
attr_reader :status_code
|
@@ -40,6 +43,9 @@ module Mihari
|
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
46
|
+
#
|
47
|
+
# (dry-schema) Schema validation error
|
48
|
+
#
|
43
49
|
class ValidationError < Error
|
44
50
|
attr_reader :errors
|
45
51
|
|
data/lib/mihari/feed/parser.rb
CHANGED
data/lib/mihari/feed/reader.rb
CHANGED
data/lib/mihari/http.rb
CHANGED
@@ -4,6 +4,9 @@ require "http"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module HTTP
|
7
|
+
#
|
8
|
+
# Better error handling feature
|
9
|
+
#
|
7
10
|
class BetterError < ::HTTP::Feature
|
8
11
|
def wrap_response(response)
|
9
12
|
unless response.status.success?
|
@@ -24,6 +27,9 @@ module Mihari
|
|
24
27
|
::HTTP::Options.register_feature(:better_error, self)
|
25
28
|
end
|
26
29
|
|
30
|
+
#
|
31
|
+
# HTTP client factory
|
32
|
+
#
|
27
33
|
class Factory
|
28
34
|
class << self
|
29
35
|
#
|
data/lib/mihari/mixins/refang.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Mixins
|
5
|
+
#
|
6
|
+
# Retriable mixin
|
7
|
+
#
|
5
8
|
module Retriable
|
6
9
|
DEFAULT_ON = [
|
7
10
|
Errno::ECONNRESET,
|
@@ -11,8 +14,9 @@ module Mihari
|
|
11
14
|
Timeout::Error,
|
12
15
|
RetryableError,
|
13
16
|
NetworkError,
|
14
|
-
TimeoutError
|
15
|
-
|
17
|
+
TimeoutError,
|
18
|
+
StatusCodeError
|
19
|
+
].freeze
|
16
20
|
|
17
21
|
#
|
18
22
|
# Retry on error
|
data/lib/mihari/models/alert.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Models
|
5
|
+
#
|
6
|
+
# Alert model
|
7
|
+
#
|
5
8
|
class Alert < ActiveRecord::Base
|
6
9
|
has_many :taggings, dependent: :destroy
|
7
10
|
has_many :artifacts, dependent: :destroy
|
@@ -13,7 +16,7 @@ module Mihari
|
|
13
16
|
#
|
14
17
|
# Search alerts
|
15
18
|
#
|
16
|
-
# @param [Structs::Filters::Alert::SearchFilterWithPagination] filter
|
19
|
+
# @param [Mihari::Structs::Filters::Alert::SearchFilterWithPagination] filter
|
17
20
|
#
|
18
21
|
# @return [Array<Alert>]
|
19
22
|
#
|
@@ -35,7 +38,7 @@ module Mihari
|
|
35
38
|
#
|
36
39
|
# Count alerts
|
37
40
|
#
|
38
|
-
# @param [
|
41
|
+
# @param [Mihari::Structs::Filters::Alert::SearchFilter] filter
|
39
42
|
#
|
40
43
|
# @return [Integer]
|
41
44
|
#
|
@@ -47,7 +50,7 @@ module Mihari
|
|
47
50
|
private
|
48
51
|
|
49
52
|
#
|
50
|
-
# @param [Structs::Filters::Alert::SearchFilter] filter
|
53
|
+
# @param [Mihari::Structs::Filters::Alert::SearchFilter] filter
|
51
54
|
#
|
52
55
|
# @return [Array<Integer>]
|
53
56
|
#
|
@@ -65,7 +68,7 @@ module Mihari
|
|
65
68
|
end
|
66
69
|
|
67
70
|
#
|
68
|
-
# @param [Structs::Filters::Alert::SearchFilter] filter
|
71
|
+
# @param [Mihari::Structs::Filters::Alert::SearchFilter] filter
|
69
72
|
#
|
70
73
|
# @return [Mihari::Models::Alert]
|
71
74
|
#
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Models
|
5
|
+
#
|
6
|
+
# Artifact validator
|
7
|
+
#
|
5
8
|
class ArtifactValidator < ActiveModel::Validator
|
6
9
|
def validate(record)
|
7
10
|
return if record.data_type
|
@@ -10,6 +13,9 @@ module Mihari
|
|
10
13
|
end
|
11
14
|
end
|
12
15
|
|
16
|
+
#
|
17
|
+
# Artifact model
|
18
|
+
#
|
13
19
|
class Artifact < ActiveRecord::Base
|
14
20
|
belongs_to :alert
|
15
21
|
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Models
|
5
|
+
#
|
6
|
+
# AS model
|
7
|
+
#
|
5
8
|
class AutonomousSystem < ActiveRecord::Base
|
6
9
|
belongs_to :artifact
|
7
10
|
|
@@ -17,7 +20,7 @@ module Mihari
|
|
17
20
|
# @return [Mihari::AutonomousSystem, nil]
|
18
21
|
#
|
19
22
|
def build_by_ip(ip, enricher: Enrichers::IPInfo.new)
|
20
|
-
result = enricher.
|
23
|
+
result = enricher.result(ip).bind do |res|
|
21
24
|
value = res&.asn
|
22
25
|
if value.nil?
|
23
26
|
Success nil
|
data/lib/mihari/models/cpe.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Models
|
5
|
+
#
|
6
|
+
# CPE model
|
7
|
+
#
|
5
8
|
class CPE < ActiveRecord::Base
|
6
9
|
belongs_to :artifact
|
7
10
|
|
@@ -17,7 +20,7 @@ module Mihari
|
|
17
20
|
# @return [Array<Mihari::CPE>]
|
18
21
|
#
|
19
22
|
def build_by_ip(ip, enricher: Enrichers::Shodan.new)
|
20
|
-
result = enricher.
|
23
|
+
result = enricher.result(ip).bind do |res|
|
21
24
|
if res.nil?
|
22
25
|
Success []
|
23
26
|
else
|
data/lib/mihari/models/dns.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Models
|
5
|
+
#
|
6
|
+
# DNS record model
|
7
|
+
#
|
5
8
|
class DnsRecord < ActiveRecord::Base
|
6
9
|
belongs_to :artifact
|
7
10
|
|
@@ -17,7 +20,7 @@ module Mihari
|
|
17
20
|
# @return [Array<Mihari::Models::DnsRecord>]
|
18
21
|
#
|
19
22
|
def build_by_domain(domain, enricher: Enrichers::GooglePublicDNS.new)
|
20
|
-
result = enricher.
|
23
|
+
result = enricher.result(domain).bind do |responses|
|
21
24
|
Success(
|
22
25
|
responses.map do |res|
|
23
26
|
res.answers.map do |answer|
|