mihari 5.6.1 → 5.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/README.md +1 -0
  4. data/config.ru +1 -1
  5. data/docs/analyzers/fofa.md +31 -0
  6. data/docs/analyzers/index.md +1 -0
  7. data/frontend/package-lock.json +183 -186
  8. data/frontend/package.json +10 -10
  9. data/frontend/src/components/alert/Form.vue +1 -14
  10. data/frontend/src/components/artifact/AS.vue +2 -8
  11. data/frontend/src/components/artifact/DnsRecords.vue +2 -8
  12. data/frontend/src/components/artifact/ReverseDnsNames.vue +2 -10
  13. data/frontend/src/components/artifact/WhoisRecord.vue +1 -1
  14. data/lib/mihari/{base.rb → actor.rb} +27 -3
  15. data/lib/mihari/analyzers/base.rb +16 -20
  16. data/lib/mihari/analyzers/binaryedge.rb +4 -1
  17. data/lib/mihari/analyzers/censys.rb +5 -3
  18. data/lib/mihari/analyzers/circl.rb +4 -1
  19. data/lib/mihari/analyzers/crtsh.rb +4 -1
  20. data/lib/mihari/analyzers/dnstwister.rb +4 -1
  21. data/lib/mihari/analyzers/feed.rb +3 -0
  22. data/lib/mihari/analyzers/fofa.rb +65 -0
  23. data/lib/mihari/analyzers/greynoise.rb +4 -1
  24. data/lib/mihari/analyzers/hunterhow.rb +7 -2
  25. data/lib/mihari/analyzers/onyphe.rb +4 -1
  26. data/lib/mihari/analyzers/otx.rb +4 -1
  27. data/lib/mihari/analyzers/passivetotal.rb +5 -2
  28. data/lib/mihari/analyzers/pulsedive.rb +4 -1
  29. data/lib/mihari/analyzers/securitytrails.rb +5 -2
  30. data/lib/mihari/analyzers/shodan.rb +4 -1
  31. data/lib/mihari/analyzers/urlscan.rb +5 -2
  32. data/lib/mihari/analyzers/virustotal.rb +9 -6
  33. data/lib/mihari/analyzers/virustotal_intelligence.rb +4 -1
  34. data/lib/mihari/analyzers/zoomeye.rb +8 -5
  35. data/lib/mihari/cli/alert.rb +3 -0
  36. data/lib/mihari/cli/base.rb +3 -0
  37. data/lib/mihari/cli/database.rb +3 -0
  38. data/lib/mihari/cli/main.rb +3 -0
  39. data/lib/mihari/cli/rule.rb +3 -0
  40. data/lib/mihari/clients/base.rb +3 -0
  41. data/lib/mihari/clients/binaryedge.rb +5 -2
  42. data/lib/mihari/clients/censys.rb +7 -4
  43. data/lib/mihari/clients/circl.rb +3 -0
  44. data/lib/mihari/clients/crtsh.rb +5 -2
  45. data/lib/mihari/clients/dnstwister.rb +3 -0
  46. data/lib/mihari/clients/fofa.rb +83 -0
  47. data/lib/mihari/clients/greynoise.rb +5 -2
  48. data/lib/mihari/clients/hunterhow.rb +5 -2
  49. data/lib/mihari/clients/misp.rb +3 -0
  50. data/lib/mihari/clients/onyphe.rb +5 -2
  51. data/lib/mihari/clients/otx.rb +3 -0
  52. data/lib/mihari/clients/passivetotal.rb +7 -4
  53. data/lib/mihari/clients/publsedive.rb +4 -1
  54. data/lib/mihari/clients/securitytrails.rb +6 -3
  55. data/lib/mihari/clients/shodan.rb +5 -2
  56. data/lib/mihari/clients/the_hive.rb +3 -0
  57. data/lib/mihari/clients/urlscan.rb +7 -4
  58. data/lib/mihari/clients/virustotal.rb +5 -2
  59. data/lib/mihari/clients/zoomeye.rb +3 -0
  60. data/lib/mihari/commands/alert.rb +5 -14
  61. data/lib/mihari/commands/database.rb +3 -0
  62. data/lib/mihari/commands/rule.rb +11 -11
  63. data/lib/mihari/commands/search.rb +9 -6
  64. data/lib/mihari/commands/version.rb +3 -0
  65. data/lib/mihari/commands/web.rb +4 -1
  66. data/lib/mihari/config.rb +139 -150
  67. data/lib/mihari/constants.rb +1 -1
  68. data/lib/mihari/database.rb +6 -0
  69. data/lib/mihari/emitters/base.rb +16 -25
  70. data/lib/mihari/emitters/database.rb +10 -9
  71. data/lib/mihari/emitters/misp.rb +20 -41
  72. data/lib/mihari/emitters/slack.rb +16 -13
  73. data/lib/mihari/emitters/the_hive.rb +18 -46
  74. data/lib/mihari/emitters/webhook.rb +34 -23
  75. data/lib/mihari/enrichers/base.rb +16 -15
  76. data/lib/mihari/enrichers/google_public_dns.rb +6 -5
  77. data/lib/mihari/enrichers/ipinfo.rb +10 -8
  78. data/lib/mihari/enrichers/shodan.rb +4 -6
  79. data/lib/mihari/enrichers/whois.rb +13 -10
  80. data/lib/mihari/errors.rb +6 -0
  81. data/lib/mihari/feed/parser.rb +3 -0
  82. data/lib/mihari/feed/reader.rb +3 -0
  83. data/lib/mihari/http.rb +6 -0
  84. data/lib/mihari/mixins/autonomous_system.rb +3 -0
  85. data/lib/mihari/mixins/configurable.rb +3 -0
  86. data/lib/mihari/mixins/error_notification.rb +3 -0
  87. data/lib/mihari/mixins/falsepositive.rb +3 -0
  88. data/lib/mihari/mixins/refang.rb +3 -0
  89. data/lib/mihari/mixins/retriable.rb +6 -2
  90. data/lib/mihari/models/alert.rb +78 -73
  91. data/lib/mihari/models/artifact.rb +186 -178
  92. data/lib/mihari/models/autonomous_system.rb +25 -20
  93. data/lib/mihari/models/cpe.rb +24 -19
  94. data/lib/mihari/models/dns.rb +27 -22
  95. data/lib/mihari/models/geolocation.rb +25 -20
  96. data/lib/mihari/models/port.rb +24 -19
  97. data/lib/mihari/models/reverse_dns.rb +24 -19
  98. data/lib/mihari/models/rule.rb +71 -66
  99. data/lib/mihari/models/tag.rb +8 -3
  100. data/lib/mihari/models/tagging.rb +8 -3
  101. data/lib/mihari/models/whois.rb +20 -17
  102. data/lib/mihari/rule.rb +357 -0
  103. data/lib/mihari/schemas/alert.rb +3 -0
  104. data/lib/mihari/schemas/analyzer.rb +105 -87
  105. data/lib/mihari/schemas/emitter.rb +12 -5
  106. data/lib/mihari/schemas/enricher.rb +11 -4
  107. data/lib/mihari/schemas/macros.rb +4 -0
  108. data/lib/mihari/schemas/mixins.rb +20 -0
  109. data/lib/mihari/schemas/rule.rb +6 -10
  110. data/lib/mihari/service.rb +16 -0
  111. data/lib/mihari/services/alert_builder.rb +8 -5
  112. data/lib/mihari/services/alert_proxy.rb +16 -7
  113. data/lib/mihari/services/alert_runner.rb +10 -14
  114. data/lib/mihari/services/rule_builder.rb +10 -7
  115. data/lib/mihari/services/rule_runner.rb +11 -13
  116. data/lib/mihari/structs/binaryedge.rb +14 -29
  117. data/lib/mihari/structs/censys.rb +54 -133
  118. data/lib/mihari/structs/config.rb +20 -31
  119. data/lib/mihari/structs/filters.rb +38 -0
  120. data/lib/mihari/structs/fofa.rb +44 -0
  121. data/lib/mihari/structs/google_public_dns.rb +10 -28
  122. data/lib/mihari/structs/greynoise.rb +38 -89
  123. data/lib/mihari/structs/hunterhow.rb +27 -25
  124. data/lib/mihari/structs/ipinfo.rb +14 -35
  125. data/lib/mihari/structs/onyphe.rb +36 -81
  126. data/lib/mihari/structs/shodan.rb +53 -118
  127. data/lib/mihari/structs/urlscan.rb +27 -66
  128. data/lib/mihari/structs/virustotal_intelligence.rb +23 -59
  129. data/lib/mihari/type_checker.rb +4 -0
  130. data/lib/mihari/types.rb +3 -0
  131. data/lib/mihari/version.rb +1 -1
  132. data/lib/mihari/web/api.rb +15 -10
  133. data/lib/mihari/web/app.rb +59 -54
  134. data/lib/mihari/web/endpoints/alerts.rb +94 -89
  135. data/lib/mihari/web/endpoints/artifacts.rb +115 -110
  136. data/lib/mihari/web/endpoints/configs.rb +18 -13
  137. data/lib/mihari/web/endpoints/ip_addresses.rb +21 -16
  138. data/lib/mihari/web/endpoints/rules.rb +202 -204
  139. data/lib/mihari/web/endpoints/tags.rb +41 -36
  140. data/lib/mihari/web/middleware/connection_adapter.rb +16 -9
  141. data/lib/mihari/web/middleware/error_notification_adapter.rb +17 -10
  142. data/lib/mihari/web/public/assets/{index-9cc489e6.js → index-821134e2.js} +54 -54
  143. data/lib/mihari/web/public/assets/mode-yaml-24faa242.js +8 -0
  144. data/lib/mihari/web/public/index.html +1 -1
  145. data/lib/mihari.rb +30 -13
  146. data/mihari.gemspec +9 -3
  147. data/mkdocs.yml +3 -2
  148. data/requirements.txt +1 -1
  149. metadata +44 -26
  150. data/lib/mihari/analyzers/rule.rb +0 -232
  151. data/lib/mihari/services/rule_proxy.rb +0 -182
  152. data/lib/mihari/templates/rule.yml.erb +0 -5
  153. data/lib/mihari/web/public/assets/mode-yaml-a21faa53.js +0 -8
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Schemas
5
+ #
6
+ # Mixins for schemas
7
+ #
8
+ module Mixins
9
+ def get_or_composition
10
+ schemas = constants.map { |sym| const_get sym }
11
+ return schemas.first if schemas.length <= 1
12
+
13
+ base, *others = schemas
14
+ others.each { |other| base = base.or(other) }
15
+
16
+ base
17
+ end
18
+ end
19
+ end
20
+ end
@@ -21,17 +21,10 @@ module Mihari
21
21
  optional(:created_on).value(:date)
22
22
  optional(:updated_on).value(:date)
23
23
 
24
- required(:queries).value(:array).each do
25
- AnalyzerAPIKey | AnalyzerAPIKeyPagination | Censys | CIRCL | PassiveTotal | ZoomEye | Crtsh | Feed | HunterHow | DNSTwister
26
- end
27
-
28
- optional(:emitters).value(:array).each do
29
- Emitters::Database | Emitters::MISP | Emitters::TheHive | Emitters::Slack | Emitters::Webhook
30
- end.default(DEFAULT_EMITTERS)
24
+ required(:queries).value(:array).each { Analyzer } # rubocop:disable Lint/Void
31
25
 
32
- optional(:enrichers).value(:array).each do
33
- Enrichers::Whois | Enrichers::IPInfo | Enrichers::Shodan | Enrichers::GooglePublicDNS
34
- end.default(DEFAULT_ENRICHERS)
26
+ optional(:emitters).value(:array).each { Emitter }.default(DEFAULT_EMITTERS) # rubocop:disable Lint/Void
27
+ optional(:enrichers).value(:array).each { Enricher }.default(DEFAULT_ENRICHERS) # rubocop:disable Lint/Void
35
28
 
36
29
  optional(:data_types).value(array[Types::DataTypes]).default(Mihari::Types::DataTypes.values)
37
30
  optional(:falsepositives).value(array[:string]).default([])
@@ -40,6 +33,9 @@ module Mihari
40
33
  optional(:artifact_ttl).value(:integer)
41
34
  end
42
35
 
36
+ #
37
+ # Rule schema contract
38
+ #
43
39
  class RuleContract < Dry::Validation::Contract
44
40
  include Mihari::Mixins::FalsePositive
45
41
 
@@ -0,0 +1,16 @@
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
+ end
16
+ end
@@ -8,9 +8,10 @@ require "yaml"
8
8
 
9
9
  module Mihari
10
10
  module Services
11
- class AlertBuilder
12
- include Dry::Monads[:result, :try]
13
-
11
+ #
12
+ # Alert builder
13
+ #
14
+ class AlertBuilder < Service
14
15
  # @return [String]
15
16
  attr_reader :path
16
17
 
@@ -20,6 +21,8 @@ module Mihari
20
21
  # @param [String] path
21
22
  #
22
23
  def initialize(path)
24
+ super()
25
+
23
26
  @path = path
24
27
  end
25
28
 
@@ -35,8 +38,8 @@ module Mihari
35
38
  )
36
39
  end
37
40
 
38
- def result
39
- Try[StandardError] { AlertProxy.new(data) }.to_result
41
+ def call
42
+ AlertProxy.new(**data)
40
43
  end
41
44
  end
42
45
  end
@@ -4,7 +4,10 @@ require "json"
4
4
 
5
5
  module Mihari
6
6
  module Services
7
- class AlertProxy
7
+ #
8
+ # Alert proxy
9
+ #
10
+ class AlertProxy < Service
8
11
  # @return [Hash]
9
12
  attr_reader :data
10
13
 
@@ -16,7 +19,9 @@ module Mihari
16
19
  #
17
20
  # @param [Hash] data
18
21
  #
19
- def initialize(data)
22
+ def initialize(**data)
23
+ super()
24
+
20
25
  @data = data.deep_symbolize_keys
21
26
  @errors = nil
22
27
 
@@ -54,21 +59,24 @@ module Mihari
54
59
  end
55
60
 
56
61
  #
57
- # @return [Array<Mihari::Artifact>]
62
+ # @return [Array<Mihari::Models::Artifact>]
58
63
  #
59
64
  def artifacts
60
65
  @artifacts ||= data[:artifacts].map do |data|
61
- artifact = Artifact.new(data: data)
66
+ artifact = Models::Artifact.new(data: data)
62
67
  artifact.rule_id = rule_id
63
68
  artifact
64
69
  end.uniq(&:data).select(&:valid?)
65
70
  end
66
71
 
67
72
  #
68
- # @return [Mihari::Services::RuleProxy]
73
+ # @return [Mihari::Rule]
69
74
  #
70
75
  def rule
71
- @rule ||= Services::RuleProxy.new(Mihari::Rule.find(rule_id).data)
76
+ @rule ||= [].tap do |out|
77
+ data = Mihari::Models::Rule.find(rule_id).data
78
+ out << Rule.new(**data)
79
+ end.first
72
80
  end
73
81
 
74
82
  class << self
@@ -80,7 +88,8 @@ module Mihari
80
88
  # @return [Mihari::Services::Alert]
81
89
  #
82
90
  def from_yaml(yaml)
83
- new YAML.safe_load(yaml, permitted_classes: [Date, Symbol])
91
+ data = YAML.safe_load(yaml, permitted_classes: [Date, Symbol])
92
+ new(**data)
84
93
  end
85
94
  end
86
95
  end
@@ -2,29 +2,25 @@
2
2
 
3
3
  module Mihari
4
4
  module Services
5
- class AlertRunner
6
- include Dry::Monads[:result, :try]
7
-
5
+ #
6
+ # Alert runner
7
+ #
8
+ class AlertRunner < Service
8
9
  # @return [Mihari::Services::AlertProxy]
9
10
  attr_reader :alert
10
11
 
11
12
  def initialize(alert)
12
- @alert = alert
13
- end
13
+ super()
14
14
 
15
- #
16
- # @return [Mihari::Alert]
17
- #
18
- def run
19
- emitter = Emitters::Database.new(artifacts: alert.artifacts, rule: alert.rule)
20
- emitter.emit
15
+ @alert = alert
21
16
  end
22
17
 
23
18
  #
24
- # @return [Dry::Monads::Result::Success<Mihari::Alert, nil>, Dry::Monads::Result::Failure]
19
+ # @return [Mihari::Models::Alert]
25
20
  #
26
- def result
27
- Try[StandardError] { run }.to_result
21
+ def call
22
+ emitter = Emitters::Database.new(rule: alert.rule)
23
+ emitter.call alert.artifacts
28
24
  end
29
25
  end
30
26
  end
@@ -7,9 +7,10 @@ require "yaml"
7
7
 
8
8
  module Mihari
9
9
  module Services
10
- class RuleBuilder
11
- include Dry::Monads[:result, :try]
12
-
10
+ #
11
+ # Rule builder
12
+ #
13
+ class RuleBuilder < Service
13
14
  # @return [String]
14
15
  attr_reader :path_or_id
15
16
 
@@ -19,6 +20,8 @@ module Mihari
19
20
  # @param [String] path_or_id
20
21
  #
21
22
  def initialize(path_or_id)
23
+ super()
24
+
22
25
  @path_or_id = path_or_id
23
26
  end
24
27
 
@@ -26,8 +29,8 @@ module Mihari
26
29
  # @return [Hash]
27
30
  #
28
31
  def data
29
- if Mihari::Rule.exists?(path_or_id)
30
- rule = Mihari::Rule.find(path_or_id)
32
+ if Mihari::Models::Rule.exists?(path_or_id)
33
+ rule = Mihari::Models::Rule.find(path_or_id)
31
34
  return rule.data
32
35
  end
33
36
 
@@ -39,8 +42,8 @@ module Mihari
39
42
  )
40
43
  end
41
44
 
42
- def result
43
- Try[StandardError] { RuleProxy.new(data) }.to_result
45
+ def call
46
+ Rule.new(**data)
44
47
  end
45
48
  end
46
49
  end
@@ -2,13 +2,18 @@
2
2
 
3
3
  module Mihari
4
4
  module Services
5
- class RuleRunner
5
+ #
6
+ # Rule runner
7
+ #
8
+ class RuleRunner < Service
6
9
  include Dry::Monads[:result, :try]
7
10
 
8
- # @return [Mihari::Services::RuleProxy]
11
+ # @return [Mihari::Rule]
9
12
  attr_reader :rule
10
13
 
11
14
  def initialize(rule)
15
+ super()
16
+
12
17
  @rule = rule
13
18
  end
14
19
 
@@ -16,7 +21,7 @@ module Mihari
16
21
  # @return [Boolean]
17
22
  #
18
23
  def diff?
19
- model = Mihari::Rule.find(rule.id)
24
+ model = Mihari::Models::Rule.find(rule.id)
20
25
  model.data != rule.data.deep_stringify_keys
21
26
  rescue ActiveRecord::RecordNotFound
22
27
  false
@@ -27,17 +32,10 @@ module Mihari
27
32
  end
28
33
 
29
34
  #
30
- # @return [Mihari::Alert, nil]
31
- #
32
- def run
33
- rule.analyzer.run
34
- end
35
-
36
- #
37
- # @return [Dry::Monads::Result::Success<Mihari::Alert, nil>, Dry::Monads::Result::Failure]
35
+ # @return [Mihari::Models::Alert, nil]
38
36
  #
39
- def result
40
- Try[StandardError] { run }.to_result
37
+ def call
38
+ rule.call
41
39
  end
42
40
  end
43
41
  end
@@ -1,16 +1,13 @@
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
15
12
  def from_dynamic!(d)
16
13
  d = Types::Hash[d]
@@ -22,15 +19,10 @@ module Mihari
22
19
  end
23
20
 
24
21
  class Event < Dry::Struct
22
+ # @!attribute [r] target
23
+ # @return [Target]
25
24
  attribute :target, Target
26
25
 
27
- #
28
- # @return [Target]
29
- #
30
- def target
31
- attributes[:target]
32
- end
33
-
34
26
  class << self
35
27
  def from_dynamic!(d)
36
28
  d = Types::Hash[d]
@@ -43,33 +35,26 @@ module Mihari
43
35
 
44
36
  class Response < Dry::Struct
45
37
  # @!attribute [r] page
46
- # @return [Integer]
47
- attribute :page, Types::Integer
38
+ # @return [Integer]
39
+ attribute :page, Types::Int
48
40
 
49
41
  # @!attribute [r] pagesize
50
- # @return [Integer]
51
- attribute :pagesize, Types::Integer
42
+ # @return [Integer]
43
+ attribute :pagesize, Types::Int
52
44
 
53
45
  # @!attribute [r] total
54
- # @return [Integer]
55
- attribute :total, Types::Integer
46
+ # @return [Integer]
47
+ attribute :total, Types::Int
56
48
 
57
49
  # @!attribute [r] events
58
- # @return [Array<Event>]
50
+ # @return [Array<Event>]
59
51
  attribute :events, Types.Array(Event)
60
52
 
61
- #
62
- # @return [Array<Event>]
63
- #
64
- def events
65
- attributes[:events]
66
- end
67
-
68
53
  #
69
54
  # @return [Array<Artifact>]
70
55
  #
71
56
  def artifacts
72
- events.map { |event| Artifact.new(data: event.target.ip) }
57
+ events.map { |event| Models::Artifact.new(data: event.target.ip) }
73
58
  end
74
59
 
75
60
  class << self
@@ -6,20 +6,15 @@ 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
  #
21
16
  def as
22
- Mihari::AutonomousSystem.new(asn: normalize_asn(asn))
17
+ Mihari::Models::AutonomousSystem.new(asn: normalize_asn(asn))
23
18
  end
24
19
 
25
20
  class << self
@@ -38,22 +33,13 @@ module Mihari
38
33
  end
39
34
 
40
35
  class Location < Dry::Struct
36
+ # @!attribute [r] country
37
+ # @return [String, nil]
41
38
  attribute :country, Types::String.optional
42
- attribute :country_code, Types::String.optional
43
39
 
44
- #
45
- # @return [String, nil]
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
40
+ # @!attribute [r] country_code
41
+ # @return [String, nil]
42
+ attribute :country_code, Types::String.optional
57
43
 
58
44
  #
59
45
  # @return [Mihari::Geolocation] <description>
@@ -63,7 +49,7 @@ module Mihari
63
49
  # then set geolocation as nil
64
50
  return nil if country.nil?
65
51
 
66
- Mihari::Geolocation.new(
52
+ Mihari::Models::Geolocation.new(
67
53
  country: country,
68
54
  country_code: country_code
69
55
  )
@@ -86,20 +72,15 @@ module Mihari
86
72
  end
87
73
 
88
74
  class Service < Dry::Struct
89
- attribute :port, Types::Integer
90
-
91
- #
92
- # @return [Integer]
93
- #
94
- def port
95
- attributes[:port]
96
- end
75
+ # @!attribute [r] port
76
+ # @return [Integer, nil]
77
+ attribute :port, Types::Int
97
78
 
98
79
  #
99
80
  # @return [Mihari::Port]
100
81
  #
101
82
  def _port
102
- Port.new(port: port)
83
+ Models::Port.new(port: port)
103
84
  end
104
85
 
105
86
  class << self
@@ -118,46 +99,25 @@ module Mihari
118
99
  end
119
100
 
120
101
  class Hit < Dry::Struct
102
+ # @!attribute [r] ip
103
+ # @return [String]
121
104
  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
105
 
127
- #
128
- # @return [String]
129
- #
130
- def ip
131
- attributes[:ip]
132
- end
133
-
134
- #
135
- # @return [Location]
136
- #
137
- def location
138
- attributes[:location]
139
- end
106
+ # @!attribute [r] location
107
+ # @return [Location]
108
+ attribute :location, Location
140
109
 
141
- #
142
- # @return [AutonomousSystem]
143
- #
144
- def autonomous_system
145
- attributes[:autonomous_system]
146
- end
110
+ # @!attribute [r] autonomous_system
111
+ # @return [AutonomousSystem]
112
+ attribute :autonomous_system, AutonomousSystem
147
113
 
148
- #
149
- # @return [Hash]
150
- #
151
- def metadata
152
- attributes[:metadata]
153
- end
114
+ # @!attribute [r] metadata
115
+ # @return [Hash]
116
+ attribute :metadata, Types::Hash
154
117
 
155
- #
156
- # @return [Array<Service>]
157
- #
158
- def services
159
- attributes[:services]
160
- end
118
+ # @!attribute [r] services
119
+ # @return [Array<Service>]
120
+ attribute :services, Types.Array(Service)
161
121
 
162
122
  #
163
123
  # @return [Array<Mihari::Port>]
@@ -167,10 +127,10 @@ module Mihari
167
127
  end
168
128
 
169
129
  #
170
- # @return [Mihari::Artifact]
130
+ # @return [Mihari::Models::Artifact]
171
131
  #
172
132
  def artifact
173
- Artifact.new(
133
+ Models::Artifact.new(
174
134
  data: ip,
175
135
  metadata: metadata,
176
136
  autonomous_system: autonomous_system.as,
@@ -199,22 +159,13 @@ module Mihari
199
159
  end
200
160
 
201
161
  class Links < Dry::Struct
162
+ # @!attribute [r] next
163
+ # @return [String, nil]
202
164
  attribute :next, Types::String.optional
203
- attribute :prev, Types::String.optional
204
165
 
205
- #
206
- # @return [String, nil]
207
- #
208
- def next
209
- attributes[:next]
210
- end
211
-
212
- #
213
- # @return [String, nil]
214
- #
215
- def prev
216
- attributes[:prev]
217
- end
166
+ # @!attribute [r] prev
167
+ # @return [String, nil]
168
+ attribute :prev, Types::String.optional
218
169
 
219
170
  class << self
220
171
  #
@@ -233,41 +184,24 @@ module Mihari
233
184
  end
234
185
 
235
186
  class Result < Dry::Struct
187
+ # @!attribute [r] query
188
+ # @return [String]
236
189
  attribute :query, Types::String
237
- attribute :total, Types::Int
238
- attribute :hits, Types.Array(Hit)
239
- attribute :links, Links
240
190
 
241
- #
242
- # @return [String]
243
- #
244
- def query
245
- attributes[:query]
246
- end
247
-
248
- #
249
- # @return [Integer]
250
- #
251
- def total
252
- attributes[:total]
253
- end
191
+ # @!attribute [r] total
192
+ # @return [Integer]
193
+ attribute :total, Types::Int
254
194
 
255
- #
256
- # @return [Array<Hit>]
257
- #
258
- def hits
259
- attributes[:hits]
260
- end
195
+ # @!attribute [r] hits
196
+ # @return [Array<Hit>]
197
+ attribute :hits, Types.Array(Hit)
261
198
 
262
- #
263
- # @return [Links]
264
- #
265
- def links
266
- attributes[:links]
267
- end
199
+ # @!attribute [r] links
200
+ # @return [Links]
201
+ attribute :links, Links
268
202
 
269
203
  #
270
- # @return [Array<Mihari::Artifact>]
204
+ # @return [Array<Mihari::Models::Artifact>]
271
205
  #
272
206
  def artifacts
273
207
  hits.map(&:artifact)
@@ -292,30 +226,17 @@ module Mihari
292
226
  end
293
227
 
294
228
  class Response < Dry::Struct
229
+ # @!attribute [r] code
230
+ # @return [Integer]
295
231
  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
232
 
306
- #
307
- # @return [String]
308
- #
309
- def status
310
- attributes[:status]
311
- end
233
+ # @!attribute [r] status
234
+ # @return [String]
235
+ attribute :status, Types::String
312
236
 
313
- #
314
- # @return [Result]
315
- #
316
- def result
317
- attributes[:result]
318
- end
237
+ # @!attribute [r] result
238
+ # @return [Result]
239
+ attribute :result, Result
319
240
 
320
241
  class << self
321
242
  #