mihari 5.6.2 → 5.7.1

Sign up to get free protection for your applications and to get access to all the features.
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
data/lib/mihari/config.rb CHANGED
@@ -1,178 +1,167 @@
1
- module Mihari
2
- class Config
3
- # @return [String, nil]
4
- attr_reader :binaryedge_api_key
5
-
6
- # @return [String, nil]
7
- attr_reader :censys_id
8
-
9
- # @return [String, nil]
10
- attr_reader :censys_secret
11
-
12
- # @return [String, nil]
13
- attr_reader :circl_passive_password
14
-
15
- # @return [String, nil]
16
- attr_reader :circl_passive_username
17
-
18
- # @return [URI]
19
- attr_reader :database_url
20
-
21
- # @return [String, nil]
22
- attr_reader :greynoise_api_key
23
-
24
- # @return [String, nil]
25
- attr_reader :hunterhow_api_key
26
-
27
- # @return [String, nil]
28
- attr_reader :ipinfo_api_key
29
-
30
- # @return [String, nil]
31
- attr_reader :misp_url
32
-
33
- # @return [String, nil]
34
- attr_reader :misp_api_key
35
-
36
- # @return [String, nil]
37
- attr_reader :onyphe_api_key
38
-
39
- # @return [String, nil]
40
- attr_reader :otx_api_key
41
-
42
- # @return [String, nil]
43
- attr_reader :passivetotal_api_key
44
-
45
- # @return [String, nil]
46
- attr_reader :passivetotal_username
47
-
48
- # @return [String, nil]
49
- attr_reader :pulsedive_api_key
50
-
51
- # @return [String, nil]
52
- attr_reader :securitytrails_api_key
53
-
54
- # @return [String, nil]
55
- attr_reader :shodan_api_key
56
-
57
- # @return [String, nil]
58
- attr_reader :slack_channel
59
-
60
- # @return [String, nil]
61
- attr_reader :slack_webhook_url
62
-
63
- # @return [String, nil]
64
- attr_reader :thehive_url
1
+ # frozen_string_literal: true
65
2
 
66
- # @return [String, nil]
67
- attr_reader :thehive_api_key
3
+ require "anyway_config"
68
4
 
69
- # @return [String, nil]
70
- attr_reader :thehive_api_version
71
-
72
- # @return [String, nil]
73
- attr_reader :urlscan_api_key
74
-
75
- # @return [String, nil]
76
- attr_reader :virustotal_api_key
77
-
78
- # @return [String, nil]
79
- attr_reader :zoomeye_api_key
80
-
81
- # @return [String, nil]
82
- attr_reader :sentry_dsn
83
-
84
- # @return [Boolean]
85
- attr_accessor :hide_config_values
86
-
87
- # @return [Integer]
88
- attr_reader :retry_interval
89
-
90
- # @return [Integer]
91
- attr_reader :retry_times
92
-
93
- # @return [Boolean]
94
- attr_reader :retry_exponential_backoff
95
-
96
- # @return [Integer]
97
- attr_reader :pagination_interval
98
-
99
- # @return [Integer]
100
- attr_reader :pagination_limit
101
-
102
- # @return [Boolean]
103
- attr_reader :ignore_error
104
-
105
- def initialize
106
- load
107
- end
108
-
109
- def load
110
- @binaryedge_api_key = ENV.fetch("BINARYEDGE_API_KEY", nil)
111
-
112
- @censys_id = ENV.fetch("CENSYS_ID", nil)
113
- @censys_secret = ENV.fetch("CENSYS_SECRET", nil)
114
-
115
- @circl_passive_password = ENV.fetch("CIRCL_PASSIVE_PASSWORD", nil)
116
- @circl_passive_username = ENV.fetch("CIRCL_PASSIVE_USERNAME", nil)
117
-
118
- @database_url = URI(ENV.fetch("DATABASE_URL", "sqlite3:///mihari.db"))
119
-
120
- @greynoise_api_key = ENV.fetch("GREYNOISE_API_KEY", nil)
121
-
122
- @ipinfo_api_key = ENV.fetch("IPINFO_API_KEY", nil)
123
-
124
- @hunterhow_api_key = ENV.fetch("HUNTERHOW_API_KEY", nil)
5
+ module Mihari
6
+ class Config < Anyway::Config
7
+ config_name :mihari
8
+ env_prefix ""
9
+
10
+ attr_config(
11
+ # analyzers, emitters & enrichers
12
+ binaryedge_api_key: nil,
13
+ censys_id: nil,
14
+ censys_secret: nil,
15
+ circl_passive_password: nil,
16
+ circl_passive_username: nil,
17
+ database_url: URI("sqlite3:///mihari.db"),
18
+ fofa_api_key: nil,
19
+ fofa_email: nil,
20
+ greynoise_api_key: nil,
21
+ hunterhow_api_key: nil,
22
+ ipinfo_api_key: nil,
23
+ misp_api_key: nil,
24
+ misp_url: nil,
25
+ onyphe_api_key: nil,
26
+ otx_api_key: nil,
27
+ passivetotal_api_key: nil,
28
+ passivetotal_username: nil,
29
+ pulsedive_api_key: nil,
30
+ securitytrails_api_key: nil,
31
+ shodan_api_key: nil,
32
+ slack_channel: nil,
33
+ slack_webhook_url: nil,
34
+ thehive_api_key: nil,
35
+ thehive_api_version: nil,
36
+ thehive_url: nil,
37
+ urlscan_api_key: nil,
38
+ virustotal_api_key: nil,
39
+ zoomeye_api_key: nil,
40
+ # others
41
+ hide_config_values: true,
42
+ ignore_error: false,
43
+ pagination_interval: 0,
44
+ pagination_limit: 100,
45
+ retry_exponential_backoff: true,
46
+ retry_interval: 5,
47
+ retry_times: 3,
48
+ sentry_dsn: nil
49
+ )
50
+
51
+ # @!attribute [r] binaryedge_api_key
52
+ # @return [String, nil]
53
+
54
+ # @!attribute [r] censys_id
55
+ # @return [String, nil]
125
56
 
126
- @misp_url = ENV.fetch("MISP_URL", nil)
127
- @misp_api_key = ENV.fetch("MISP_API_KEY", nil)
57
+ # @!attribute [r] circl_passive_password
58
+ # @return [String, nil]
59
+
60
+ # @!attribute [r] circl_passive_username
61
+ # @return [String, nil]
62
+
63
+ # @!attribute [r] database_url
64
+ # @return [String, nil]
65
+
66
+ # @!attribute [r] fofa_api_key
67
+ # @return [String, nil]
68
+
69
+ # @!attribute [r] fofa_email
70
+ # @return [String, nil]
71
+
72
+ # @!attribute [r] greynoise_api_key
73
+ # @return [String, nil]
74
+
75
+ # @!attribute [r] hunterhow_api_key
76
+ # @return [String, nil]
77
+
78
+ # @!attribute [r] ipinfo_api_key
79
+ # @return [String, nil]
80
+
81
+ # @!attribute [r] misp_url
82
+ # @return [String, nil]
83
+
84
+ # @!attribute [r] misp_api_key
85
+ # @return [String, nil]
86
+
87
+ # @!attribute [r] onyphe_api_key
88
+ # @return [String, nil]
89
+
90
+ # @!attribute [r] otx_api_key
91
+ # @return [String, nil]
92
+
93
+ # @!attribute [r] passivetotal_api_key
94
+ # @return [String, nil]
95
+
96
+ # @!attribute [r] passivetotal_username
97
+ # @return [String, nil]
98
+
99
+ # @!attribute [r] pulsedive_api_key
100
+ # @return [String, nil]
101
+
102
+ # @!attribute [r] securitytrails_api_key
103
+ # @return [String, nil]
104
+
105
+ # @!attribute [r] shodan_api_key
106
+ # @return [String, nil]
128
107
 
129
- @onyphe_api_key = ENV.fetch("ONYPHE_API_KEY", nil)
108
+ # @!attribute [r] slack_channel
109
+ # @return [String, nil]
110
+
111
+ # @!attribute [r] slack_webhook_url
112
+ # @return [String, nil]
130
113
 
131
- @otx_api_key = ENV.fetch("OTX_API_KEY", nil)
114
+ # @!attribute [r] thehive_url
115
+ # @return [String, nil]
132
116
 
133
- @passivetotal_api_key = ENV.fetch("PASSIVETOTAL_API_KEY", nil)
134
- @passivetotal_username = ENV.fetch("PASSIVETOTAL_USERNAME", nil)
117
+ # @!attribute [r] thehive_api_key
118
+ # @return [String, nil]
135
119
 
136
- @pulsedive_api_key = ENV.fetch("PULSEDIVE_API_KEY", nil)
120
+ # @!attribute [r] thehive_api_version
121
+ # @return [String, nil]
137
122
 
138
- @securitytrails_api_key = ENV.fetch("SECURITYTRAILS_API_KEY", nil)
123
+ # @!attribute [r] urlscan_api_key
124
+ # @return [String, nil]
139
125
 
140
- @shodan_api_key = ENV.fetch("SHODAN_API_KEY", nil)
126
+ # @!attribute [r] virustotal_api_key
127
+ # @return [String, nil]
141
128
 
142
- @slack_channel = ENV.fetch("SLACK_CHANNEL", nil)
143
- @slack_webhook_url = ENV.fetch("SLACK_WEBHOOK_URL", nil)
129
+ # @!attribute [r] zoomeye_api_key
130
+ # @return [String, nil]
144
131
 
145
- @thehive_url = ENV.fetch("THEHIVE_URL", nil)
146
- @thehive_api_key = ENV.fetch("THEHIVE_API_KEY", nil)
147
- @thehive_api_version = ENV.fetch("THEHIVE_API_VERSION", nil)
132
+ # @!attribute [r] sentry_dsn
133
+ # @return [String, nil]
148
134
 
149
- @urlscan_api_key = ENV.fetch("URLSCAN_API_KEY", nil)
135
+ # @!attribute [r] retry_interval
136
+ # @return [Integer]
150
137
 
151
- @virustotal_api_key = ENV.fetch("VIRUSTOTAL_API_KEY", nil)
138
+ # @!attribute [r] retry_times
139
+ # @return [Integer]
152
140
 
153
- @zoomeye_api_key = ENV.fetch("ZOOMEYE_API_KEY", nil)
141
+ # @!attribute [r] retry_exponential_backoff
142
+ # @return [Boolean]
154
143
 
155
- @sentry_dsn = ENV.fetch("SENTRY_DSN", nil)
144
+ # @!attribute [r] pagination_interval
145
+ # @return [Integer]
156
146
 
157
- @hide_config_values = ENV.fetch("HIDE_CONFIG_VALUES", true)
147
+ # @!attribute [r] pagination_limit
148
+ # @return [Integer]
158
149
 
159
- @retry_times = ENV.fetch("RETRY_TIMES", 3).to_i
160
- @retry_interval = ENV.fetch("RETRY_INTERVAL", 5).to_i
161
- @retry_exponential_backoff = ENV.fetch("RETRY_EXPONENTIAL_BACKOFF", true).to_s.downcase == "true"
150
+ # @!attribute [r] ignore_error
151
+ # @return [Boolean]
162
152
 
163
- @pagination_interval = ENV.fetch("PAGINATION_INTERVAL", 0).to_i
164
- @pagination_limit = ENV.fetch("PAGINATION_LIMIT", 100).to_i
153
+ # @!attribute [rw] hide_config_values
154
+ # @return [Boolean]
165
155
 
166
- @ignore_error = ENV.fetch("IGNORE_ERROR", false)
156
+ def database_url=(val)
157
+ super URI(val.to_s)
167
158
  end
168
159
 
169
160
  #
170
161
  # @return [Array<String>]
171
162
  #
172
163
  def keys
173
- instance_variables.map do |key|
174
- key[1..].to_s.upcase
175
- end
164
+ to_h.keys.map(&:to_s).map(&:upcase)
176
165
  end
177
166
  end
178
167
  end
@@ -5,7 +5,7 @@ module Mihari
5
5
  DEFAULT_DATA_TYPES = Types::DataTypes.values.freeze
6
6
 
7
7
  # @return [Array<Hash>]
8
- DEFAULT_EMITTERS = %w[database].map { |name| { emitter: name } }.freeze
8
+ DEFAULT_EMITTERS = Emitters::Database.class_keys.map { |name| { emitter: name } }.freeze
9
9
 
10
10
  # @return [Array<Hash>]
11
11
  DEFAULT_ENRICHERS = Mihari.enricher_to_class.keys.map { |name| { enricher: name.downcase } }.freeze
@@ -13,6 +13,9 @@ def development_env?
13
13
  env == "development"
14
14
  end
15
15
 
16
+ #
17
+ # Mihari v5 DB schema
18
+ #
16
19
  class V5Schema < ActiveRecord::Migration[7.1]
17
20
  def change
18
21
  create_table :rules, id: :string, if_not_exists: true do |t|
@@ -125,6 +128,9 @@ def schemas
125
128
  end
126
129
 
127
130
  module Mihari
131
+ #
132
+ # Database
133
+ #
128
134
  class Database
129
135
  class << self
130
136
  #
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Emitters
5
+ #
6
+ # Base class for emitters
7
+ #
5
8
  class Base < Actor
6
9
  # @return [Mihari::Rule]
7
10
  attr_reader :rule
@@ -9,9 +12,8 @@ module Mihari
9
12
  #
10
13
  # @param [Mihari::Rule] rule
11
14
  # @param [Hash, nil] options
12
- # @param [Hash] **_params
13
15
  #
14
- def initialize(rule:, options: nil, **_params)
16
+ def initialize(rule:, options: nil)
15
17
  super(options: options)
16
18
 
17
19
  @rule = rule
@@ -20,23 +22,23 @@ module Mihari
20
22
  #
21
23
  # @param [Array<Mihari::Models::Artifact>] artifacts
22
24
  #
23
- def emit_result(artifacts)
25
+ def call(artifacts)
26
+ raise NotImplementedError, "You must implement #{self.class}##{__method__}"
27
+ end
28
+
29
+ #
30
+ # @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
31
+ #
32
+ def result(artifacts)
24
33
  Try[StandardError] do
25
34
  retry_on_error(
26
35
  times: retry_times,
27
36
  interval: retry_interval,
28
37
  exponential_backoff: retry_exponential_backoff
29
- ) { emit artifacts }
38
+ ) { call(artifacts) }
30
39
  end.to_result
31
40
  end
32
41
 
33
- #
34
- # @param [Array<Mihari::Models::Artifact>] artifacts
35
- #
36
- def emit(artifacts)
37
- raise NotImplementedError, "You must implement #{self.class}##{__method__}"
38
- end
39
-
40
42
  class << self
41
43
  def inherited(child)
42
44
  super
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Mihari
4
4
  module Emitters
5
+ #
6
+ # Database emitter
7
+ #
5
8
  class Database < Base
6
9
  #
7
10
  # Create an alert
@@ -10,7 +13,7 @@ module Mihari
10
13
  #
11
14
  # @return [Mihari::Models::Alert, nil]
12
15
  #
13
- def emit(artifacts)
16
+ def call(artifacts)
14
17
  return if artifacts.empty?
15
18
 
16
19
  tags = rule.tags.filter_map { |name| Models::Tag.find_or_create_by(name: name) }.uniq
@@ -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,16 +12,16 @@ module Mihari
9
12
  # @return [String, nil]
10
13
  attr_reader :api_key
11
14
 
12
- # @return [Mihari::Services::Rule]
15
+ # @return [Mihari::Rule]
13
16
  attr_reader :rule
14
17
 
15
18
  # @return [Array<Mihari::Models::Artifact>]
16
19
  attr_accessor :artifacts
17
20
 
18
21
  #
19
- # @param [Mihari::Services::Rule] rule
22
+ # @param [Mihari::Rule] rule
20
23
  # @param [Hash, nil] options
21
- # @param [Hash] **params
24
+ # @param [Hash, nil] params
22
25
  #
23
26
  def initialize(rule:, options: nil, **params)
24
27
  super(rule: rule, options: options)
@@ -41,7 +44,7 @@ module Mihari
41
44
  #
42
45
  # @param [Array<Mihari::Models::Artifact>] artifacts
43
46
  #
44
- def emit(artifacts)
47
+ def call(artifacts)
45
48
  return if artifacts.empty?
46
49
 
47
50
  client.create_event({
@@ -135,9 +135,9 @@ module Mihari
135
135
  attr_accessor :artifacts
136
136
 
137
137
  #
138
- # @param [Mihari::Services::Rule] rule
138
+ # @param [Mihari::Rule] rule
139
139
  # @param [Hash, nil] options
140
- # @param [Hash] **params
140
+ # @param [Hash, nil] params
141
141
  #
142
142
  def initialize(rule:, options: nil, **params)
143
143
  super(rule: rule, options: options)
@@ -216,7 +216,7 @@ module Mihari
216
216
  #
217
217
  # @param [Array<Mihari::Models::Artifact>] artifacts
218
218
  #
219
- def emit(artifacts)
219
+ def call(artifacts)
220
220
  return if artifacts.empty?
221
221
 
222
222
  @artifacts = artifacts
@@ -16,9 +16,9 @@ module Mihari
16
16
  attr_accessor :artifacts
17
17
 
18
18
  #
19
- # @param [Mihari::Services::Rule] rule
19
+ # @param [Mihari::Rule] rule
20
20
  # @param [Hash, nil] options
21
- # @param [Hash] **params
21
+ # @param [Hash] params
22
22
  #
23
23
  def initialize(rule:, options: nil, **params)
24
24
  super(rule: rule, options: options)
@@ -42,7 +42,7 @@ module Mihari
42
42
  #
43
43
  # @param [Array<Mihari::Models::Artifact>] artifacts
44
44
  #
45
- def emit(artifacts)
45
+ def call(artifacts)
46
46
  return if artifacts.empty?
47
47
 
48
48
  @artifacts = artifacts
@@ -61,8 +61,9 @@ module Mihari
61
61
  attr_accessor :artifacts
62
62
 
63
63
  #
64
- # @param [Mihari::Services::Rule] rule
65
- # @param [Hash] **options
64
+ # @param [Mihari::Rule] rule
65
+ # @param [Hash, nil] options
66
+ # @param [Hash, nil] params
66
67
  #
67
68
  def initialize(rule:, options: nil, **params)
68
69
  super(rule: rule, options: options)
@@ -87,7 +88,7 @@ module Mihari
87
88
  #
88
89
  # @param [Array<Mihari::Models::Artifact>] artifacts
89
90
  #
90
- def emit(artifacts)
91
+ def call(artifacts)
91
92
  return if artifacts.empty?
92
93
 
93
94
  @artifacts = artifacts
@@ -2,28 +2,34 @@
2
2
 
3
3
  module Mihari
4
4
  module Enrichers
5
+ #
6
+ # Base class for enrichers
7
+ #
5
8
  class Base < Actor
6
9
  def initialize(options: nil)
7
10
  super(options: options)
8
11
  end
9
12
 
10
- 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)
11
24
  Try[StandardError] do
12
25
  retry_on_error(
13
26
  times: retry_times,
14
27
  interval: retry_interval,
15
28
  exponential_backoff: retry_exponential_backoff
16
- ) { query value }
29
+ ) { call value }
17
30
  end.to_result
18
31
  end
19
32
 
20
- #
21
- # @param [String] value
22
- #
23
- def query(value)
24
- raise NotImplementedError, "You must implement #{self.class}##{__method__}"
25
- end
26
-
27
33
  class << self
28
34
  def inherited(child)
29
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
@@ -27,16 +28,17 @@ module Mihari
27
28
  #
28
29
  # @param [String] ip
29
30
  #
30
- # @return [Mihari::Structs::IPInfo::Response, nil]
31
+ # @return [Mihari::Structs::IPInfo::Response]
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