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
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mihari
|
2
|
+
#
|
3
|
+
# Base class for services
|
4
|
+
#
|
5
|
+
class Service
|
6
|
+
include Dry::Monads[:result, :try]
|
7
|
+
|
8
|
+
def call(*args, **kwargs)
|
9
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def result(...)
|
13
|
+
Try[StandardError] { call(...) }.to_result
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
def call(...)
|
18
|
+
new.call(...)
|
19
|
+
end
|
20
|
+
|
21
|
+
def result(...)
|
22
|
+
new.result(...)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -8,21 +8,91 @@ require "yaml"
|
|
8
8
|
|
9
9
|
module Mihari
|
10
10
|
module Services
|
11
|
-
|
12
|
-
|
11
|
+
#
|
12
|
+
# Alert proxy
|
13
|
+
#
|
14
|
+
class AlertProxy
|
15
|
+
# @return [Hash]
|
16
|
+
attr_reader :data
|
13
17
|
|
14
|
-
# @return [
|
15
|
-
attr_reader :
|
18
|
+
# @return [Array, nil]
|
19
|
+
attr_reader :errors
|
16
20
|
|
17
21
|
#
|
18
22
|
# Initialize
|
19
23
|
#
|
20
|
-
# @param [
|
24
|
+
# @param [Hash] data
|
21
25
|
#
|
22
|
-
def initialize(
|
23
|
-
|
26
|
+
def initialize(**data)
|
27
|
+
super()
|
28
|
+
|
29
|
+
@data = data.deep_symbolize_keys
|
30
|
+
@errors = nil
|
31
|
+
|
32
|
+
validate!
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# @return [Boolean]
|
37
|
+
#
|
38
|
+
def errors?
|
39
|
+
return false if @errors.nil?
|
40
|
+
|
41
|
+
!@errors.empty?
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate!
|
45
|
+
contract = Schemas::AlertContract.new
|
46
|
+
result = contract.call(data)
|
47
|
+
|
48
|
+
@data = result.to_h
|
49
|
+
@errors = result.errors
|
50
|
+
|
51
|
+
raise ValidationError.new("Validation failed", errors) if errors?
|
52
|
+
end
|
53
|
+
|
54
|
+
def [](key)
|
55
|
+
data key.to_sym
|
56
|
+
end
|
57
|
+
|
58
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
#
|
61
|
+
def rule_id
|
62
|
+
@rule_id ||= data[:rule_id]
|
63
|
+
end
|
64
|
+
|
65
|
+
#
|
66
|
+
# @return [Array<Mihari::Models::Artifact>]
|
67
|
+
#
|
68
|
+
def artifacts
|
69
|
+
@artifacts ||= data[:artifacts].map do |data|
|
70
|
+
artifact = Models::Artifact.new(data: data)
|
71
|
+
artifact.rule_id = rule_id
|
72
|
+
artifact
|
73
|
+
end.uniq(&:data).select(&:valid?)
|
24
74
|
end
|
25
75
|
|
76
|
+
#
|
77
|
+
# @return [Mihari::Rule]
|
78
|
+
#
|
79
|
+
def rule
|
80
|
+
@rule ||= [].tap do |out|
|
81
|
+
data = Mihari::Models::Rule.find(rule_id).data
|
82
|
+
out << Rule.new(**data)
|
83
|
+
end.first
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Alert builder
|
89
|
+
#
|
90
|
+
class AlertBuilder < Service
|
91
|
+
# @return [String]
|
92
|
+
attr_reader :path
|
93
|
+
|
94
|
+
#
|
95
|
+
# @param [String] path
|
26
96
|
#
|
27
97
|
# @return [Hash]
|
28
98
|
#
|
@@ -35,8 +105,14 @@ module Mihari
|
|
35
105
|
)
|
36
106
|
end
|
37
107
|
|
38
|
-
|
39
|
-
|
108
|
+
#
|
109
|
+
# @param [String] path
|
110
|
+
#
|
111
|
+
# @return [Mihari::AlertProxy]
|
112
|
+
#
|
113
|
+
def call(path)
|
114
|
+
@path = path
|
115
|
+
AlertProxy.new(**data)
|
40
116
|
end
|
41
117
|
end
|
42
118
|
end
|
@@ -2,29 +2,18 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Services
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(alert)
|
12
|
-
@alert = alert
|
13
|
-
end
|
14
|
-
|
5
|
+
#
|
6
|
+
# Alert runner
|
7
|
+
#
|
8
|
+
class AlertRunner < Service
|
9
|
+
#
|
10
|
+
# @param [Mihari::Services::AlertProxy] alert
|
15
11
|
#
|
16
12
|
# @return [Mihari::Models::Alert]
|
17
13
|
#
|
18
|
-
def
|
14
|
+
def call(alert)
|
19
15
|
emitter = Emitters::Database.new(rule: alert.rule)
|
20
|
-
emitter.
|
21
|
-
end
|
22
|
-
|
23
|
-
#
|
24
|
-
# @return [Dry::Monads::Result::Success<Mihari::Models::Alert, nil>, Dry::Monads::Result::Failure]
|
25
|
-
#
|
26
|
-
def result
|
27
|
-
Try[StandardError] { run }.to_result
|
16
|
+
emitter.call alert.artifacts
|
28
17
|
end
|
29
18
|
end
|
30
19
|
end
|
@@ -7,21 +7,15 @@ require "yaml"
|
|
7
7
|
|
8
8
|
module Mihari
|
9
9
|
module Services
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
#
|
11
|
+
# Rule builder
|
12
|
+
#
|
13
|
+
class RuleBuilder < Service
|
13
14
|
# @return [String]
|
14
15
|
attr_reader :path_or_id
|
15
16
|
|
16
|
-
#
|
17
|
-
# Initialize
|
18
17
|
#
|
19
18
|
# @param [String] path_or_id
|
20
|
-
#
|
21
|
-
def initialize(path_or_id)
|
22
|
-
@path_or_id = path_or_id
|
23
|
-
end
|
24
|
-
|
25
19
|
#
|
26
20
|
# @return [Hash]
|
27
21
|
#
|
@@ -39,8 +33,15 @@ module Mihari
|
|
39
33
|
)
|
40
34
|
end
|
41
35
|
|
42
|
-
|
43
|
-
|
36
|
+
#
|
37
|
+
# @param [String] path_or_id
|
38
|
+
#
|
39
|
+
# @return [Mihari::Rule]
|
40
|
+
#
|
41
|
+
def call(path_or_id)
|
42
|
+
@path_or_id = path_or_id
|
43
|
+
|
44
|
+
Rule.new(**data)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
@@ -2,42 +2,17 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Services
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
attr_reader :rule
|
10
|
-
|
11
|
-
def initialize(rule)
|
12
|
-
@rule = rule
|
13
|
-
end
|
14
|
-
|
5
|
+
#
|
6
|
+
# Rule runner
|
7
|
+
#
|
8
|
+
class RuleRunner < Service
|
15
9
|
#
|
16
|
-
# @
|
17
|
-
#
|
18
|
-
def diff?
|
19
|
-
model = Mihari::Models::Rule.find(rule.id)
|
20
|
-
model.data != rule.data.deep_stringify_keys
|
21
|
-
rescue ActiveRecord::RecordNotFound
|
22
|
-
false
|
23
|
-
end
|
24
|
-
|
25
|
-
def update_or_create
|
26
|
-
rule.model.save
|
27
|
-
end
|
28
|
-
|
10
|
+
# @params [Mihari::Rule]
|
29
11
|
#
|
30
12
|
# @return [Mihari::Models::Alert, nil]
|
31
13
|
#
|
32
|
-
def
|
33
|
-
rule.
|
34
|
-
end
|
35
|
-
|
36
|
-
#
|
37
|
-
# @return [Dry::Monads::Result::Success<Mihari::Models::Alert, nil>, Dry::Monads::Result::Failure]
|
38
|
-
#
|
39
|
-
def result
|
40
|
-
Try[StandardError] { run }.to_result
|
14
|
+
def call(rule)
|
15
|
+
rule.call
|
41
16
|
end
|
42
17
|
end
|
43
18
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Mihari
|
2
4
|
module Structs
|
3
5
|
module BinaryEdge
|
4
6
|
class Target < Dry::Struct
|
7
|
+
# @!attribute [r] ip
|
8
|
+
# @return [String]
|
5
9
|
attribute :ip, Types::String
|
6
10
|
|
7
|
-
#
|
8
|
-
# @return [String]
|
9
|
-
#
|
10
|
-
def ip
|
11
|
-
attributes[:ip]
|
12
|
-
end
|
13
|
-
|
14
11
|
class << self
|
12
|
+
#
|
13
|
+
# @param [Hash] d
|
14
|
+
#
|
15
15
|
def from_dynamic!(d)
|
16
16
|
d = Types::Hash[d]
|
17
17
|
new(
|
@@ -22,16 +22,14 @@ module Mihari
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class Event < Dry::Struct
|
25
|
+
# @!attribute [r] target
|
26
|
+
# @return [Target]
|
25
27
|
attribute :target, Target
|
26
28
|
|
27
|
-
#
|
28
|
-
# @return [Target]
|
29
|
-
#
|
30
|
-
def target
|
31
|
-
attributes[:target]
|
32
|
-
end
|
33
|
-
|
34
29
|
class << self
|
30
|
+
#
|
31
|
+
# @param [Hash] d
|
32
|
+
#
|
35
33
|
def from_dynamic!(d)
|
36
34
|
d = Types::Hash[d]
|
37
35
|
new(
|
@@ -43,28 +41,21 @@ module Mihari
|
|
43
41
|
|
44
42
|
class Response < Dry::Struct
|
45
43
|
# @!attribute [r] page
|
46
|
-
#
|
47
|
-
attribute :page, Types::
|
44
|
+
# @return [Integer]
|
45
|
+
attribute :page, Types::Int
|
48
46
|
|
49
47
|
# @!attribute [r] pagesize
|
50
|
-
#
|
51
|
-
attribute :pagesize, Types::
|
48
|
+
# @return [Integer]
|
49
|
+
attribute :pagesize, Types::Int
|
52
50
|
|
53
51
|
# @!attribute [r] total
|
54
|
-
#
|
55
|
-
attribute :total, Types::
|
52
|
+
# @return [Integer]
|
53
|
+
attribute :total, Types::Int
|
56
54
|
|
57
55
|
# @!attribute [r] events
|
58
|
-
#
|
56
|
+
# @return [Array<Event>]
|
59
57
|
attribute :events, Types.Array(Event)
|
60
58
|
|
61
|
-
#
|
62
|
-
# @return [Array<Event>]
|
63
|
-
#
|
64
|
-
def events
|
65
|
-
attributes[:events]
|
66
|
-
end
|
67
|
-
|
68
59
|
#
|
69
60
|
# @return [Array<Artifact>]
|
70
61
|
#
|
@@ -73,6 +64,9 @@ module Mihari
|
|
73
64
|
end
|
74
65
|
|
75
66
|
class << self
|
67
|
+
#
|
68
|
+
# @param [Hash] d
|
69
|
+
#
|
76
70
|
def from_dynamic!(d)
|
77
71
|
d = Types::Hash[d]
|
78
72
|
new(
|
@@ -6,15 +6,10 @@ module Mihari
|
|
6
6
|
class AutonomousSystem < Dry::Struct
|
7
7
|
include Mixins::AutonomousSystem
|
8
8
|
|
9
|
+
# @!attribute [r] asn
|
10
|
+
# @return [Integer]
|
9
11
|
attribute :asn, Types::Int
|
10
12
|
|
11
|
-
#
|
12
|
-
# @return [Integer]
|
13
|
-
#
|
14
|
-
def asn
|
15
|
-
attributes[:asn]
|
16
|
-
end
|
17
|
-
|
18
13
|
#
|
19
14
|
# @return [Mihari::AutonomousSystem]
|
20
15
|
#
|
@@ -26,8 +21,6 @@ module Mihari
|
|
26
21
|
#
|
27
22
|
# @param [Hash] d
|
28
23
|
#
|
29
|
-
# @return [AutonomousSystem]
|
30
|
-
#
|
31
24
|
def from_dynamic!(d)
|
32
25
|
d = Types::Hash[d]
|
33
26
|
new(
|
@@ -38,22 +31,13 @@ module Mihari
|
|
38
31
|
end
|
39
32
|
|
40
33
|
class Location < Dry::Struct
|
34
|
+
# @!attribute [r] country
|
35
|
+
# @return [String, nil]
|
41
36
|
attribute :country, Types::String.optional
|
42
|
-
attribute :country_code, Types::String.optional
|
43
37
|
|
44
|
-
#
|
45
|
-
#
|
46
|
-
|
47
|
-
def country
|
48
|
-
attributes[:country]
|
49
|
-
end
|
50
|
-
|
51
|
-
#
|
52
|
-
# @return [String, nil]
|
53
|
-
#
|
54
|
-
def country_code
|
55
|
-
attributes[:country_code]
|
56
|
-
end
|
38
|
+
# @!attribute [r] country_code
|
39
|
+
# @return [String, nil]
|
40
|
+
attribute :country_code, Types::String.optional
|
57
41
|
|
58
42
|
#
|
59
43
|
# @return [Mihari::Geolocation] <description>
|
@@ -73,8 +57,6 @@ module Mihari
|
|
73
57
|
#
|
74
58
|
# @param [Hash] d
|
75
59
|
#
|
76
|
-
# @return [Location]
|
77
|
-
#
|
78
60
|
def from_dynamic!(d)
|
79
61
|
d = Types::Hash[d]
|
80
62
|
new(
|
@@ -86,14 +68,9 @@ module Mihari
|
|
86
68
|
end
|
87
69
|
|
88
70
|
class Service < Dry::Struct
|
89
|
-
attribute
|
90
|
-
|
91
|
-
|
92
|
-
# @return [Integer]
|
93
|
-
#
|
94
|
-
def port
|
95
|
-
attributes[:port]
|
96
|
-
end
|
71
|
+
# @!attribute [r] port
|
72
|
+
# @return [Integer, nil]
|
73
|
+
attribute :port, Types::Int
|
97
74
|
|
98
75
|
#
|
99
76
|
# @return [Mihari::Port]
|
@@ -106,8 +83,6 @@ module Mihari
|
|
106
83
|
#
|
107
84
|
# @param [Hash] d
|
108
85
|
#
|
109
|
-
# @return [Service]
|
110
|
-
#
|
111
86
|
def from_dynamic!(d)
|
112
87
|
d = Types::Hash[d]
|
113
88
|
new(
|
@@ -118,46 +93,25 @@ module Mihari
|
|
118
93
|
end
|
119
94
|
|
120
95
|
class Hit < Dry::Struct
|
96
|
+
# @!attribute [r] ip
|
97
|
+
# @return [String]
|
121
98
|
attribute :ip, Types::String
|
122
|
-
attribute :location, Location
|
123
|
-
attribute :autonomous_system, AutonomousSystem
|
124
|
-
attribute :metadata, Types::Hash
|
125
|
-
attribute :services, Types.Array(Service)
|
126
|
-
|
127
|
-
#
|
128
|
-
# @return [String]
|
129
|
-
#
|
130
|
-
def ip
|
131
|
-
attributes[:ip]
|
132
|
-
end
|
133
99
|
|
134
|
-
#
|
135
|
-
#
|
136
|
-
|
137
|
-
def location
|
138
|
-
attributes[:location]
|
139
|
-
end
|
100
|
+
# @!attribute [r] location
|
101
|
+
# @return [Location]
|
102
|
+
attribute :location, Location
|
140
103
|
|
141
|
-
#
|
142
|
-
#
|
143
|
-
|
144
|
-
def autonomous_system
|
145
|
-
attributes[:autonomous_system]
|
146
|
-
end
|
104
|
+
# @!attribute [r] autonomous_system
|
105
|
+
# @return [AutonomousSystem]
|
106
|
+
attribute :autonomous_system, AutonomousSystem
|
147
107
|
|
148
|
-
#
|
149
|
-
#
|
150
|
-
|
151
|
-
def metadata
|
152
|
-
attributes[:metadata]
|
153
|
-
end
|
108
|
+
# @!attribute [r] metadata
|
109
|
+
# @return [Hash]
|
110
|
+
attribute :metadata, Types::Hash
|
154
111
|
|
155
|
-
#
|
156
|
-
#
|
157
|
-
|
158
|
-
def services
|
159
|
-
attributes[:services]
|
160
|
-
end
|
112
|
+
# @!attribute [r] services
|
113
|
+
# @return [Array<Service>]
|
114
|
+
attribute :services, Types.Array(Service)
|
161
115
|
|
162
116
|
#
|
163
117
|
# @return [Array<Mihari::Port>]
|
@@ -183,8 +137,6 @@ module Mihari
|
|
183
137
|
#
|
184
138
|
# @param [Hash] d
|
185
139
|
#
|
186
|
-
# @return [Hit]
|
187
|
-
#
|
188
140
|
def from_dynamic!(d)
|
189
141
|
d = Types::Hash[d]
|
190
142
|
new(
|
@@ -199,29 +151,18 @@ module Mihari
|
|
199
151
|
end
|
200
152
|
|
201
153
|
class Links < Dry::Struct
|
154
|
+
# @!attribute [r] next
|
155
|
+
# @return [String, nil]
|
202
156
|
attribute :next, Types::String.optional
|
203
|
-
attribute :prev, Types::String.optional
|
204
|
-
|
205
|
-
#
|
206
|
-
# @return [String, nil]
|
207
|
-
#
|
208
|
-
def next
|
209
|
-
attributes[:next]
|
210
|
-
end
|
211
157
|
|
212
|
-
#
|
213
|
-
#
|
214
|
-
|
215
|
-
def prev
|
216
|
-
attributes[:prev]
|
217
|
-
end
|
158
|
+
# @!attribute [r] prev
|
159
|
+
# @return [String, nil]
|
160
|
+
attribute :prev, Types::String.optional
|
218
161
|
|
219
162
|
class << self
|
220
163
|
#
|
221
164
|
# @param [Hash] d
|
222
165
|
#
|
223
|
-
# @return [Links]
|
224
|
-
#
|
225
166
|
def from_dynamic!(d)
|
226
167
|
d = Types::Hash[d]
|
227
168
|
new(
|
@@ -233,38 +174,21 @@ module Mihari
|
|
233
174
|
end
|
234
175
|
|
235
176
|
class Result < Dry::Struct
|
177
|
+
# @!attribute [r] query
|
178
|
+
# @return [String]
|
236
179
|
attribute :query, Types::String
|
237
|
-
attribute :total, Types::Int
|
238
|
-
attribute :hits, Types.Array(Hit)
|
239
|
-
attribute :links, Links
|
240
|
-
|
241
|
-
#
|
242
|
-
# @return [String]
|
243
|
-
#
|
244
|
-
def query
|
245
|
-
attributes[:query]
|
246
|
-
end
|
247
180
|
|
248
|
-
#
|
249
|
-
#
|
250
|
-
|
251
|
-
def total
|
252
|
-
attributes[:total]
|
253
|
-
end
|
181
|
+
# @!attribute [r] total
|
182
|
+
# @return [Integer]
|
183
|
+
attribute :total, Types::Int
|
254
184
|
|
255
|
-
#
|
256
|
-
#
|
257
|
-
|
258
|
-
def hits
|
259
|
-
attributes[:hits]
|
260
|
-
end
|
185
|
+
# @!attribute [r] hits
|
186
|
+
# @return [Array<Hit>]
|
187
|
+
attribute :hits, Types.Array(Hit)
|
261
188
|
|
262
|
-
#
|
263
|
-
#
|
264
|
-
|
265
|
-
def links
|
266
|
-
attributes[:links]
|
267
|
-
end
|
189
|
+
# @!attribute [r] links
|
190
|
+
# @return [Links]
|
191
|
+
attribute :links, Links
|
268
192
|
|
269
193
|
#
|
270
194
|
# @return [Array<Mihari::Models::Artifact>]
|
@@ -277,8 +201,6 @@ module Mihari
|
|
277
201
|
#
|
278
202
|
# @param [Hash] d
|
279
203
|
#
|
280
|
-
# @return [Result]
|
281
|
-
#
|
282
204
|
def from_dynamic!(d)
|
283
205
|
d = Types::Hash[d]
|
284
206
|
new(
|
@@ -292,37 +214,22 @@ module Mihari
|
|
292
214
|
end
|
293
215
|
|
294
216
|
class Response < Dry::Struct
|
217
|
+
# @!attribute [r] code
|
218
|
+
# @return [Integer]
|
295
219
|
attribute :code, Types::Int
|
296
|
-
attribute :status, Types::String
|
297
|
-
attribute :result, Result
|
298
|
-
|
299
|
-
#
|
300
|
-
# @return [Integer]
|
301
|
-
#
|
302
|
-
def code
|
303
|
-
attributes[:code]
|
304
|
-
end
|
305
220
|
|
306
|
-
#
|
307
|
-
#
|
308
|
-
|
309
|
-
def status
|
310
|
-
attributes[:status]
|
311
|
-
end
|
221
|
+
# @!attribute [r] status
|
222
|
+
# @return [String]
|
223
|
+
attribute :status, Types::String
|
312
224
|
|
313
|
-
#
|
314
|
-
#
|
315
|
-
|
316
|
-
def result
|
317
|
-
attributes[:result]
|
318
|
-
end
|
225
|
+
# @!attribute [r] result
|
226
|
+
# @return [Result]
|
227
|
+
attribute :result, Result
|
319
228
|
|
320
229
|
class << self
|
321
230
|
#
|
322
231
|
# @param [Hash] d
|
323
232
|
#
|
324
|
-
# @return [Response]
|
325
|
-
#
|
326
233
|
def from_dynamic!(d)
|
327
234
|
d = Types::Hash[d]
|
328
235
|
new(
|