mihari 5.6.2 → 5.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (267) 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/lib/mihari/actor.rb +18 -2
  6. data/lib/mihari/analyzers/base.rb +13 -12
  7. data/lib/mihari/analyzers/binaryedge.rb +4 -1
  8. data/lib/mihari/analyzers/censys.rb +4 -2
  9. data/lib/mihari/analyzers/circl.rb +4 -1
  10. data/lib/mihari/analyzers/crtsh.rb +4 -1
  11. data/lib/mihari/analyzers/dnstwister.rb +4 -1
  12. data/lib/mihari/analyzers/feed.rb +3 -0
  13. data/lib/mihari/analyzers/fofa.rb +65 -0
  14. data/lib/mihari/analyzers/greynoise.rb +4 -1
  15. data/lib/mihari/analyzers/hunterhow.rb +6 -1
  16. data/lib/mihari/analyzers/onyphe.rb +4 -1
  17. data/lib/mihari/analyzers/otx.rb +4 -1
  18. data/lib/mihari/analyzers/passivetotal.rb +4 -1
  19. data/lib/mihari/analyzers/pulsedive.rb +3 -0
  20. data/lib/mihari/analyzers/securitytrails.rb +4 -1
  21. data/lib/mihari/analyzers/shodan.rb +4 -1
  22. data/lib/mihari/analyzers/urlscan.rb +4 -1
  23. data/lib/mihari/analyzers/virustotal.rb +4 -1
  24. data/lib/mihari/analyzers/virustotal_intelligence.rb +4 -1
  25. data/lib/mihari/analyzers/zoomeye.rb +5 -2
  26. data/lib/mihari/cli/alert.rb +3 -0
  27. data/lib/mihari/cli/base.rb +3 -0
  28. data/lib/mihari/cli/database.rb +3 -0
  29. data/lib/mihari/cli/main.rb +3 -0
  30. data/lib/mihari/cli/rule.rb +3 -0
  31. data/lib/mihari/clients/base.rb +3 -0
  32. data/lib/mihari/clients/binaryedge.rb +5 -2
  33. data/lib/mihari/clients/censys.rb +7 -4
  34. data/lib/mihari/clients/circl.rb +3 -0
  35. data/lib/mihari/clients/crtsh.rb +3 -0
  36. data/lib/mihari/clients/dnstwister.rb +3 -0
  37. data/lib/mihari/clients/fofa.rb +83 -0
  38. data/lib/mihari/clients/greynoise.rb +5 -2
  39. data/lib/mihari/clients/hunterhow.rb +5 -2
  40. data/lib/mihari/clients/misp.rb +3 -0
  41. data/lib/mihari/clients/onyphe.rb +5 -2
  42. data/lib/mihari/clients/otx.rb +3 -0
  43. data/lib/mihari/clients/passivetotal.rb +3 -0
  44. data/lib/mihari/clients/publsedive.rb +4 -1
  45. data/lib/mihari/clients/securitytrails.rb +3 -0
  46. data/lib/mihari/clients/shodan.rb +5 -2
  47. data/lib/mihari/clients/the_hive.rb +3 -0
  48. data/lib/mihari/clients/urlscan.rb +7 -4
  49. data/lib/mihari/clients/virustotal.rb +5 -2
  50. data/lib/mihari/clients/zoomeye.rb +3 -0
  51. data/lib/mihari/commands/alert.rb +9 -16
  52. data/lib/mihari/commands/database.rb +3 -0
  53. data/lib/mihari/commands/rule.rb +10 -1
  54. data/lib/mihari/commands/search.rb +13 -29
  55. data/lib/mihari/commands/version.rb +3 -0
  56. data/lib/mihari/commands/web.rb +4 -1
  57. data/lib/mihari/config.rb +139 -150
  58. data/lib/mihari/constants.rb +1 -1
  59. data/lib/mihari/database.rb +6 -0
  60. data/lib/mihari/emitters/base.rb +13 -11
  61. data/lib/mihari/emitters/database.rb +4 -1
  62. data/lib/mihari/emitters/misp.rb +7 -4
  63. data/lib/mihari/emitters/slack.rb +3 -3
  64. data/lib/mihari/emitters/the_hive.rb +3 -3
  65. data/lib/mihari/emitters/webhook.rb +4 -3
  66. data/lib/mihari/enrichers/base.rb +15 -9
  67. data/lib/mihari/enrichers/google_public_dns.rb +6 -5
  68. data/lib/mihari/enrichers/ipinfo.rb +11 -9
  69. data/lib/mihari/enrichers/shodan.rb +4 -6
  70. data/lib/mihari/enrichers/whois.rb +12 -9
  71. data/lib/mihari/entities/tag.rb +1 -0
  72. data/lib/mihari/errors.rb +6 -0
  73. data/lib/mihari/feed/parser.rb +3 -0
  74. data/lib/mihari/feed/reader.rb +3 -0
  75. data/lib/mihari/http.rb +6 -0
  76. data/lib/mihari/mixins/autonomous_system.rb +3 -0
  77. data/lib/mihari/mixins/configurable.rb +3 -0
  78. data/lib/mihari/mixins/error_notification.rb +3 -0
  79. data/lib/mihari/mixins/falsepositive.rb +3 -0
  80. data/lib/mihari/mixins/refang.rb +3 -0
  81. data/lib/mihari/mixins/retriable.rb +6 -2
  82. data/lib/mihari/models/alert.rb +7 -4
  83. data/lib/mihari/models/artifact.rb +6 -0
  84. data/lib/mihari/models/autonomous_system.rb +4 -1
  85. data/lib/mihari/models/cpe.rb +4 -1
  86. data/lib/mihari/models/dns.rb +4 -1
  87. data/lib/mihari/models/geolocation.rb +4 -1
  88. data/lib/mihari/models/port.rb +4 -1
  89. data/lib/mihari/models/reverse_dns.rb +4 -1
  90. data/lib/mihari/models/rule.rb +6 -3
  91. data/lib/mihari/models/tag.rb +3 -0
  92. data/lib/mihari/models/tagging.rb +3 -0
  93. data/lib/mihari/models/whois.rb +4 -3
  94. data/lib/mihari/rule.rb +31 -12
  95. data/lib/mihari/schemas/alert.rb +3 -0
  96. data/lib/mihari/schemas/analyzer.rb +11 -0
  97. data/lib/mihari/schemas/emitter.rb +3 -0
  98. data/lib/mihari/schemas/enricher.rb +3 -0
  99. data/lib/mihari/schemas/macros.rb +4 -0
  100. data/lib/mihari/schemas/mixins.rb +5 -0
  101. data/lib/mihari/schemas/rule.rb +3 -0
  102. data/lib/mihari/service.rb +26 -0
  103. data/lib/mihari/services/alert_builder.rb +85 -9
  104. data/lib/mihari/services/alert_runner.rb +8 -19
  105. data/lib/mihari/services/rule_builder.rb +13 -12
  106. data/lib/mihari/services/rule_runner.rb +7 -32
  107. data/lib/mihari/structs/binaryedge.rb +22 -28
  108. data/lib/mihari/structs/censys.rb +48 -141
  109. data/lib/mihari/structs/config.rb +19 -30
  110. data/lib/mihari/structs/filters.rb +38 -0
  111. data/lib/mihari/structs/fofa.rb +47 -0
  112. data/lib/mihari/structs/google_public_dns.rb +10 -32
  113. data/lib/mihari/structs/greynoise.rb +33 -90
  114. data/lib/mihari/structs/hunterhow.rb +24 -28
  115. data/lib/mihari/structs/ipinfo.rb +14 -37
  116. data/lib/mihari/structs/onyphe.rb +31 -80
  117. data/lib/mihari/structs/shodan.rb +47 -114
  118. data/lib/mihari/structs/urlscan.rb +24 -69
  119. data/lib/mihari/structs/virustotal_intelligence.rb +20 -64
  120. data/lib/mihari/type_checker.rb +4 -0
  121. data/lib/mihari/types.rb +3 -0
  122. data/lib/mihari/version.rb +1 -1
  123. data/lib/mihari/web/api.rb +15 -10
  124. data/lib/mihari/web/app.rb +64 -56
  125. data/lib/mihari/web/endpoints/alerts.rb +127 -85
  126. data/lib/mihari/web/endpoints/artifacts.rb +91 -79
  127. data/lib/mihari/web/endpoints/configs.rb +18 -13
  128. data/lib/mihari/web/endpoints/ip_addresses.rb +35 -15
  129. data/lib/mihari/web/endpoints/rules.rb +236 -187
  130. data/lib/mihari/web/endpoints/tags.rb +42 -35
  131. data/lib/mihari/web/middleware/connection_adapter.rb +16 -9
  132. data/lib/mihari/web/middleware/error_notification_adapter.rb +17 -10
  133. data/lib/mihari/web/public/assets/{index-28d4c79d.js → index-07fafab5.js} +31 -30
  134. data/lib/mihari/web/public/assets/mode-yaml-24faa242.js +8 -0
  135. data/lib/mihari/web/public/index.html +1 -1
  136. data/lib/mihari.rb +24 -6
  137. data/mihari.gemspec +9 -2
  138. data/mkdocs.yml +4 -2
  139. metadata +38 -133
  140. data/docs/alternatives.md +0 -5
  141. data/docs/analyzers/binaryedge.md +0 -26
  142. data/docs/analyzers/censys.md +0 -31
  143. data/docs/analyzers/circl.md +0 -37
  144. data/docs/analyzers/crtsh.md +0 -26
  145. data/docs/analyzers/dnstwister.md +0 -25
  146. data/docs/analyzers/feed.md +0 -73
  147. data/docs/analyzers/greynoise.md +0 -26
  148. data/docs/analyzers/hunterhow.md +0 -33
  149. data/docs/analyzers/index.md +0 -103
  150. data/docs/analyzers/onyphe.md +0 -26
  151. data/docs/analyzers/otx.md +0 -28
  152. data/docs/analyzers/passivetotal.md +0 -52
  153. data/docs/analyzers/pulsedive.md +0 -28
  154. data/docs/analyzers/securitytrails.md +0 -41
  155. data/docs/analyzers/shodan.md +0 -26
  156. data/docs/analyzers/urlscan.md +0 -28
  157. data/docs/analyzers/virustotal.md +0 -43
  158. data/docs/analyzers/virustotal_intelligence.md +0 -33
  159. data/docs/analyzers/zoomeye.md +0 -38
  160. data/docs/configuration.md +0 -35
  161. data/docs/emitters/database.md +0 -22
  162. data/docs/emitters/hive.md +0 -26
  163. data/docs/emitters/index.md +0 -36
  164. data/docs/emitters/misp.md +0 -21
  165. data/docs/emitters/slack.md +0 -21
  166. data/docs/emitters/webhook.md +0 -63
  167. data/docs/enrichers/google_public_dns.md +0 -19
  168. data/docs/enrichers/index.md +0 -35
  169. data/docs/enrichers/ipinfo.md +0 -26
  170. data/docs/enrichers/shodan.md +0 -22
  171. data/docs/enrichers/whois.md +0 -17
  172. data/docs/github_actions.md +0 -43
  173. data/docs/index.md +0 -11
  174. data/docs/installation.md +0 -31
  175. data/docs/requirements.md +0 -13
  176. data/docs/rule.md +0 -168
  177. data/docs/tags.md +0 -3
  178. data/docs/usage.md +0 -103
  179. data/frontend/.eslintrc.cjs +0 -22
  180. data/frontend/.gitignore +0 -31
  181. data/frontend/.prettierrc.json +0 -8
  182. data/frontend/README.md +0 -3
  183. data/frontend/env.d.ts +0 -5
  184. data/frontend/index.html +0 -21
  185. data/frontend/package-lock.json +0 -7219
  186. data/frontend/package.json +0 -67
  187. data/frontend/public/favicon.ico +0 -0
  188. data/frontend/scripts/swagger_doc_to_yaml.rb +0 -23
  189. data/frontend/src/App.vue +0 -27
  190. data/frontend/src/ace-config.ts +0 -6
  191. data/frontend/src/api-helper.ts +0 -111
  192. data/frontend/src/api.ts +0 -105
  193. data/frontend/src/components/ErrorMessage.vue +0 -31
  194. data/frontend/src/components/Loading.vue +0 -15
  195. data/frontend/src/components/Navbar.vue +0 -42
  196. data/frontend/src/components/Pagination.vue +0 -119
  197. data/frontend/src/components/alert/Alert.vue +0 -87
  198. data/frontend/src/components/alert/Alerts.vue +0 -63
  199. data/frontend/src/components/alert/AlertsWithPagination.vue +0 -90
  200. data/frontend/src/components/alert/AlertsWrapper.vue +0 -128
  201. data/frontend/src/components/alert/Form.vue +0 -182
  202. data/frontend/src/components/artifact/AS.vue +0 -29
  203. data/frontend/src/components/artifact/Artifact.vue +0 -287
  204. data/frontend/src/components/artifact/ArtifactTag.vue +0 -64
  205. data/frontend/src/components/artifact/ArtifactTags.vue +0 -29
  206. data/frontend/src/components/artifact/ArtifactWrapper.vue +0 -57
  207. data/frontend/src/components/artifact/CPEs.vue +0 -23
  208. data/frontend/src/components/artifact/DnsRecords.vue +0 -38
  209. data/frontend/src/components/artifact/Ports.vue +0 -23
  210. data/frontend/src/components/artifact/ReverseDnsNames.vue +0 -31
  211. data/frontend/src/components/artifact/Tags.vue +0 -29
  212. data/frontend/src/components/artifact/WhoisRecord.vue +0 -44
  213. data/frontend/src/components/config/Configs.vue +0 -65
  214. data/frontend/src/components/config/ConfigsWrapper.vue +0 -32
  215. data/frontend/src/components/link/Link.vue +0 -32
  216. data/frontend/src/components/link/Links.vue +0 -42
  217. data/frontend/src/components/rule/EditRule.vue +0 -72
  218. data/frontend/src/components/rule/EditRuleWrapper.vue +0 -48
  219. data/frontend/src/components/rule/Form.vue +0 -158
  220. data/frontend/src/components/rule/InputForm.vue +0 -45
  221. data/frontend/src/components/rule/NewRule.vue +0 -57
  222. data/frontend/src/components/rule/Rule.vue +0 -100
  223. data/frontend/src/components/rule/RuleWrapper.vue +0 -53
  224. data/frontend/src/components/rule/Rules.vue +0 -84
  225. data/frontend/src/components/rule/RulesWrapper.vue +0 -121
  226. data/frontend/src/components/rule/YAML.vue +0 -37
  227. data/frontend/src/components/tag/Tag.vue +0 -65
  228. data/frontend/src/components/tag/Tags.vue +0 -37
  229. data/frontend/src/countries.ts +0 -350
  230. data/frontend/src/index.ts +0 -20
  231. data/frontend/src/links/anyrun.ts +0 -19
  232. data/frontend/src/links/base.ts +0 -14
  233. data/frontend/src/links/censys.ts +0 -20
  234. data/frontend/src/links/crtsh.ts +0 -20
  235. data/frontend/src/links/dnslytics.ts +0 -38
  236. data/frontend/src/links/greynoise.ts +0 -20
  237. data/frontend/src/links/index.ts +0 -40
  238. data/frontend/src/links/intezer.ts +0 -20
  239. data/frontend/src/links/otx.ts +0 -33
  240. data/frontend/src/links/securitytrails.ts +0 -38
  241. data/frontend/src/links/shodan.ts +0 -20
  242. data/frontend/src/links/urlscan.ts +0 -50
  243. data/frontend/src/links/virustotal.ts +0 -72
  244. data/frontend/src/main.ts +0 -41
  245. data/frontend/src/router/index.ts +0 -57
  246. data/frontend/src/rule.ts +0 -14
  247. data/frontend/src/shims-vue.d.ts +0 -6
  248. data/frontend/src/swagger.yaml +0 -771
  249. data/frontend/src/types.ts +0 -188
  250. data/frontend/src/utils.ts +0 -54
  251. data/frontend/src/views/Alerts.vue +0 -20
  252. data/frontend/src/views/Artifact.vue +0 -39
  253. data/frontend/src/views/Configs.vue +0 -20
  254. data/frontend/src/views/EditRule.vue +0 -39
  255. data/frontend/src/views/NewRule.vue +0 -26
  256. data/frontend/src/views/Rule.vue +0 -39
  257. data/frontend/src/views/Rules.vue +0 -20
  258. data/frontend/tests/utils.spec.ts +0 -9
  259. data/frontend/tsconfig.app.json +0 -21
  260. data/frontend/tsconfig.json +0 -14
  261. data/frontend/tsconfig.node.json +0 -13
  262. data/frontend/tsconfig.vitest.json +0 -12
  263. data/frontend/vite.config.ts +0 -24
  264. data/frontend/vitest.config.ts +0 -21
  265. data/lib/mihari/services/alert_proxy.rb +0 -92
  266. data/lib/mihari/templates/rule.yml.erb +0 -5
  267. data/lib/mihari/web/public/assets/mode-yaml-a21faa53.js +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7136011e523fa8b61ed048932c1ca7e265425a4eaf89c76a5f8052f74c108f17
4
- data.tar.gz: 243dfcbc17341520912a626210a336d0cdd419b011160d4d2f60ddd1f2326c33
3
+ metadata.gz: 2d27340b82929d2a9dba6cab93c9e429112eed2f254f18595b765bd65852cdfa
4
+ data.tar.gz: 137141dad2d1b3c4f5b33a2ed38824a9e19c965c7d13e99d20358c2d546dd24c
5
5
  SHA512:
6
- metadata.gz: eade462830cc2258517594564713cd5b612755f359a4efafb40fd16973282785f9a0ad610e3063c9b372ffddcf45e98773e6047f3761547493a68f6bafe25769
7
- data.tar.gz: 7ff869faaaf0782d842e241e476d5b7602d94e3c08ae2588d4fcbe56d0c44bb6b38714db72fa6be5da70ca5989c6803193b0516614af80d2752114783ff3a5bf
6
+ metadata.gz: 84825a14e57d1e740d7ee1e312ac23454017665b92dbdbe9fd2fe0cb55eb900addda0d9563049cf493094b67e9f1e5888d09fe37e7a102db5732f09837558fec
7
+ data.tar.gz: 393031f2550d7943271dd4b662c65b1da2df322661cdf1228808848e93f7bb7f65acaf8d1861599036bd951b464b5248f615e2abd738b171699eaf396b64f7c4
data/.rubocop.yml CHANGED
@@ -3,12 +3,16 @@ Style/HashSyntax:
3
3
  Style/StringLiterals:
4
4
  EnforcedStyle: double_quotes
5
5
  Metrics/BlockLength:
6
+ Max: 150
6
7
  Exclude:
7
8
  - "spec/**/*"
8
9
  - "*.gemspec"
9
10
  Metrics/ClassLength:
10
11
  Enabled: false
11
12
  Metrics/MethodLength:
12
- Max: 20
13
+ Max: 50
14
+ Metrics/AbcSize:
15
+ Max: 50
13
16
  require:
14
17
  - rubocop-rspec
18
+ - rubocop-yard
data/README.md CHANGED
@@ -24,6 +24,7 @@ Mihari supports the following services by default.
24
24
  - [CIRCL passive DNS](https://www.circl.lu/services/passive-dns/) / [passive SSL](https://www.circl.lu/services/passive-ssl/)
25
25
  - [crt.sh](https://crt.sh/)
26
26
  - [dnstwister](https://dnstwister.report/)
27
+ - [Fofa](https://en.fofa.info/)
27
28
  - [GreyNoise](https://www.greynoise.io/)
28
29
  - [HunterHow](https://hunter.how/)
29
30
  - [Onyphe](https://onyphe.io)
data/config.ru CHANGED
@@ -3,4 +3,4 @@ require "./lib/mihari"
3
3
  # set rack env as development
4
4
  ENV["RACK_ENV"] ||= "development"
5
5
 
6
- run Mihari::App.instance
6
+ run Mihari::Web::App.instance
data/lib/mihari/actor.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Mihari
4
4
  #
5
- # Base class for Analyzer, Emitter and Enricher
5
+ # Yet another base service class for Analyzer, Emitter and Enricher
6
6
  #
7
7
  class Actor
8
8
  include Dry::Monads[:result, :try]
@@ -16,7 +16,9 @@ module Mihari
16
16
  #
17
17
  # @param [Hash, nil] options
18
18
  #
19
- def initialize(*_args, options: nil, **_kwargs)
19
+ def initialize(options: nil)
20
+ super()
21
+
20
22
  @options = options || {}
21
23
  end
22
24
 
@@ -57,6 +59,20 @@ module Mihari
57
59
  raise ConfigurationError, message
58
60
  end
59
61
 
62
+ def call(*args, **kwargs)
63
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
64
+ end
65
+
66
+ def result(...)
67
+ Try[StandardError] do
68
+ retry_on_error(
69
+ times: retry_times,
70
+ interval: retry_interval,
71
+ exponential_backoff: retry_exponential_backoff
72
+ ) { call(...) }
73
+ end.to_result
74
+ end
75
+
60
76
  class << self
61
77
  #
62
78
  # @return [String]
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # Base class for analyzers
7
+ #
5
8
  class Base < Actor
6
9
  # @return [String]
7
10
  attr_reader :query
@@ -53,22 +56,20 @@ module Mihari
53
56
  # @return [Array<Mihari::Models::Artifact>]
54
57
  #
55
58
  def normalized_artifacts
56
- retry_on_error(times: retry_times, interval: retry_interval, exponential_backoff: retry_exponential_backoff) do
57
- artifacts.compact.sort.map do |artifact|
58
- # No need to set data_type manually
59
- # It is set automatically in #initialize
60
- artifact = artifact.is_a?(Models::Artifact) ? artifact : Models::Artifact.new(data: artifact)
61
- artifact.source = self.class.class_key
62
- artifact
63
- end.select(&:valid?).uniq(&:data)
64
- end
59
+ artifacts.compact.sort.map do |artifact|
60
+ # No need to set data_type manually
61
+ # It is set automatically in #initialize
62
+ artifact = artifact.is_a?(Models::Artifact) ? artifact : Models::Artifact.new(data: artifact)
63
+ artifact.source = self.class.class_key
64
+ artifact
65
+ end.select(&:valid?).uniq(&:data)
65
66
  end
66
67
 
67
68
  #
68
- # @return [Dry::Monads::Result::Success<Array<Mihari::Models::Artifact>>, Dry::Monads::Result::Failure]
69
+ # @return [Array<Mihari::Models::Artifact>]
69
70
  #
70
- def result
71
- Try[StandardError] { normalized_artifacts }.to_result
71
+ def call
72
+ normalized_artifacts
72
73
  end
73
74
 
74
75
  class << self
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # BinaryEdge analyzer
7
+ #
5
8
  class BinaryEdge < Base
6
9
  # @return [String, nil]
7
10
  attr_reader :api_key
@@ -32,7 +35,7 @@ module Mihari
32
35
  # @return [Mihari::Clients::BinaryEdge]
33
36
  #
34
37
  def client
35
- @client ||= Clients::BinaryEdge.new(
38
+ Clients::BinaryEdge.new(
36
39
  api_key: api_key,
37
40
  pagination_interval: pagination_interval,
38
41
  timeout: timeout
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # Censys analyzer
7
+ #
5
8
  class Censys < Base
6
9
  # @return [String, nil]
7
10
  attr_reader :id
@@ -12,7 +15,6 @@ module Mihari
12
15
  #
13
16
  # @param [String] query
14
17
  # @param [hash, nil] options
15
- # @param [String, nil] api_key
16
18
  # @param [String, nil] id
17
19
  # @param [String, nil] secret
18
20
  #
@@ -52,7 +54,7 @@ module Mihari
52
54
  # @return [Mihari::Clients::Censys]
53
55
  #
54
56
  def client
55
- @client ||= Clients::Censys.new(
57
+ Clients::Censys.new(
56
58
  id: id,
57
59
  secret: secret,
58
60
  pagination_interval: pagination_interval,
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # CIRCL passive DNS/SSL analyzer
7
+ #
5
8
  class CIRCL < Base
6
9
  include Mixins::Refang
7
10
 
@@ -51,7 +54,7 @@ module Mihari
51
54
  private
52
55
 
53
56
  def client
54
- @client ||= Clients::CIRCL.new(username: username, password: password, timeout: timeout)
57
+ Clients::CIRCL.new(username: username, password: password, timeout: timeout)
55
58
  end
56
59
 
57
60
  def username?
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # crt.sh analyzer
7
+ #
5
8
  class Crtsh < Base
6
9
  # @return [Boolean]
7
10
  attr_reader :exclude_expired
@@ -28,7 +31,7 @@ module Mihari
28
31
  # @return [Mihari::Clients::Crtsh]
29
32
  #
30
33
  def client
31
- @client ||= Mihari::Clients::Crtsh.new(timeout: timeout)
34
+ Mihari::Clients::Crtsh.new(timeout: timeout)
32
35
  end
33
36
  end
34
37
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # DNSTwister analyzer
7
+ #
5
8
  class DNSTwister < Base
6
9
  include Mixins::Refang
7
10
 
@@ -39,7 +42,7 @@ module Mihari
39
42
  end
40
43
 
41
44
  def client
42
- @client ||= Clients::DNSTwister.new(timeout: timeout)
45
+ Clients::DNSTwister.new(timeout: timeout)
43
46
  end
44
47
 
45
48
  #
@@ -5,6 +5,9 @@ require "mihari/feed/parser"
5
5
 
6
6
  module Mihari
7
7
  module Analyzers
8
+ #
9
+ # Feed analyzer
10
+ #
8
11
  class Feed < Base
9
12
  # @return [Hash, nil]
10
13
  attr_reader :data
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Analyzers
5
+ #
6
+ # Fofa analyzer
7
+ #
8
+ class Fofa < Base
9
+ # @return [String, nil]
10
+ attr_reader :api_key
11
+
12
+ # @return [String, nil]
13
+ attr_reader :email
14
+
15
+ #
16
+ # @param [String] query
17
+ # @param [Hash, nil] options
18
+ # @param [String, nil] api_key
19
+ # @param [String, nil] email
20
+ #
21
+ def initialize(query, options: nil, api_key: nil, email: nil)
22
+ super(query, options: options)
23
+
24
+ @api_key = api_key || Mihari.config.fofa_api_key
25
+ @email = email || Mihari.config.fofa_email
26
+ end
27
+
28
+ def artifacts
29
+ client.search_with_pagination(query, pagination_limit: pagination_limit).map do |res|
30
+ (res.results || []).map { |result| result[1] }
31
+ end.flatten.compact
32
+ end
33
+
34
+ def configuration_keys
35
+ %w[fofa_api_key fofa_email]
36
+ end
37
+
38
+ def configured?
39
+ api_key? && email?
40
+ end
41
+
42
+ private
43
+
44
+ def api_key?
45
+ !api_key.nil?
46
+ end
47
+
48
+ def email?
49
+ !email.nil?
50
+ end
51
+
52
+ #
53
+ # @return [Mihari::Clients::Fofa]
54
+ #
55
+ def client
56
+ Clients::Fofa.new(
57
+ api_key: api_key,
58
+ email: email,
59
+ pagination_interval: pagination_interval,
60
+ timeout: timeout
61
+ )
62
+ end
63
+ end
64
+ end
65
+ end
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # GreyNoise analyzer
7
+ #
5
8
  class GreyNoise < Base
6
9
  # @return [String, nil]
7
10
  attr_reader :api_key
@@ -31,7 +34,7 @@ module Mihari
31
34
  private
32
35
 
33
36
  def client
34
- @client ||= Clients::GreyNoise.new(
37
+ Clients::GreyNoise.new(
35
38
  api_key: api_key,
36
39
  pagination_interval: pagination_interval,
37
40
  timeout: timeout
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # hunter.how analyzer
7
+ #
5
8
  class HunterHow < Base
6
9
  # @return [String, nil]
7
10
  attr_reader :api_key
@@ -14,6 +17,8 @@ module Mihari
14
17
 
15
18
  #
16
19
  # @param [String] query
20
+ # @param [Date] start_time
21
+ # @param [Date] end_time
17
22
  # @param [Hash, nil] options
18
23
  # @param [String, nil] api_key
19
24
  #
@@ -46,7 +51,7 @@ module Mihari
46
51
  private
47
52
 
48
53
  def client
49
- @client ||= Clients::HunterHow.new(
54
+ Clients::HunterHow.new(
50
55
  api_key: api_key,
51
56
  pagination_interval: pagination_interval,
52
57
  timeout: timeout
@@ -4,6 +4,9 @@ require "normalize_country"
4
4
 
5
5
  module Mihari
6
6
  module Analyzers
7
+ #
8
+ # Onyphe analyzer
9
+ #
7
10
  class Onyphe < Base
8
11
  # @return [String, nil]
9
12
  attr_reader :api_key
@@ -33,7 +36,7 @@ module Mihari
33
36
  private
34
37
 
35
38
  def client
36
- @client ||= Clients::Onyphe.new(
39
+ Clients::Onyphe.new(
37
40
  api_key: api_key,
38
41
  pagination_interval: pagination_interval,
39
42
  timeout: timeout
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # OTX analyzer
7
+ #
5
8
  class OTX < Base
6
9
  include Mixins::Refang
7
10
 
@@ -42,7 +45,7 @@ module Mihari
42
45
  private
43
46
 
44
47
  def client
45
- @client ||= Mihari::Clients::OTX.new(api_key: api_key, timeout: timeout)
48
+ Mihari::Clients::OTX.new(api_key: api_key, timeout: timeout)
46
49
  end
47
50
 
48
51
  #
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # PassiveTotal analyzer
7
+ #
5
8
  class PassiveTotal < Base
6
9
  include Mixins::Refang
7
10
 
@@ -62,7 +65,7 @@ module Mihari
62
65
  private
63
66
 
64
67
  def client
65
- @client ||= Clients::PassiveTotal.new(username: username, api_key: api_key, timeout: timeout)
68
+ Clients::PassiveTotal.new(username: username, api_key: api_key, timeout: timeout)
66
69
  end
67
70
 
68
71
  #
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # Pulsedive analyzer
7
+ #
5
8
  class Pulsedive < Base
6
9
  include Mixins::Refang
7
10
 
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # SecurityTrails
7
+ #
5
8
  class SecurityTrails < Base
6
9
  include Mixins::Refang
7
10
 
@@ -56,7 +59,7 @@ module Mihari
56
59
  private
57
60
 
58
61
  def client
59
- @client ||= Clients::SecurityTrails.new(api_key: api_key, timeout: timeout)
62
+ Clients::SecurityTrails.new(api_key: api_key, timeout: timeout)
60
63
  end
61
64
 
62
65
  #
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # Shodan analyzer
7
+ #
5
8
  class Shodan < Base
6
9
  # @return [String, nil]
7
10
  attr_reader :api_key
@@ -34,7 +37,7 @@ module Mihari
34
37
  # @return [Clients::Shodan]
35
38
  #
36
39
  def client
37
- @client ||= Clients::Shodan.new(
40
+ Clients::Shodan.new(
38
41
  api_key: api_key,
39
42
  pagination_interval: pagination_interval,
40
43
  timeout: timeout
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # urlscan.io analyzer
7
+ #
5
8
  class Urlscan < Base
6
9
  SUPPORTED_DATA_TYPES = %w[url domain ip].freeze
7
10
 
@@ -44,7 +47,7 @@ module Mihari
44
47
  private
45
48
 
46
49
  def client
47
- @client ||= Clients::UrlScan.new(
50
+ Clients::Urlscan.new(
48
51
  api_key: api_key,
49
52
  pagination_interval: pagination_interval,
50
53
  timeout: timeout
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # VirusTotal analyzer
7
+ #
5
8
  class VirusTotal < Base
6
9
  include Mixins::Refang
7
10
 
@@ -51,7 +54,7 @@ module Mihari
51
54
  private
52
55
 
53
56
  def client
54
- @client = Clients::VirusTotal.new(api_key: api_key)
57
+ Clients::VirusTotal.new(api_key: api_key)
55
58
  end
56
59
 
57
60
  #
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # VirusTotal Intelligence analyzer
7
+ #
5
8
  class VirusTotalIntelligence < Base
6
9
  # @return [String, nil]
7
10
  attr_reader :api_key
@@ -49,7 +52,7 @@ module Mihari
49
52
  # @return [::VirusTotal::API]
50
53
  #
51
54
  def client
52
- @client = Clients::VirusTotal.new(
55
+ Clients::VirusTotal.new(
53
56
  api_key: api_key,
54
57
  pagination_interval: pagination_interval,
55
58
  timeout: timeout
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Analyzers
5
+ #
6
+ # ZoomEye analyzer
7
+ #
5
8
  class ZoomEye < Base
6
9
  # @return [String, nil]
7
10
  attr_reader :api_key
@@ -53,7 +56,7 @@ module Mihari
53
56
  end
54
57
 
55
58
  def client
56
- @client ||= Clients::ZoomEye.new(
59
+ Clients::ZoomEye.new(
57
60
  api_key: api_key,
58
61
  pagination_interval: pagination_interval,
59
62
  timeout: timeout
@@ -63,7 +66,7 @@ module Mihari
63
66
  #
64
67
  # Convert responses into an array of String
65
68
  #
66
- # @param [Hash] response
69
+ # @param [Hash] res
67
70
  #
68
71
  # @return [Array<Mihari::Models::Artifact>]
69
72
  #
@@ -4,6 +4,9 @@ require "mihari/commands/alert"
4
4
 
5
5
  module Mihari
6
6
  module CLI
7
+ #
8
+ # Alert CLI class (mihari alert ...)
9
+ #
7
10
  class Alert < Base
8
11
  include Mihari::Commands::Alert
9
12
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module CLI
5
+ #
6
+ # Base class for Thor classes
7
+ #
5
8
  class Base < Thor
6
9
  class << self
7
10
  def exit_on_failure?
@@ -4,6 +4,9 @@ require "mihari/commands/database"
4
4
 
5
5
  module Mihari
6
6
  module CLI
7
+ #
8
+ # Database CLI class (mihari db ...)
9
+ #
7
10
  class Database < Base
8
11
  include Mihari::Commands::Database
9
12
  end
@@ -19,6 +19,9 @@ require "mihari/cli/rule"
19
19
 
20
20
  module Mihari
21
21
  module CLI
22
+ #
23
+ # Main CLI class
24
+ #
22
25
  class Main < Base
23
26
  class_option :debug, desc: "Sets up debug mode", aliases: ["-d"], type: :boolean
24
27
  class_around :safe_execute
@@ -4,6 +4,9 @@ require "mihari/commands/rule"
4
4
 
5
5
  module Mihari
6
6
  module CLI
7
+ #
8
+ # Rule CLI class (mihari rule ...)
9
+ #
7
10
  class Rule < Base
8
11
  include Mihari::Commands::Rule
9
12
  end
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Clients
5
+ #
6
+ # Base class for API clients
7
+ #
5
8
  class Base
6
9
  # @return [String]
7
10
  attr_reader :base_url
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Clients
5
+ #
6
+ # BinaryEdge API client
7
+ #
5
8
  class BinaryEdge < Base
6
9
  #
7
10
  # @param [String] base_url
@@ -27,7 +30,7 @@ module Mihari
27
30
  # @param [Integer] page Default 1, Maximum: 500
28
31
  # @param [Integer, nil] only_ips If selected, only output IP addresses, ports and protocols.
29
32
  #
30
- # @return [Structs::BinaryEdge::Response]
33
+ # @return [Mihari::Structs::BinaryEdge::Response]
31
34
  #
32
35
  def search(query, page: 1, only_ips: nil)
33
36
  params = {
@@ -45,7 +48,7 @@ module Mihari
45
48
  # @param [Integer, nil] only_ips
46
49
  # @param [Integer] pagination_limit
47
50
  #
48
- # @return [Enumerable<Structs::BinaryEdge::Response.>]
51
+ # @return [Enumerable<Mihari::Structs::BinaryEdge::Response>]
49
52
  #
50
53
  def search_with_pagination(query, only_ips: nil, pagination_limit: Mihari.config.pagination_limit)
51
54
  Enumerator.new do |y|
@@ -4,6 +4,9 @@ require "base64"
4
4
 
5
5
  module Mihari
6
6
  module Clients
7
+ #
8
+ # Censys API client
9
+ #
7
10
  class Censys < Base
8
11
  #
9
12
  # @param [String] base_url
@@ -36,10 +39,10 @@ module Mihari
36
39
  # For more details, see our documentation: https://search.censys.io/api/v2/docs
37
40
  #
38
41
  # @param [String] query the query to be executed.
39
- # @params [Integer, nil] per_page the number of results to be returned for each page.
40
- # @params [Integer, nil] cursor the cursor of the desired result set.
42
+ # @param [Integer, nil] per_page the number of results to be returned for each page.
43
+ # @param [Integer, nil] cursor the cursor of the desired result set.
41
44
  #
42
- # @return [Structs::Censys::Response]
45
+ # @return [Mihari::Structs::Censys::Response]
43
46
  #
44
47
  def search(query, per_page: nil, cursor: nil)
45
48
  params = { q: query, per_page: per_page, cursor: cursor }.compact
@@ -52,7 +55,7 @@ module Mihari
52
55
  # @param [Integer, nil] per_page
53
56
  # @param [Integer] pagination_limit
54
57
  #
55
- # @return [Enumerable<Structs::Censys::Response>]
58
+ # @return [Enumerable<Mihari::Structs::Censys::Response>]
56
59
  #
57
60
  def search_with_pagination(query, per_page: nil, pagination_limit: Mihari.config.pagination_limit)
58
61
  cursor = nil