mihari 4.11.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +1 -1
  3. data/README.md +13 -3
  4. data/Steepfile +0 -1
  5. data/build_frontend.sh +0 -3
  6. data/docker/Dockerfile +11 -12
  7. data/images/Tines-Full_Logo-Tines_Black.png +0 -0
  8. data/lib/mihari/analyzers/base.rb +12 -28
  9. data/lib/mihari/analyzers/rule.rb +23 -36
  10. data/lib/mihari/cli/main.rb +6 -11
  11. data/lib/mihari/commands/initializer.rb +47 -0
  12. data/lib/mihari/commands/{search.rb → searcher.rb} +9 -20
  13. data/lib/mihari/commands/validator.rb +2 -2
  14. data/lib/mihari/commands/web.rb +4 -2
  15. data/lib/mihari/constants.rb +3 -3
  16. data/lib/mihari/database.rb +52 -87
  17. data/lib/mihari/emitters/database.rb +16 -7
  18. data/lib/mihari/emitters/misp.rb +13 -5
  19. data/lib/mihari/emitters/slack.rb +15 -8
  20. data/lib/mihari/emitters/the_hive.rb +42 -21
  21. data/lib/mihari/emitters/webhook.rb +99 -31
  22. data/lib/mihari/entities/alert.rb +7 -5
  23. data/lib/mihari/entities/artifact.rb +20 -8
  24. data/lib/mihari/entities/config.rb +2 -6
  25. data/lib/mihari/entities/rule.rb +8 -0
  26. data/lib/mihari/http.rb +13 -13
  27. data/lib/mihari/mixins/{disallowed_data_value.rb → falsepositive.rb} +8 -8
  28. data/lib/mihari/models/alert.rb +2 -15
  29. data/lib/mihari/models/artifact.rb +28 -17
  30. data/lib/mihari/models/rule.rb +7 -13
  31. data/lib/mihari/schemas/emitter.rb +6 -8
  32. data/lib/mihari/schemas/rule.rb +11 -13
  33. data/lib/mihari/structs/config.rb +41 -0
  34. data/lib/mihari/structs/filters.rb +2 -2
  35. data/lib/mihari/structs/rule.rb +96 -83
  36. data/lib/mihari/templates/rule.yml.erb +5 -23
  37. data/lib/mihari/types.rb +1 -1
  38. data/lib/mihari/version.rb +1 -1
  39. data/lib/mihari/web/api.rb +0 -2
  40. data/lib/mihari/web/app.rb +10 -4
  41. data/lib/mihari/web/endpoints/alerts.rb +11 -3
  42. data/lib/mihari/web/endpoints/configs.rb +1 -6
  43. data/lib/mihari/web/endpoints/rules.rb +27 -15
  44. data/lib/mihari/web/public/assets/{fa-brands-400.c7ae37d3.ttf → fa-brands-400-2ef6fdde.ttf} +0 -0
  45. data/lib/mihari/web/public/assets/fa-brands-400-f4617423.woff2 +0 -0
  46. data/lib/mihari/web/public/assets/fa-regular-400-12dea17b.ttf +0 -0
  47. data/lib/mihari/web/public/assets/fa-regular-400-7ba24c41.woff2 +0 -0
  48. data/lib/mihari/web/public/assets/fa-solid-900-67a880b4.ttf +0 -0
  49. data/lib/mihari/web/public/assets/fa-solid-900-e2c5cf54.woff2 +0 -0
  50. data/lib/mihari/web/public/assets/fa-v4compatibility-7c377405.woff2 +0 -0
  51. data/lib/mihari/web/public/assets/fa-v4compatibility-8d9500e8.ttf +0 -0
  52. data/lib/mihari/web/public/assets/{index.e1e67d84.css → index-625e95fe.css} +3 -3
  53. data/lib/mihari/web/public/assets/index-63900d73.js +50 -0
  54. data/lib/mihari/web/public/index.html +3 -3
  55. data/lib/mihari/web/public/redoc-static.html +26 -27
  56. data/lib/mihari.rb +11 -21
  57. data/mihari.gemspec +14 -14
  58. metadata +46 -131
  59. data/lib/mihari/cli/init.rb +0 -11
  60. data/lib/mihari/cli/validator.rb +0 -11
  61. data/lib/mihari/commands/init.rb +0 -51
  62. data/lib/mihari/emitters/http.rb +0 -127
  63. data/lib/mihari/entities/source.rb +0 -9
  64. data/lib/mihari/status.rb +0 -55
  65. data/lib/mihari/web/endpoints/sources.rb +0 -19
  66. data/lib/mihari/web/public/assets/fa-brands-400.3fe890d0.woff2 +0 -0
  67. data/lib/mihari/web/public/assets/fa-regular-400.fdc1f753.ttf +0 -0
  68. data/lib/mihari/web/public/assets/fa-regular-400.fe69d948.woff2 +0 -0
  69. data/lib/mihari/web/public/assets/fa-solid-900.6d53c706.ttf +0 -0
  70. data/lib/mihari/web/public/assets/fa-solid-900.d27bc752.woff2 +0 -0
  71. data/lib/mihari/web/public/assets/fa-v4compatibility.4d73f280.ttf +0 -0
  72. data/lib/mihari/web/public/assets/fa-v4compatibility.7d1c2ce5.woff2 +0 -0
  73. data/lib/mihari/web/public/assets/index.d3a61a69.js +0 -68
  74. data/sig/lib/mihari/analyzers/base.rbs +0 -90
  75. data/sig/lib/mihari/analyzers/binaryedge.rbs +0 -26
  76. data/sig/lib/mihari/analyzers/censys.rbs +0 -41
  77. data/sig/lib/mihari/analyzers/circl.rbs +0 -31
  78. data/sig/lib/mihari/analyzers/crtsh.rbs +0 -17
  79. data/sig/lib/mihari/analyzers/dnpedia.rbs +0 -15
  80. data/sig/lib/mihari/analyzers/dnstwister.rbs +0 -25
  81. data/sig/lib/mihari/analyzers/feed.rbs +0 -20
  82. data/sig/lib/mihari/analyzers/onyphe.rbs +0 -34
  83. data/sig/lib/mihari/analyzers/otx.rbs +0 -33
  84. data/sig/lib/mihari/analyzers/passivetotal.rbs +0 -35
  85. data/sig/lib/mihari/analyzers/pulsedive.rbs +0 -27
  86. data/sig/lib/mihari/analyzers/rule.rbs +0 -68
  87. data/sig/lib/mihari/analyzers/securitytrails.rbs +0 -33
  88. data/sig/lib/mihari/analyzers/shodan.rbs +0 -36
  89. data/sig/lib/mihari/analyzers/urlscan.rbs +0 -31
  90. data/sig/lib/mihari/analyzers/virustotal.rbs +0 -31
  91. data/sig/lib/mihari/analyzers/virustotal_intelligence.rbs +0 -33
  92. data/sig/lib/mihari/analyzers/zoomeye.rbs +0 -35
  93. data/sig/lib/mihari/cli/base.rbs +0 -9
  94. data/sig/lib/mihari/cli/init.rbs +0 -7
  95. data/sig/lib/mihari/cli/main.rbs +0 -9
  96. data/sig/lib/mihari/cli/validator.rbs +0 -7
  97. data/sig/lib/mihari/commands/init.rbs +0 -9
  98. data/sig/lib/mihari/commands/json.rbs +0 -7
  99. data/sig/lib/mihari/commands/search.rbs +0 -35
  100. data/sig/lib/mihari/commands/validator.rbs +0 -9
  101. data/sig/lib/mihari/commands/web.rbs +0 -7
  102. data/sig/lib/mihari/constants.rbs +0 -5
  103. data/sig/lib/mihari/database.rbs +0 -25
  104. data/sig/lib/mihari/emitters/base.rbs +0 -18
  105. data/sig/lib/mihari/emitters/database.rbs +0 -9
  106. data/sig/lib/mihari/emitters/http.rbs +0 -35
  107. data/sig/lib/mihari/emitters/misp.rbs +0 -34
  108. data/sig/lib/mihari/emitters/slack.rbs +0 -73
  109. data/sig/lib/mihari/emitters/stdout.rbs +0 -9
  110. data/sig/lib/mihari/emitters/the_hive.rbs +0 -32
  111. data/sig/lib/mihari/emitters/webhook.rbs +0 -20
  112. data/sig/lib/mihari/enrichers/base.rbs +0 -12
  113. data/sig/lib/mihari/enrichers/google_public_dns.rbs +0 -18
  114. data/sig/lib/mihari/enrichers/ipinfo.rbs +0 -16
  115. data/sig/lib/mihari/errors.rbs +0 -10
  116. data/sig/lib/mihari/feed/parser.rbs +0 -11
  117. data/sig/lib/mihari/feed/reader.rbs +0 -56
  118. data/sig/lib/mihari/http.rbs +0 -64
  119. data/sig/lib/mihari/mixins/autonomous_system.rbs +0 -14
  120. data/sig/lib/mihari/mixins/configurable.rbs +0 -30
  121. data/sig/lib/mihari/mixins/configuration.rbs +0 -45
  122. data/sig/lib/mihari/mixins/disallowed_data_value.rbs +0 -23
  123. data/sig/lib/mihari/mixins/error_notification.rbs +0 -12
  124. data/sig/lib/mihari/mixins/hash.rbs +0 -14
  125. data/sig/lib/mihari/mixins/refang.rbs +0 -14
  126. data/sig/lib/mihari/mixins/retriable.rbs +0 -15
  127. data/sig/lib/mihari/models/alert.rbs +0 -18
  128. data/sig/lib/mihari/models/artifact.rbs +0 -69
  129. data/sig/lib/mihari/models/autonomous_system.rbs +0 -14
  130. data/sig/lib/mihari/models/cpe.rbs +0 -7
  131. data/sig/lib/mihari/models/dns.rbs +0 -19
  132. data/sig/lib/mihari/models/geolocation.rbs +0 -15
  133. data/sig/lib/mihari/models/port.rbs +0 -7
  134. data/sig/lib/mihari/models/reverse_dns.rbs +0 -14
  135. data/sig/lib/mihari/models/rule.rbs +0 -17
  136. data/sig/lib/mihari/models/tag.rbs +0 -5
  137. data/sig/lib/mihari/models/tagging.rbs +0 -4
  138. data/sig/lib/mihari/models/whois.rbs +0 -66
  139. data/sig/lib/mihari/status.rbs +0 -25
  140. data/sig/lib/mihari/structs/censys.rbs +0 -58
  141. data/sig/lib/mihari/structs/filters.rbs +0 -40
  142. data/sig/lib/mihari/structs/google_public_dns.rbs +0 -21
  143. data/sig/lib/mihari/structs/greynoise.rbs +0 -30
  144. data/sig/lib/mihari/structs/ipinfo.rbs +0 -17
  145. data/sig/lib/mihari/structs/onyphe.rbs +0 -25
  146. data/sig/lib/mihari/structs/rule.rbs +0 -57
  147. data/sig/lib/mihari/structs/shodan.rbs +0 -30
  148. data/sig/lib/mihari/structs/urlscan.rbs +0 -28
  149. data/sig/lib/mihari/structs/virustotal_intelligence.rbs +0 -33
  150. data/sig/lib/mihari/type_checker.rbs +0 -48
  151. data/sig/lib/mihari/types.rbs +0 -23
  152. data/sig/lib/mihari/version.rbs +0 -3
  153. data/sig/lib/mihari/web/app.rbs +0 -5
  154. data/sig/lib/mihari.rbs +0 -54
@@ -2,15 +2,11 @@
2
2
 
3
3
  module Mihari
4
4
  module Entities
5
- class ConfigStatus < Grape::Entity
5
+ class Config < Grape::Entity
6
+ expose :name, documentation: { type: String, required: true }
6
7
  expose :type, documentation: { type: String, required: true }
7
8
  expose :values, documentation: { type: String, is_array: true, required: true }
8
9
  expose :is_configured, documentation: { type: Grape::API::Boolean, required: true }, as: :isConfigured
9
10
  end
10
-
11
- class Config < Grape::Entity
12
- expose :name, documentation: { type: String, required: true }
13
- expose :status, using: Entities::ConfigStatus, documentation: { type: ConfigStatus, required: true }
14
- end
15
11
  end
16
12
  end
@@ -14,9 +14,13 @@ module Mihari
14
14
 
15
15
  class Rule < Grape::Entity
16
16
  expose :id, documentation: { type: String, required: true }
17
+ expose :title, documentation: { type: String, required: true }
18
+ expose :description, documentation: { type: String, required: true }
17
19
  expose :yaml, documentation: { type: String, required: true }
18
20
  expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt
19
21
  expose :updated_at, documentation: { type: DateTime, required: true }, as: :updatedAt
22
+
23
+ expose :tags, using: Entities::Tag, documentation: { type: Entities::Tag, is_array: true, required: true }
20
24
  end
21
25
 
22
26
  class RulesWithPagination < Grape::Entity
@@ -25,5 +29,9 @@ module Mihari
25
29
  expose :current_page, documentation: { type: Integer, required: true }, as: :currentPage
26
30
  expose :page_size, documentation: { type: Integer, required: true }, as: :pageSize
27
31
  end
32
+
33
+ class RuleIDs < Grape::Entity
34
+ expose :rule_ids, documentation: { type: Array[String], required: true }, as: :ruleIds
35
+ end
28
36
  end
29
37
  end
data/lib/mihari/http.rb CHANGED
@@ -4,10 +4,10 @@ require "insensitive_hash"
4
4
 
5
5
  module Mihari
6
6
  class HTTP
7
- attr_reader :uri, :headers, :payload
7
+ attr_reader :url, :headers, :payload
8
8
 
9
- def initialize(uri, headers: {}, payload: {})
10
- @uri = uri.is_a?(URI) ? uri : URI(uri.to_s)
9
+ def initialize(url, headers: {}, payload: {})
10
+ @url = url.is_a?(URI) ? url : URI(url.to_s)
11
11
  @headers = headers.insensitive
12
12
  @payload = payload
13
13
  end
@@ -18,10 +18,10 @@ module Mihari
18
18
  # @return [Net::HTTPResponse]
19
19
  #
20
20
  def get
21
- new_uri = uri.deep_dup
22
- new_uri.query = Addressable::URI.form_encode(payload) unless payload.empty?
21
+ new_url = url.deep_dup
22
+ new_url.query = Addressable::URI.form_encode(payload) unless payload.empty?
23
23
 
24
- get = Net::HTTP::Get.new(new_uri)
24
+ get = Net::HTTP::Get.new(new_url)
25
25
  request get
26
26
  end
27
27
 
@@ -31,7 +31,7 @@ module Mihari
31
31
  # @return [Net::HTTPResponse]
32
32
  #
33
33
  def post
34
- post = Net::HTTP::Post.new(uri)
34
+ post = Net::HTTP::Post.new(url)
35
35
 
36
36
  case content_type
37
37
  when "application/json"
@@ -44,13 +44,13 @@ module Mihari
44
44
  end
45
45
 
46
46
  class << self
47
- def get(uri, headers: {}, params: {})
48
- client = new(uri, headers: headers, payload: params)
47
+ def get(url, headers: {}, params: {})
48
+ client = new(url, headers: headers, payload: params)
49
49
  client.get
50
50
  end
51
51
 
52
- def post(uri, headers: {}, payload: {})
53
- client = new(uri, headers: headers, payload: payload)
52
+ def post(url, headers: {}, payload: {})
53
+ client = new(url, headers: headers, payload: payload)
54
54
  client.post
55
55
  end
56
56
  end
@@ -67,7 +67,7 @@ module Mihari
67
67
  # @return [Hahs]
68
68
  #
69
69
  def https_options
70
- return { use_ssl: true } if uri.scheme == "https"
70
+ return { use_ssl: true } if url.scheme == "https"
71
71
 
72
72
  {}
73
73
  end
@@ -80,7 +80,7 @@ module Mihari
80
80
  # @return [Net::HTTPResponse]
81
81
  #
82
82
  def request(req)
83
- Net::HTTP.start(uri.host, uri.port, https_options) do |http|
83
+ Net::HTTP.start(url.host, url.port, https_options) do |http|
84
84
  # set headers
85
85
  headers.each do |k, v|
86
86
  req[k] = v
@@ -2,24 +2,24 @@
2
2
 
3
3
  module Mihari
4
4
  module Mixins
5
- module DisallowedDataValue
5
+ module FalsePositive
6
6
  include Memist::Memoizable
7
7
 
8
8
  #
9
- # Normalize a value as a disallowed data value
9
+ # Normalize a falsepositive value
10
10
  #
11
- # @param [String] value Data value
11
+ # @param [String] value
12
12
  #
13
- # @return [String, Regexp] Normalized value
13
+ # @return [String, Regexp]
14
14
  #
15
- def normalize_disallowed_data_value(value)
15
+ def normalize_falsepositive(value)
16
16
  return value if !value.start_with?("/") || !value.end_with?("/")
17
17
 
18
18
  # if a value is surrounded by slashes, take it as a regexp
19
19
  value_without_slashes = value[1..-2]
20
20
  Regexp.compile value_without_slashes.to_s
21
21
  end
22
- memoize :normalize_disallowed_data_value
22
+ memoize :normalize_falsepositive
23
23
 
24
24
  #
25
25
  # Check whetehr a value is valid format as a disallowed data value
@@ -28,9 +28,9 @@ module Mihari
28
28
  #
29
29
  # @return [Boolean] true if it is valid, otherwise false
30
30
  #
31
- def valid_disallowed_data_value?(value)
31
+ def valid_falsepositive?(value)
32
32
  begin
33
- normalize_disallowed_data_value value
33
+ normalize_falsepositive value
34
34
  rescue RegexpError
35
35
  return false
36
36
  end
@@ -28,20 +28,7 @@ module Mihari
28
28
  relation = build_relation(filter.without_pagination)
29
29
 
30
30
  alert_ids = relation.limit(limit).offset(offset).order(id: :desc).pluck(:id).uniq
31
- eager_load(
32
- {
33
- artifacts: [
34
- :autonomous_system,
35
- :geolocation,
36
- :whois_record,
37
- :dns_records,
38
- :reverse_dns_names,
39
- :cpes,
40
- :ports
41
- ]
42
- },
43
- :tags
44
- ).where(id: [alert_ids]).order(id: :desc)
31
+ eager_load(:artifacts, :tags).where(id: [alert_ids]).order(id: :desc)
45
32
  end
46
33
 
47
34
  #
@@ -83,7 +70,7 @@ module Mihari
83
70
  relation = relation.where(artifacts: { id: artifact_ids }) unless artifact_ids.empty?
84
71
  relation = relation.where(tags: { name: filter.tag_name }) if filter.tag_name
85
72
 
86
- relation = relation.where(source: filter.source) if filter.source
73
+ relation = relation.where(rule_id: filter.rule_id) if filter.rule_id
87
74
  relation = relation.where(title: filter.title) if filter.title
88
75
 
89
76
  relation = relation.where("description LIKE ?", "%#{filter.description}%") if filter.description
@@ -25,8 +25,12 @@ module Mihari
25
25
 
26
26
  validates_with ArtifactValidator
27
27
 
28
+ # @return [Array<Mihari::Tag>] Tags
28
29
  attr_accessor :tags
29
30
 
31
+ # @return [String, nil] Rule ID
32
+ attr_accessor :rule_id
33
+
30
34
  def initialize(*args, **kwargs)
31
35
  attrs = args.first || kwargs
32
36
  data_ = attrs[:data]
@@ -36,27 +40,34 @@ module Mihari
36
40
  super(*args, **kwargs)
37
41
 
38
42
  self.data_type = TypeChecker.type(data)
39
- self.tags = []
43
+
44
+ @tags = []
45
+ @rule_id = ""
40
46
  end
41
47
 
42
48
  #
43
49
  # Check uniqueness of artifact
44
50
  #
45
- # @param [Boolean] ignore_old_artifacts
46
- # @param [Integer] ignore_threshold
51
+ # @param [Time, nil] base_time Base time to check decaying
52
+ # @param [Integer, nil] artifact_lifetime Artifact lifetime (TTL) in seconds
47
53
  #
48
54
  # @return [Boolean] true if it is unique. Otherwise false.
49
55
  #
50
- def unique?(ignore_old_artifacts: false, ignore_threshold: 0)
51
- artifact = self.class.where(data: data).order(created_at: :desc).first
56
+ def unique?(base_time: nil, artifact_lifetime: nil)
57
+ artifact = self.class.joins(:alert).where(
58
+ data: data,
59
+ alert: { rule_id: rule_id }
60
+ ).order(created_at: :desc).first
52
61
  return true if artifact.nil?
53
62
 
54
- return false unless ignore_old_artifacts
63
+ # check whetehr the artifact is decayed or not
64
+ return false if artifact_lifetime.nil?
65
+
66
+ # use the current UTC time if base_time is not given (for testing)
67
+ base_time ||= Time.now.utc
55
68
 
56
- days_before = (-ignore_threshold).days.from_now.utc
57
- # if an artifact is created before {ignore_threshold} days, ignore it
58
- # within {ignore_threshold} days, do not ignore it
59
- artifact.created_at < days_before
69
+ decayed_at = base_time - (artifact_lifetime || -1).seconds
70
+ artifact.created_at < decayed_at
60
71
  end
61
72
 
62
73
  #
@@ -139,14 +150,14 @@ module Mihari
139
150
  whois: [
140
151
  :enrich_whois
141
152
  ],
142
- ipinfo: [
143
- :enrich_autonomous_system,
144
- :enrich_geolocation
153
+ ipinfo: %i[
154
+ enrich_autonomous_system
155
+ enrich_geolocation
145
156
  ],
146
- shodan: [
147
- :enrich_ports,
148
- :enrich_cpes,
149
- :enrich_reverse_dns
157
+ shodan: %i[
158
+ enrich_ports
159
+ enrich_cpes
160
+ enrich_reverse_dns
150
161
  ],
151
162
  google_public_dns: [
152
163
  :enrich_dns
@@ -4,24 +4,18 @@ require "yaml"
4
4
 
5
5
  module Mihari
6
6
  class Rule < ActiveRecord::Base
7
- has_many :alerts, foreign_key: :source
7
+ has_many :alerts, dependent: :destroy
8
8
 
9
9
  def symbolized_data
10
10
  @symbolized_data ||= data.deep_symbolize_keys
11
11
  end
12
12
 
13
- #
14
- # Returns a hash representative
15
- #
16
- # @return [Hash]
17
- #
18
- def to_h
19
- {
20
- id: id,
21
- yaml: yaml || data.to_yaml,
22
- created_at: created_at,
23
- updated_at: updated_at
24
- }
13
+ def yaml
14
+ data.to_yaml
15
+ end
16
+
17
+ def tags
18
+ (data["tags"] || []).map { |tag| { name: tag } }
25
19
  end
26
20
 
27
21
  class << self
@@ -2,20 +2,18 @@
2
2
 
3
3
  module Mihari
4
4
  module Schemas
5
- Emitter = Dry::Schema.Params do
6
- required(:emitter).value(Types::EmitterTypes)
5
+ Database = Dry::Schema.Params do
6
+ required(:emitter).value(Types::String.enum("database"))
7
7
  end
8
8
 
9
9
  MISP = Dry::Schema.Params do
10
10
  required(:emitter).value(Types::String.enum("misp"))
11
- optional(:api_endpoint).value(:string)
12
11
  optional(:url).value(:string)
13
12
  optional(:api_key).value(:string)
14
13
  end
15
14
 
16
15
  TheHive = Dry::Schema.Params do
17
16
  required(:emitter).value(Types::String.enum("the_hive"))
18
- optional(:api_endpoint).value(:string)
19
17
  optional(:url).value(:string)
20
18
  optional(:api_key).value(:string)
21
19
  optional(:api_version).value(Types::String.enum("v4", "v5")).default("v4")
@@ -27,11 +25,11 @@ module Mihari
27
25
  optional(:channel).value(:string)
28
26
  end
29
27
 
30
- HTTP = Dry::Schema.Params do
31
- required(:emitter).value(Types::String.enum("http"))
28
+ Webhook = Dry::Schema.Params do
29
+ required(:emitter).value(Types::String.enum("webhook"))
32
30
  required(:url).value(:string)
33
- optional(:http_request_method).value(Types::HTTPRequestMethods).default("POST")
34
- optional(:http_request_headers).value(:hash).default({})
31
+ optional(:method).value(Types::HTTPRequestMethods).default("POST")
32
+ optional(:headers).value(:hash).default({})
35
33
  optional(:template).value(:string)
36
34
  end
37
35
  end
@@ -7,18 +7,17 @@ require "mihari/schemas/enricher"
7
7
  module Mihari
8
8
  module Schemas
9
9
  Rule = Dry::Schema.Params do
10
+ required(:id).value(:string)
10
11
  required(:title).value(:string)
11
12
  required(:description).value(:string)
12
13
 
13
14
  optional(:tags).value(array[:string]).default([])
14
- optional(:id).value(:string)
15
15
 
16
- optional(:status).value(:string)
17
-
18
- optional(:related).value(array[:string])
16
+ optional(:author).value(:string)
19
17
  optional(:references).value(array[:string])
18
+ optional(:related).value(array[:string])
19
+ optional(:status).value(:string)
20
20
 
21
- optional(:author).value(:string)
22
21
  optional(:created_on).value(:date)
23
22
  optional(:updated_on).value(:date)
24
23
 
@@ -26,15 +25,14 @@ module Mihari
26
25
  AnalyzerWithoutAPIKey | AnalyzerWithAPIKey | Censys | CIRCL | PassiveTotal | ZoomEye | Urlscan | Crtsh | Feed
27
26
  end
28
27
 
29
- optional(:emitters).value(:array).each { Emitter | MISP | TheHive | Slack | HTTP }
28
+ optional(:emitters).value(:array).each { Database | MISP | TheHive | Slack | Webhook }
30
29
 
31
30
  optional(:enrichers).value(:array).each(Enricher)
32
31
 
33
- optional(:allowed_data_types).value(array[Types::DataTypes]).default(ALLOWED_DATA_TYPES)
34
- optional(:disallowed_data_values).value(array[:string]).default([])
32
+ optional(:data_types).value(array[Types::DataTypes]).default(DEFAULT_DATA_TYPES)
33
+ optional(:falsepositives).value(array[:string]).default([])
35
34
 
36
- optional(:ignore_old_artifacts).value(:bool).default(false)
37
- optional(:ignore_threshold).value(:integer).default(0)
35
+ optional(:artifact_lifetime).value(:integer)
38
36
 
39
37
  before(:key_coercer) do |result|
40
38
  # it looks like that dry-schema v1.9.1 has an issue with setting an array of schemas as a default value
@@ -53,13 +51,13 @@ module Mihari
53
51
  end
54
52
 
55
53
  class RuleContract < Dry::Validation::Contract
56
- include Mihari::Mixins::DisallowedDataValue
54
+ include Mihari::Mixins::FalsePositive
57
55
 
58
56
  params(Rule)
59
57
 
60
- rule(:disallowed_data_values) do
58
+ rule(:falsepositives) do
61
59
  value.each do |v|
62
- key.failure("#{v} is not a valid format.") unless valid_disallowed_data_value?(v)
60
+ key.failure("#{v} is not a valid format.") unless valid_falsepositive?(v)
63
61
  end
64
62
  end
65
63
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Structs
5
+ class Config < Dry::Struct
6
+ attribute :name, Types::String
7
+ attribute :type, Types::String
8
+ attribute :is_configured, Types::Bool
9
+ attribute :values, Types.Array(Types::Hash).optional
10
+
11
+ #
12
+ # @param [Class<Mihari::Analyzers::Base>, Class<Mihari::Emitters::Base>] klass
13
+ #
14
+ # @return [Mihari::Structs::Config, nil] config
15
+ #
16
+ def self.from_class(klass)
17
+ return nil if klass == Mihari::Analyzers::Rule
18
+
19
+ name = klass.to_s.split("::").last.to_s
20
+
21
+ is_analyzer = klass.ancestors.include?(Mihari::Analyzers::Base)
22
+ is_emitter = klass.ancestors.include?(Mihari::Emitters::Base)
23
+ is_enricher = klass.ancestors.include?(Mihari::Enrichers::Base)
24
+
25
+ type = "Analyzer"
26
+ type = "Emitter" if is_emitter
27
+ type = "Enricher" if is_enricher
28
+
29
+ begin
30
+ instance = is_analyzer ? klass.new("dummy") : klass.new
31
+ is_configured = instance.configured?
32
+ values = instance.configuration_values
33
+
34
+ new(name: name, values: values, is_configured: is_configured, type: type)
35
+ rescue ArgumentError => _e
36
+ nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -7,7 +7,7 @@ module Mihari
7
7
  class SearchFilter < Dry::Struct
8
8
  attribute? :artifact_data, Types::String.optional
9
9
  attribute? :description, Types::String.optional
10
- attribute? :source, Types::String.optional
10
+ attribute? :rule_id, Types::String.optional
11
11
  attribute? :tag_name, Types::String.optional
12
12
  attribute? :title, Types::String.optional
13
13
  attribute? :from_at, Types::DateTime.optional
@@ -30,7 +30,7 @@ module Mihari
30
30
  artifact_data: artifact_data,
31
31
  description: description,
32
32
  from_at: from_at,
33
- source: source,
33
+ rule_id: rule_id,
34
34
  tag_name: tag_name,
35
35
  title: title,
36
36
  to_at: to_at,