mihari 5.6.2 → 5.7.1
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/lib/mihari/actor.rb +18 -2
- 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 +9 -16
- data/lib/mihari/commands/database.rb +3 -0
- data/lib/mihari/commands/rule.rb +10 -1
- data/lib/mihari/commands/search.rb +13 -29
- 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 +11 -9
- data/lib/mihari/enrichers/shodan.rb +4 -6
- data/lib/mihari/enrichers/whois.rb +12 -9
- data/lib/mihari/entities/tag.rb +1 -0
- 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 +31 -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 +26 -0
- data/lib/mihari/services/alert_builder.rb +85 -9
- data/lib/mihari/services/alert_runner.rb +8 -19
- data/lib/mihari/services/rule_builder.rb +13 -12
- data/lib/mihari/services/rule_runner.rb +7 -32
- data/lib/mihari/structs/binaryedge.rb +22 -28
- data/lib/mihari/structs/censys.rb +48 -141
- data/lib/mihari/structs/config.rb +19 -30
- data/lib/mihari/structs/filters.rb +38 -0
- data/lib/mihari/structs/fofa.rb +47 -0
- data/lib/mihari/structs/google_public_dns.rb +10 -32
- data/lib/mihari/structs/greynoise.rb +33 -90
- data/lib/mihari/structs/hunterhow.rb +24 -28
- data/lib/mihari/structs/ipinfo.rb +14 -37
- data/lib/mihari/structs/onyphe.rb +31 -80
- data/lib/mihari/structs/shodan.rb +47 -114
- data/lib/mihari/structs/urlscan.rb +24 -69
- data/lib/mihari/structs/virustotal_intelligence.rb +20 -64
- 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 +64 -56
- data/lib/mihari/web/endpoints/alerts.rb +127 -85
- data/lib/mihari/web/endpoints/artifacts.rb +91 -79
- data/lib/mihari/web/endpoints/configs.rb +18 -13
- data/lib/mihari/web/endpoints/ip_addresses.rb +35 -15
- data/lib/mihari/web/endpoints/rules.rb +236 -187
- data/lib/mihari/web/endpoints/tags.rb +42 -35
- 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-07fafab5.js} +31 -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 -6
- data/mihari.gemspec +9 -2
- data/mkdocs.yml +4 -2
- metadata +38 -133
- data/docs/alternatives.md +0 -5
- data/docs/analyzers/binaryedge.md +0 -26
- data/docs/analyzers/censys.md +0 -31
- data/docs/analyzers/circl.md +0 -37
- data/docs/analyzers/crtsh.md +0 -26
- data/docs/analyzers/dnstwister.md +0 -25
- data/docs/analyzers/feed.md +0 -73
- data/docs/analyzers/greynoise.md +0 -26
- data/docs/analyzers/hunterhow.md +0 -33
- data/docs/analyzers/index.md +0 -103
- data/docs/analyzers/onyphe.md +0 -26
- data/docs/analyzers/otx.md +0 -28
- data/docs/analyzers/passivetotal.md +0 -52
- data/docs/analyzers/pulsedive.md +0 -28
- data/docs/analyzers/securitytrails.md +0 -41
- data/docs/analyzers/shodan.md +0 -26
- data/docs/analyzers/urlscan.md +0 -28
- data/docs/analyzers/virustotal.md +0 -43
- data/docs/analyzers/virustotal_intelligence.md +0 -33
- data/docs/analyzers/zoomeye.md +0 -38
- data/docs/configuration.md +0 -35
- data/docs/emitters/database.md +0 -22
- data/docs/emitters/hive.md +0 -26
- data/docs/emitters/index.md +0 -36
- data/docs/emitters/misp.md +0 -21
- data/docs/emitters/slack.md +0 -21
- data/docs/emitters/webhook.md +0 -63
- data/docs/enrichers/google_public_dns.md +0 -19
- data/docs/enrichers/index.md +0 -35
- data/docs/enrichers/ipinfo.md +0 -26
- data/docs/enrichers/shodan.md +0 -22
- data/docs/enrichers/whois.md +0 -17
- data/docs/github_actions.md +0 -43
- data/docs/index.md +0 -11
- data/docs/installation.md +0 -31
- data/docs/requirements.md +0 -13
- data/docs/rule.md +0 -168
- data/docs/tags.md +0 -3
- data/docs/usage.md +0 -103
- data/frontend/.eslintrc.cjs +0 -22
- data/frontend/.gitignore +0 -31
- data/frontend/.prettierrc.json +0 -8
- data/frontend/README.md +0 -3
- data/frontend/env.d.ts +0 -5
- data/frontend/index.html +0 -21
- data/frontend/package-lock.json +0 -7219
- data/frontend/package.json +0 -67
- data/frontend/public/favicon.ico +0 -0
- data/frontend/scripts/swagger_doc_to_yaml.rb +0 -23
- data/frontend/src/App.vue +0 -27
- data/frontend/src/ace-config.ts +0 -6
- data/frontend/src/api-helper.ts +0 -111
- data/frontend/src/api.ts +0 -105
- data/frontend/src/components/ErrorMessage.vue +0 -31
- data/frontend/src/components/Loading.vue +0 -15
- data/frontend/src/components/Navbar.vue +0 -42
- data/frontend/src/components/Pagination.vue +0 -119
- data/frontend/src/components/alert/Alert.vue +0 -87
- data/frontend/src/components/alert/Alerts.vue +0 -63
- data/frontend/src/components/alert/AlertsWithPagination.vue +0 -90
- data/frontend/src/components/alert/AlertsWrapper.vue +0 -128
- data/frontend/src/components/alert/Form.vue +0 -182
- data/frontend/src/components/artifact/AS.vue +0 -29
- data/frontend/src/components/artifact/Artifact.vue +0 -287
- data/frontend/src/components/artifact/ArtifactTag.vue +0 -64
- data/frontend/src/components/artifact/ArtifactTags.vue +0 -29
- data/frontend/src/components/artifact/ArtifactWrapper.vue +0 -57
- data/frontend/src/components/artifact/CPEs.vue +0 -23
- data/frontend/src/components/artifact/DnsRecords.vue +0 -38
- data/frontend/src/components/artifact/Ports.vue +0 -23
- data/frontend/src/components/artifact/ReverseDnsNames.vue +0 -31
- data/frontend/src/components/artifact/Tags.vue +0 -29
- data/frontend/src/components/artifact/WhoisRecord.vue +0 -44
- data/frontend/src/components/config/Configs.vue +0 -65
- data/frontend/src/components/config/ConfigsWrapper.vue +0 -32
- data/frontend/src/components/link/Link.vue +0 -32
- data/frontend/src/components/link/Links.vue +0 -42
- data/frontend/src/components/rule/EditRule.vue +0 -72
- data/frontend/src/components/rule/EditRuleWrapper.vue +0 -48
- data/frontend/src/components/rule/Form.vue +0 -158
- data/frontend/src/components/rule/InputForm.vue +0 -45
- data/frontend/src/components/rule/NewRule.vue +0 -57
- data/frontend/src/components/rule/Rule.vue +0 -100
- data/frontend/src/components/rule/RuleWrapper.vue +0 -53
- data/frontend/src/components/rule/Rules.vue +0 -84
- data/frontend/src/components/rule/RulesWrapper.vue +0 -121
- data/frontend/src/components/rule/YAML.vue +0 -37
- data/frontend/src/components/tag/Tag.vue +0 -65
- data/frontend/src/components/tag/Tags.vue +0 -37
- data/frontend/src/countries.ts +0 -350
- data/frontend/src/index.ts +0 -20
- data/frontend/src/links/anyrun.ts +0 -19
- data/frontend/src/links/base.ts +0 -14
- data/frontend/src/links/censys.ts +0 -20
- data/frontend/src/links/crtsh.ts +0 -20
- data/frontend/src/links/dnslytics.ts +0 -38
- data/frontend/src/links/greynoise.ts +0 -20
- data/frontend/src/links/index.ts +0 -40
- data/frontend/src/links/intezer.ts +0 -20
- data/frontend/src/links/otx.ts +0 -33
- data/frontend/src/links/securitytrails.ts +0 -38
- data/frontend/src/links/shodan.ts +0 -20
- data/frontend/src/links/urlscan.ts +0 -50
- data/frontend/src/links/virustotal.ts +0 -72
- data/frontend/src/main.ts +0 -41
- data/frontend/src/router/index.ts +0 -57
- data/frontend/src/rule.ts +0 -14
- data/frontend/src/shims-vue.d.ts +0 -6
- data/frontend/src/swagger.yaml +0 -771
- data/frontend/src/types.ts +0 -188
- data/frontend/src/utils.ts +0 -54
- data/frontend/src/views/Alerts.vue +0 -20
- data/frontend/src/views/Artifact.vue +0 -39
- data/frontend/src/views/Configs.vue +0 -20
- data/frontend/src/views/EditRule.vue +0 -39
- data/frontend/src/views/NewRule.vue +0 -26
- data/frontend/src/views/Rule.vue +0 -39
- data/frontend/src/views/Rules.vue +0 -20
- data/frontend/tests/utils.spec.ts +0 -9
- data/frontend/tsconfig.app.json +0 -21
- data/frontend/tsconfig.json +0 -14
- data/frontend/tsconfig.node.json +0 -13
- data/frontend/tsconfig.vitest.json +0 -12
- data/frontend/vite.config.ts +0 -24
- data/frontend/vitest.config.ts +0 -21
- data/lib/mihari/services/alert_proxy.rb +0 -92
- data/lib/mihari/templates/rule.yml.erb +0 -5
- data/lib/mihari/web/public/assets/mode-yaml-a21faa53.js +0 -8
@@ -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/entities/tag.rb
CHANGED
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|
|
@@ -4,6 +4,9 @@ require "normalize_country"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Models
|
7
|
+
#
|
8
|
+
# Geolocation model
|
9
|
+
#
|
7
10
|
class Geolocation < ActiveRecord::Base
|
8
11
|
belongs_to :artifact
|
9
12
|
|
@@ -19,7 +22,7 @@ module Mihari
|
|
19
22
|
# @return [Mihari::Geolocation, nil]
|
20
23
|
#
|
21
24
|
def build_by_ip(ip, enricher: Enrichers::IPInfo.new)
|
22
|
-
result = enricher.
|
25
|
+
result = enricher.result(ip).bind do |res|
|
23
26
|
value = res&.country_code
|
24
27
|
if value.nil?
|
25
28
|
Success nil
|
data/lib/mihari/models/port.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Models
|
5
|
+
#
|
6
|
+
# Port model
|
7
|
+
#
|
5
8
|
class Port < ActiveRecord::Base
|
6
9
|
belongs_to :artifact
|
7
10
|
|
@@ -17,7 +20,7 @@ module Mihari
|
|
17
20
|
# @return [Array<Mihari::Port>]
|
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
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Models
|
5
|
+
#
|
6
|
+
# Reverse DNS name model
|
7
|
+
#
|
5
8
|
class ReverseDnsName < ActiveRecord::Base
|
6
9
|
belongs_to :artifact
|
7
10
|
|
@@ -17,7 +20,7 @@ module Mihari
|
|
17
20
|
# @return [Array<Mihari::Models::ReverseDnsName>]
|
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/rule.rb
CHANGED
@@ -4,6 +4,9 @@ require "yaml"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Models
|
7
|
+
#
|
8
|
+
# Rule model
|
9
|
+
#
|
7
10
|
class Rule < ActiveRecord::Base
|
8
11
|
has_many :alerts, dependent: :destroy
|
9
12
|
|
@@ -23,7 +26,7 @@ module Mihari
|
|
23
26
|
#
|
24
27
|
# Search rules
|
25
28
|
#
|
26
|
-
# @param [Structs::Filters::Rule::SearchFilterWithPagination] filter
|
29
|
+
# @param [Mihari::Structs::Filters::Rule::SearchFilterWithPagination] filter
|
27
30
|
#
|
28
31
|
# @return [Array<Rule>]
|
29
32
|
#
|
@@ -46,7 +49,7 @@ module Mihari
|
|
46
49
|
#
|
47
50
|
# Count alerts
|
48
51
|
#
|
49
|
-
# @param [Structs::Filters::Rule::SearchFilterWithPagination] filter
|
52
|
+
# @param [Mihari::Structs::Filters::Rule::SearchFilterWithPagination] filter
|
50
53
|
#
|
51
54
|
# @return [Integer]
|
52
55
|
#
|
@@ -58,7 +61,7 @@ module Mihari
|
|
58
61
|
private
|
59
62
|
|
60
63
|
#
|
61
|
-
# @param [Structs::Filters::Rule::SearchFilter] filter
|
64
|
+
# @param [Mihari::Structs::Filters::Rule::SearchFilter] filter
|
62
65
|
#
|
63
66
|
# @return [Mihari::Models::Rule]
|
64
67
|
#
|
data/lib/mihari/models/tag.rb
CHANGED
data/lib/mihari/models/whois.rb
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Models
|
5
|
+
#
|
6
|
+
# Whois record model
|
7
|
+
#
|
5
8
|
class WhoisRecord < ActiveRecord::Base
|
6
9
|
belongs_to :artifact
|
7
10
|
|
8
11
|
@memo = {}
|
9
12
|
|
10
13
|
class << self
|
11
|
-
include Dry::Monads[:result]
|
12
|
-
|
13
14
|
#
|
14
15
|
# Build whois record
|
15
16
|
#
|
@@ -19,7 +20,7 @@ module Mihari
|
|
19
20
|
# @return [WhoisRecord, nil]
|
20
21
|
#
|
21
22
|
def build_by_domain(domain, enricher: Enrichers::Whois.new)
|
22
|
-
result = enricher.
|
23
|
+
result = enricher.result(domain)
|
23
24
|
result.value_or nil
|
24
25
|
end
|
25
26
|
end
|
data/lib/mihari/rule.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Mihari
|
4
|
-
class Rule
|
4
|
+
class Rule < Service
|
5
5
|
include Mixins::FalsePositive
|
6
6
|
|
7
7
|
# @return [Hash]
|
@@ -19,6 +19,8 @@ module Mihari
|
|
19
19
|
# @param [Hash] data
|
20
20
|
#
|
21
21
|
def initialize(**data)
|
22
|
+
super()
|
23
|
+
|
22
24
|
@data = data.deep_symbolize_keys
|
23
25
|
@errors = nil
|
24
26
|
@base_time = Time.now.utc
|
@@ -109,16 +111,19 @@ module Mihari
|
|
109
111
|
#
|
110
112
|
def artifacts
|
111
113
|
analyzers.flat_map do |analyzer|
|
114
|
+
# @type [Dry::Monads::Result::Success<Array<Mihari::Models::Artifact>>, Dry::Monads::Result::Failure]
|
112
115
|
result = analyzer.result
|
113
116
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
if result.failure?
|
118
|
+
raise result.failure unless analyzer.ignore_error?
|
119
|
+
else
|
120
|
+
artifacts = result.value!
|
121
|
+
artifacts.map do |artifact|
|
122
|
+
artifact.rule_id = id
|
123
|
+
artifact
|
124
|
+
end
|
120
125
|
end
|
121
|
-
end
|
126
|
+
end.compact
|
122
127
|
end
|
123
128
|
|
124
129
|
#
|
@@ -169,7 +174,7 @@ module Mihari
|
|
169
174
|
|
170
175
|
# NOTE: separate parallel execution and logging
|
171
176
|
# because the logger does not work along with Parallel
|
172
|
-
results = Parallel.map(emitters) { |emitter| emitter.
|
177
|
+
results = Parallel.map(emitters) { |emitter| emitter.result enriched_artifacts }
|
173
178
|
results.zip(emitters).map do |result_and_emitter|
|
174
179
|
result, emitter = result_and_emitter
|
175
180
|
Mihari.logger.info "Emission by #{emitter.class} is failed: #{result.failure}" if result.failure?
|
@@ -183,7 +188,7 @@ module Mihari
|
|
183
188
|
#
|
184
189
|
# @return [Mihari::Models::Alert, nil]
|
185
190
|
#
|
186
|
-
def
|
191
|
+
def call
|
187
192
|
# Validate analyzers & emitters before using them
|
188
193
|
analyzers
|
189
194
|
emitters
|
@@ -213,13 +218,27 @@ module Mihari
|
|
213
218
|
)
|
214
219
|
end
|
215
220
|
|
221
|
+
#
|
222
|
+
# @return [Boolean]
|
223
|
+
#
|
224
|
+
def diff?
|
225
|
+
model = Mihari::Models::Rule.find(id)
|
226
|
+
model.data != data.deep_stringify_keys
|
227
|
+
rescue ActiveRecord::RecordNotFound
|
228
|
+
false
|
229
|
+
end
|
230
|
+
|
231
|
+
def update_or_create
|
232
|
+
model.save
|
233
|
+
end
|
234
|
+
|
216
235
|
class << self
|
217
236
|
#
|
218
237
|
# Load rule from YAML string
|
219
238
|
#
|
220
239
|
# @param [String] yaml
|
221
240
|
#
|
222
|
-
# @return [Mihari::
|
241
|
+
# @return [Mihari::Rule]
|
223
242
|
#
|
224
243
|
def from_yaml(yaml)
|
225
244
|
data = YAML.safe_load(ERB.new(yaml).result, permitted_classes: [Date, Symbol])
|
@@ -229,7 +248,7 @@ module Mihari
|
|
229
248
|
#
|
230
249
|
# @param [Mihari::Models::Rule] model
|
231
250
|
#
|
232
|
-
# @return [Mihari::
|
251
|
+
# @return [Mihari::Rule]
|
233
252
|
#
|
234
253
|
def from_model(model)
|
235
254
|
new(**model.data)
|
data/lib/mihari/schemas/alert.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Schemas
|
5
|
+
#
|
6
|
+
# Analyzer schemas
|
7
|
+
#
|
5
8
|
module Analyzers
|
6
9
|
extend Schemas::Mixins
|
7
10
|
|
@@ -61,6 +64,14 @@ module Mihari
|
|
61
64
|
optional(:options).hash(AnalyzerOptions)
|
62
65
|
end
|
63
66
|
|
67
|
+
Fofa = Dry::Schema.Params do
|
68
|
+
required(:analyzer).value(Types::String.enum(*Mihari::Analyzers::Fofa.class_keys))
|
69
|
+
required(:query).value(:string)
|
70
|
+
optional(:api_key).value(:string)
|
71
|
+
optional(:email).value(:string)
|
72
|
+
optional(:options).hash(AnalyzerPaginationOptions)
|
73
|
+
end
|
74
|
+
|
64
75
|
PassiveTotal = Dry::Schema.Params do
|
65
76
|
required(:analyzer).value(Types::String.enum(*Mihari::Analyzers::PassiveTotal.class_keys))
|
66
77
|
required(:query).value(:string)
|