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
@@ -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,50 +12,39 @@ module Mihari
9
12
  # @return [String, nil]
10
13
  attr_reader :api_key
11
14
 
12
- # @return [Array<Mihari::Artifact>]
13
- attr_reader :artifacts
14
-
15
- # @return [Mihari::Services::Rule]
15
+ # @return [Mihari::Rule]
16
16
  attr_reader :rule
17
17
 
18
+ # @return [Array<Mihari::Models::Artifact>]
19
+ attr_accessor :artifacts
20
+
18
21
  #
19
- # @param [Array<Mihari::Artifact>] artifacts
20
- # @param [Mihari::Services::Rule] rule
22
+ # @param [Mihari::Rule] rule
21
23
  # @param [Hash, nil] options
22
- # @param [Hash] **params
24
+ # @param [Hash, nil] params
23
25
  #
24
- def initialize(artifacts:, rule:, options: nil, **params)
25
- super(artifacts: artifacts, rule: rule, options: options)
26
+ def initialize(rule:, options: nil, **params)
27
+ super(rule: rule, options: options)
26
28
 
27
29
  @url = params[:url] || Mihari.config.misp_url
28
30
  @api_key = params[:api_key] || Mihari.config.misp_api_key
31
+
32
+ @artifacts = []
29
33
  end
30
34
 
35
+ #
31
36
  # @return [Boolean]
32
- def valid?
33
- unless url? && api_key?
34
- Mihari.logger.info("MISP URL is not set") unless url?
35
- Mihari.logger.info("MISP API key is not set") unless api_key?
36
- return false
37
- end
38
-
39
- unless ping?
40
- Mihari.logger.info("MISP URL (#{url}) is not reachable")
41
- return false
42
- end
43
-
44
- true
37
+ #
38
+ def configured?
39
+ api_key? && url?
45
40
  end
46
41
 
47
42
  #
48
43
  # Create a MISP event
49
44
  #
50
- # @param [Arra<Mihari::Artifact>] artifacts
51
- # @param [Mihari::Services::Rule] rule
45
+ # @param [Array<Mihari::Models::Artifact>] artifacts
52
46
  #
53
- # @return [::MISP::Event]
54
- #
55
- def emit
47
+ def call(artifacts)
56
48
  return if artifacts.empty?
57
49
 
58
50
  client.create_event({
@@ -77,7 +69,7 @@ module Mihari
77
69
  #
78
70
  # Build a MISP attribute
79
71
  #
80
- # @param [Mihari::Artifact] artifact
72
+ # @param [Mihari::Models::Artifact] artifact
81
73
  #
82
74
  # @return [Hash]
83
75
  #
@@ -143,19 +135,6 @@ module Mihari
143
135
  def api_key?
144
136
  !api_key.nil? && !api_key.empty?
145
137
  end
146
-
147
- #
148
- # Check whether a URL is reachable or not
149
- #
150
- # @return [Boolean]
151
- #
152
- def ping?
153
- base_url = url.end_with?("/") ? url[0..-2] : url
154
- login_url = "#{base_url}/users/login"
155
-
156
- http = Net::Ping::HTTP.new(login_url)
157
- http.ping?
158
- end
159
138
  end
160
139
  end
161
140
  end
@@ -131,18 +131,22 @@ module Mihari
131
131
  # @return [String]
132
132
  attr_reader :username
133
133
 
134
+ # @return [Array<Mihari::Models::Artifact>]
135
+ attr_accessor :artifacts
136
+
134
137
  #
135
- # @param [Array<Mihari::Artifact>] artifacts
136
- # @param [Mihari::Services::Rule] rule
138
+ # @param [Mihari::Rule] rule
137
139
  # @param [Hash, nil] options
138
- # @param [Hash] **params
140
+ # @param [Hash, nil] params
139
141
  #
140
- def initialize(artifacts:, rule:, options: nil, **params)
141
- super(artifacts: artifacts, rule: rule, options: options)
142
+ def initialize(rule:, options: nil, **params)
143
+ super(rule: rule, options: options)
142
144
 
143
145
  @webhook_url = params[:webhook_url] || Mihari.config.slack_webhook_url
144
146
  @channel = params[:channel] || Mihari.config.slack_channel || DEFAULT_CHANNEL
145
147
  @username = DEFAULT_USERNAME
148
+
149
+ @artifacts = []
146
150
  end
147
151
 
148
152
  #
@@ -154,12 +158,10 @@ module Mihari
154
158
  !webhook_url.nil?
155
159
  end
156
160
 
157
- #
158
- # Check webhook URL is set. Alias of #webhook_url?
159
161
  #
160
162
  # @return [Boolean]
161
163
  #
162
- def valid?
164
+ def configured?
163
165
  webhook_url?
164
166
  end
165
167
 
@@ -211,19 +213,20 @@ module Mihari
211
213
  ].join("\n")
212
214
  end
213
215
 
214
- def emit
216
+ #
217
+ # @param [Array<Mihari::Models::Artifact>] artifacts
218
+ #
219
+ def call(artifacts)
215
220
  return if artifacts.empty?
216
221
 
222
+ @artifacts = artifacts
223
+
217
224
  notifier.post(text: text, attachments: attachments, mrkdwn: true)
218
225
  end
219
226
 
220
227
  def configuration_keys
221
228
  %w[slack_webhook_url slack_channel]
222
229
  end
223
-
224
- def configured?
225
- valid?
226
- end
227
230
  end
228
231
  end
229
232
  end
@@ -12,45 +12,42 @@ module Mihari
12
12
  # @return [String, nil]
13
13
  attr_reader :api_version
14
14
 
15
+ # @return [Array<Mihari::Models::Artifact>]
16
+ attr_accessor :artifacts
17
+
15
18
  #
16
- # @param [Array<Mihari::Artifact>] artifacts
17
- # @param [Mihari::Services::Rule] rule
19
+ # @param [Mihari::Rule] rule
18
20
  # @param [Hash, nil] options
19
- # @param [Hash] **params
21
+ # @param [Hash] params
20
22
  #
21
- def initialize(artifacts:, rule:, options: nil, **params)
22
- super(artifacts: artifacts, rule: rule, options: options)
23
+ def initialize(rule:, options: nil, **params)
24
+ super(rule: rule, options: options)
23
25
 
24
26
  @url = params[:url] || Mihari.config.thehive_url
25
27
  @api_key = params[:api_key] || Mihari.config.thehive_api_key
26
28
  @api_version = params[:api_version] || Mihari.config.thehive_api_version
29
+
30
+ @artifacts = []
27
31
  end
28
32
 
33
+ #
29
34
  # @return [Boolean]
30
- def valid?
31
- unless url? && api_key?
32
- Mihari.logger.info("TheHive URL is not set") unless url?
33
- Mihari.logger.info("TheHive API key is not set") unless api_key?
34
- return false
35
- end
36
-
37
- unless ping?
38
- Mihari.logger.info("TheHive URL (#{url}) is not reachable")
39
- return false
40
- end
41
-
42
- true
35
+ #
36
+ def configured?
37
+ api_key? && url?
43
38
  end
44
39
 
45
40
  #
46
41
  # Create a Hive alert
47
42
  #
48
- # @return [::MISP::Event]
43
+ # @param [Array<Mihari::Models::Artifact>] artifacts
49
44
  #
50
- def emit
45
+ def call(artifacts)
51
46
  return if artifacts.empty?
52
47
 
53
- client.alert(payload)
48
+ @artifacts = artifacts
49
+
50
+ client.alert payload
54
51
  end
55
52
 
56
53
  #
@@ -146,31 +143,6 @@ module Mihari
146
143
  source_ref: "1"
147
144
  }
148
145
  end
149
-
150
- #
151
- # Check whether a URL is reachable or not
152
- #
153
- # @return [Boolean]
154
- #
155
- def ping?
156
- base_url = url.end_with?("/") ? url[0..-2] : url
157
-
158
- if normalized_api_version.nil?
159
- # for v4
160
- base_url = url.end_with?("/") ? url[0..-2] : url
161
- public_url = "#{base_url}/index.html"
162
- else
163
- # for v5
164
- public_url = "#{base_url}/api/v1/status/public"
165
- end
166
-
167
- http = Net::Ping::HTTP.new(public_url)
168
-
169
- # use GET for v5
170
- http.get_request = true if normalized_api_version
171
-
172
- http.ping?
173
- end
174
146
  end
175
147
  end
176
148
  end
@@ -57,23 +57,42 @@ module Mihari
57
57
  # @return [String, nil]
58
58
  attr_reader :template
59
59
 
60
+ # @return [Array<Mihari::Models::Artifact>]
61
+ attr_accessor :artifacts
62
+
60
63
  #
61
- # @param [Array<Mihari::Artifact>] artifacts
62
- # @param [Mihari::Services::Rule] rule
63
- # @param [Hash] **options
64
+ # @param [Mihari::Rule] rule
65
+ # @param [Hash, nil] options
66
+ # @param [Hash, nil] params
64
67
  #
65
- def initialize(artifacts:, rule:, options: nil, **params)
66
- super(artifacts: artifacts, rule: rule, options: options)
68
+ def initialize(rule:, options: nil, **params)
69
+ super(rule: rule, options: options)
67
70
 
68
71
  @url = Addressable::URI.parse(params[:url])
69
72
  @headers = params[:headers] || {}
70
73
  @method = params[:method] || "POST"
71
74
  @template = params[:template]
75
+
76
+ @artifacts = []
77
+ end
78
+
79
+ #
80
+ # @return [Boolean]
81
+ #
82
+ def configured?
83
+ return false if url.nil?
84
+
85
+ %w[http https].include? url.scheme.downcase
72
86
  end
73
87
 
74
- def emit
88
+ #
89
+ # @param [Array<Mihari::Models::Artifact>] artifacts
90
+ #
91
+ def call(artifacts)
75
92
  return if artifacts.empty?
76
93
 
94
+ @artifacts = artifacts
95
+
77
96
  # returns body to prevent Parallel issue (Parallel fails to handle HTTP:Response object)
78
97
  case method
79
98
  when "GET"
@@ -83,12 +102,6 @@ module Mihari
83
102
  end
84
103
  end
85
104
 
86
- def valid?
87
- return false if url.nil?
88
-
89
- %w[http https].include? url.scheme.downcase
90
- end
91
-
92
105
  private
93
106
 
94
107
  def http
@@ -101,17 +114,15 @@ module Mihari
101
114
  # @return [String]
102
115
  #
103
116
  def rendered_template
104
- [].tap do |out|
105
- options = {}
106
- options[:template] = File.read(template) unless template.nil?
107
-
108
- payload_template = PayloadTemplate.new(
109
- artifacts: artifacts,
110
- rule: rule,
111
- options: options
112
- )
113
- out << payload_template.result
114
- end.first
117
+ options = {}
118
+ options[:template] = File.read(template) unless template.nil?
119
+
120
+ payload_template = PayloadTemplate.new(
121
+ artifacts: artifacts,
122
+ rule: rule,
123
+ options: options
124
+ )
125
+ payload_template.result
115
126
  end
116
127
 
117
128
  #
@@ -2,33 +2,34 @@
2
2
 
3
3
  module Mihari
4
4
  module Enrichers
5
- class Base < Mihari::Base
6
- include Mixins::Configurable
7
- include Mixins::Retriable
8
-
9
- include Dry::Monads[:result, :try]
10
-
5
+ #
6
+ # Base class for enrichers
7
+ #
8
+ class Base < Actor
11
9
  def initialize(options: nil)
12
10
  super(options: options)
13
11
  end
14
12
 
15
- def query_result(value)
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)
16
24
  Try[StandardError] do
17
25
  retry_on_error(
18
26
  times: retry_times,
19
27
  interval: retry_interval,
20
28
  exponential_backoff: retry_exponential_backoff
21
- ) { query value }
29
+ ) { call value }
22
30
  end.to_result
23
31
  end
24
32
 
25
- #
26
- # @param [String] value
27
- #
28
- def query(value)
29
- raise NotImplementedError, "You must implement #{self.class}##{__method__}"
30
- end
31
-
32
33
  class << self
33
34
  def inherited(child)
34
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::Shodan::GooglePublicDNS::Response>]
14
+ # @return [Array<Mihari::Structs::GooglePublicDNS::Response>]
14
15
  #
15
- def query(name)
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::Shodan::GooglePublicDNS::Response, nil]
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 query(ip)
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
- memoize :query
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 query(ip)
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] name
26
+ # @param [String] domain
24
27
  #
25
- # @return [Mihari::WhoisRecord, nil]
28
+ # @return [Mihari::Models::WhoisRecord, nil]
26
29
  #
27
- def query(domain)
30
+ def call(domain)
28
31
  domain = PublicSuffix.domain(domain)
29
32
 
30
33
  # check memo
@@ -34,7 +37,7 @@ module Mihari
34
37
  parser = record.parser
35
38
  return nil if parser.available?
36
39
 
37
- whois_record = WhoisRecord.new(
40
+ whois_record = Models::WhoisRecord.new(
38
41
  domain: domain,
39
42
  created_on: get_created_on(parser),
40
43
  updated_on: get_updated_on(parser),
@@ -71,7 +74,7 @@ module Mihari
71
74
  #
72
75
  # Get created_on
73
76
  #
74
- # @param [::Whois::Parser:] 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:] 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:] 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:] 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:] parser
129
+ # @param [::Whois::Parser] parser
127
130
  #
128
- # @return [Array[Hash], nil]
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
 
@@ -4,6 +4,9 @@ require "jr/cli/core_ext"
4
4
 
5
5
  module Mihari
6
6
  module Feed
7
+ #
8
+ # Feed parser
9
+ #
7
10
  class Parser
8
11
  # @return [Array<Hash>, Array<Array<String>>]
9
12
  attr_reader :data
@@ -4,6 +4,9 @@ require "csv"
4
4
 
5
5
  module Mihari
6
6
  module Feed
7
+ #
8
+ # Feed reader
9
+ #
7
10
  class Reader
8
11
  # @return [String]
9
12
  attr_reader :url
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
  #
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Mixins
5
+ #
6
+ # Autonomous System mixin
7
+ #
5
8
  module AutonomousSystem
6
9
  #
7
10
  # Normalize ASN value
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Mixins
5
+ #
6
+ # Configurable mixin
7
+ #
5
8
  module Configurable
6
9
  #
7
10
  # Check whether there are configuration key-values or not
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Mixins
5
+ #
6
+ # Error notification mixin
7
+ #
5
8
  module ErrorNotification
6
9
  #
7
10
  # Send an exception notification if there is any error in a block