mihari 3.10.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/docker/Dockerfile +1 -1
  4. data/lib/mihari/analyzers/base.rb +7 -7
  5. data/lib/mihari/analyzers/binaryedge.rb +8 -5
  6. data/lib/mihari/analyzers/censys.rb +6 -3
  7. data/lib/mihari/analyzers/circl.rb +0 -3
  8. data/lib/mihari/analyzers/crtsh.rb +7 -5
  9. data/lib/mihari/analyzers/dnpedia.rb +4 -4
  10. data/lib/mihari/analyzers/dnstwister.rb +1 -4
  11. data/lib/mihari/analyzers/feed.rb +36 -0
  12. data/lib/mihari/analyzers/greynoise.rb +1 -3
  13. data/lib/mihari/analyzers/onyphe.rb +6 -3
  14. data/lib/mihari/analyzers/otx.rb +0 -3
  15. data/lib/mihari/analyzers/passivetotal.rb +8 -9
  16. data/lib/mihari/analyzers/pulsedive.rb +7 -5
  17. data/lib/mihari/analyzers/rule.rb +11 -5
  18. data/lib/mihari/analyzers/securitytrails.rb +10 -7
  19. data/lib/mihari/analyzers/shodan.rb +15 -8
  20. data/lib/mihari/analyzers/spyse.rb +10 -11
  21. data/lib/mihari/analyzers/urlscan.rb +39 -16
  22. data/lib/mihari/analyzers/virustotal.rb +8 -9
  23. data/lib/mihari/analyzers/virustotal_intelligence.rb +9 -5
  24. data/lib/mihari/analyzers/zoomeye.rb +12 -5
  25. data/lib/mihari/cli/base.rb +0 -5
  26. data/lib/mihari/cli/init.rb +0 -2
  27. data/lib/mihari/cli/main.rb +4 -6
  28. data/lib/mihari/cli/mixins/utils.rb +2 -18
  29. data/lib/mihari/commands/init.rb +0 -18
  30. data/lib/mihari/commands/search.rb +20 -15
  31. data/lib/mihari/commands/validator.rb +7 -19
  32. data/lib/mihari/commands/web.rb +0 -3
  33. data/lib/mihari/database.rb +71 -19
  34. data/lib/mihari/emitters/misp.rb +0 -1
  35. data/lib/mihari/emitters/slack.rb +3 -4
  36. data/lib/mihari/emitters/stdout.rb +0 -2
  37. data/lib/mihari/emitters/the_hive.rb +0 -1
  38. data/lib/mihari/emitters/webhook.rb +1 -5
  39. data/lib/mihari/enrichers/ipinfo.rb +2 -2
  40. data/lib/mihari/errors.rb +6 -0
  41. data/lib/mihari/feed/parser.rb +34 -0
  42. data/lib/mihari/feed/reader.rb +127 -0
  43. data/lib/mihari/mixins/autonomous_system.rb +2 -0
  44. data/lib/mihari/mixins/database.rb +14 -0
  45. data/lib/mihari/mixins/disallowed_data_value.rb +2 -3
  46. data/lib/mihari/mixins/rule.rb +36 -31
  47. data/lib/mihari/models/alert.rb +7 -8
  48. data/lib/mihari/models/artifact.rb +1 -7
  49. data/lib/mihari/models/autonomous_system.rb +0 -2
  50. data/lib/mihari/models/dns.rb +2 -5
  51. data/lib/mihari/models/geolocation.rb +0 -1
  52. data/lib/mihari/models/reverse_dns.rb +0 -3
  53. data/lib/mihari/models/rule.rb +73 -0
  54. data/lib/mihari/models/tag.rb +0 -2
  55. data/lib/mihari/models/tagging.rb +0 -2
  56. data/lib/mihari/models/whois.rb +0 -2
  57. data/lib/mihari/notifiers/exception_notifier.rb +0 -2
  58. data/lib/mihari/schemas/analyzer.rb +0 -5
  59. data/lib/mihari/schemas/macros.rb +0 -2
  60. data/lib/mihari/schemas/rule.rb +21 -7
  61. data/lib/mihari/status.rb +2 -2
  62. data/lib/mihari/structs/alert.rb +2 -3
  63. data/lib/mihari/structs/censys.rb +4 -3
  64. data/lib/mihari/structs/greynoise.rb +4 -3
  65. data/lib/mihari/structs/ipinfo.rb +1 -2
  66. data/lib/mihari/structs/onyphe.rb +6 -5
  67. data/lib/mihari/structs/rule.rb +121 -0
  68. data/lib/mihari/structs/shodan.rb +8 -7
  69. data/lib/mihari/structs/urlscan.rb +50 -0
  70. data/lib/mihari/structs/virustotal_intelligence.rb +4 -3
  71. data/lib/mihari/type_checker.rb +2 -6
  72. data/lib/mihari/types.rb +8 -1
  73. data/lib/mihari/version.rb +1 -1
  74. data/lib/mihari/web/api.rb +6 -0
  75. data/lib/mihari/web/app.rb +5 -7
  76. data/lib/mihari/web/endpoints/alerts.rb +7 -3
  77. data/lib/mihari/web/endpoints/artifacts.rb +6 -3
  78. data/lib/mihari/web/endpoints/command.rb +2 -1
  79. data/lib/mihari/web/endpoints/configs.rb +2 -1
  80. data/lib/mihari/web/endpoints/ip_addresses.rb +2 -1
  81. data/lib/mihari/web/endpoints/rules.rb +140 -0
  82. data/lib/mihari/web/endpoints/sources.rb +2 -1
  83. data/lib/mihari/web/endpoints/tags.rb +4 -2
  84. data/lib/mihari/web/entities/artifact.rb +4 -2
  85. data/lib/mihari/web/entities/rule.rb +35 -0
  86. data/lib/mihari/web/entities/whois.rb +1 -1
  87. data/lib/mihari/web/middleware/connection_adapter.rb +19 -0
  88. data/lib/mihari/web/public/index.html +1 -1
  89. data/lib/mihari/web/public/redoc-static.html +196 -184
  90. data/lib/mihari/web/public/static/js/app.49ab738a.js +21 -0
  91. data/lib/mihari/web/public/static/js/app.49ab738a.js.map +1 -0
  92. data/lib/mihari/web/public/static/js/app.5dc97aae.js +21 -0
  93. data/lib/mihari/web/public/static/js/app.5dc97aae.js.map +1 -0
  94. data/lib/mihari/web/public/static/js/app.f2b8890f.js +21 -0
  95. data/lib/mihari/web/public/static/js/app.f2b8890f.js.map +1 -0
  96. data/lib/mihari/web/public/static/js/app.fbc19869.js +21 -0
  97. data/lib/mihari/web/public/static/js/app.fbc19869.js.map +1 -0
  98. data/lib/mihari.rb +42 -34
  99. data/mihari.gemspec +21 -23
  100. data/sig/lib/mihari/analyzers/binaryedge.rbs +2 -3
  101. data/sig/lib/mihari/analyzers/censys.rbs +2 -3
  102. data/sig/lib/mihari/analyzers/circl.rbs +1 -3
  103. data/sig/lib/mihari/analyzers/crtsh.rbs +1 -3
  104. data/sig/lib/mihari/analyzers/dnpedia.rbs +1 -4
  105. data/sig/lib/mihari/analyzers/dnstwister.rbs +1 -3
  106. data/sig/lib/mihari/analyzers/feed.rbs +20 -0
  107. data/sig/lib/mihari/analyzers/onyphe.rbs +2 -3
  108. data/sig/lib/mihari/analyzers/otx.rbs +1 -3
  109. data/sig/lib/mihari/analyzers/passivetotal.rbs +3 -5
  110. data/sig/lib/mihari/analyzers/pulsedive.rbs +2 -4
  111. data/sig/lib/mihari/analyzers/securitytrails.rbs +3 -5
  112. data/sig/lib/mihari/analyzers/shodan.rbs +2 -3
  113. data/sig/lib/mihari/analyzers/spyse.rbs +4 -6
  114. data/sig/lib/mihari/analyzers/urlscan.rbs +6 -5
  115. data/sig/lib/mihari/analyzers/virustotal.rbs +4 -6
  116. data/sig/lib/mihari/analyzers/virustotal_intelligence.rbs +2 -3
  117. data/sig/lib/mihari/analyzers/zoomeye.rbs +4 -4
  118. data/sig/lib/mihari/commands/init.rbs +0 -2
  119. data/sig/lib/mihari/commands/validator.rbs +0 -2
  120. data/sig/lib/mihari/emitters/slack.rbs +0 -1
  121. data/sig/lib/mihari/feed/parser.rbs +11 -0
  122. data/sig/lib/mihari/feed/reader.rbs +56 -0
  123. data/sig/lib/mihari/mixins/disallowed_data_value.rbs +0 -2
  124. data/sig/lib/mihari/mixins/rule.rbs +5 -12
  125. data/sig/lib/mihari/models/alert.rbs +1 -1
  126. data/sig/lib/mihari/models/artifact.rbs +2 -0
  127. data/sig/lib/mihari/models/rule.rbs +14 -0
  128. data/sig/lib/mihari/structs/alert.rbs +1 -1
  129. data/sig/lib/mihari/structs/greynoise.rbs +3 -3
  130. data/sig/lib/mihari/structs/rule.rbs +56 -0
  131. data/sig/lib/mihari/structs/shodan.rbs +2 -2
  132. data/sig/lib/mihari/structs/urlscan.rbs +28 -0
  133. data/sig/lib/mihari/types.rbs +4 -0
  134. data/sig/lib/mihari.rbs +0 -2
  135. metadata +102 -147
  136. data/lib/mihari/cli/analyzer.rb +0 -52
  137. data/lib/mihari/commands/binaryedge.rb +0 -21
  138. data/lib/mihari/commands/censys.rb +0 -22
  139. data/lib/mihari/commands/circl.rb +0 -21
  140. data/lib/mihari/commands/crtsh.rb +0 -22
  141. data/lib/mihari/commands/dnpedia.rb +0 -21
  142. data/lib/mihari/commands/dnstwister.rb +0 -21
  143. data/lib/mihari/commands/greynoise.rb +0 -21
  144. data/lib/mihari/commands/json.rb +0 -42
  145. data/lib/mihari/commands/onyphe.rb +0 -21
  146. data/lib/mihari/commands/otx.rb +0 -21
  147. data/lib/mihari/commands/passivetotal.rb +0 -22
  148. data/lib/mihari/commands/pulsedive.rb +0 -21
  149. data/lib/mihari/commands/securitytrails.rb +0 -22
  150. data/lib/mihari/commands/shodan.rb +0 -21
  151. data/lib/mihari/commands/spyse.rb +0 -22
  152. data/lib/mihari/commands/urlscan.rb +0 -23
  153. data/lib/mihari/commands/virustotal.rb +0 -22
  154. data/lib/mihari/commands/virustotal_intelligence.rb +0 -22
  155. data/lib/mihari/commands/zoomeye.rb +0 -22
  156. data/lib/mihari/mixins/configuration.rb +0 -100
  157. data/lib/mihari/mixins/hash.rb +0 -20
  158. data/lib/mihari/schemas/configuration.rb +0 -44
  159. data/lib/mihari/web/public/grape.rb +0 -73
  160. data/sig/lib/mihari/cli/analyzer.rbs +0 -39
  161. data/sig/lib/mihari/commands/binaryedge.rbs +0 -7
  162. data/sig/lib/mihari/commands/censys.rbs +0 -7
  163. data/sig/lib/mihari/commands/circl.rbs +0 -7
  164. data/sig/lib/mihari/commands/crtsh.rbs +0 -7
  165. data/sig/lib/mihari/commands/dnpedia.rbs +0 -7
  166. data/sig/lib/mihari/commands/dnstwister.rbs +0 -7
  167. data/sig/lib/mihari/commands/onyphe.rbs +0 -7
  168. data/sig/lib/mihari/commands/otx.rbs +0 -7
  169. data/sig/lib/mihari/commands/passivetotal.rbs +0 -7
  170. data/sig/lib/mihari/commands/pulsedive.rbs +0 -7
  171. data/sig/lib/mihari/commands/securitytrails.rbs +0 -7
  172. data/sig/lib/mihari/commands/shodan.rbs +0 -7
  173. data/sig/lib/mihari/commands/spyse.rbs +0 -7
  174. data/sig/lib/mihari/commands/urlscan.rbs +0 -7
  175. data/sig/lib/mihari/commands/virustotal.rbs +0 -7
  176. data/sig/lib/mihari/commands/zoomeye.rbs +0 -7
data/lib/mihari/status.rb CHANGED
@@ -18,11 +18,11 @@ module Mihari
18
18
  # @return [Array<Hash>]
19
19
  #
20
20
  def statuses
21
- (Mihari.analyzers + Mihari.emitters + Mihari.enrichers).map do |klass|
21
+ (Mihari.analyzers + Mihari.emitters + Mihari.enrichers).to_h do |klass|
22
22
  name = klass.to_s.split("::").last.to_s
23
23
 
24
24
  [name, build_status(klass)]
25
- end.to_h.compact
25
+ end.compact
26
26
  end
27
27
 
28
28
  #
@@ -1,5 +1,4 @@
1
- require "json"
2
- require "dry/struct"
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Mihari
5
4
  module Structs
@@ -16,7 +15,7 @@ module Mihari
16
15
  attribute? :dns_record, Types::String.optional
17
16
  attribute? :reverse_dns_name, Types::String.optional
18
17
 
19
- def has_valid_artifact_filters
18
+ def valid_artifact_filters?
20
19
  !(artifact_data || asn || dns_record || reverse_dns_name).nil?
21
20
  end
22
21
  end
@@ -1,5 +1,4 @@
1
- require "json"
2
- require "dry/struct"
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Mihari
5
4
  module Structs
@@ -32,13 +31,15 @@ module Mihari
32
31
  attribute :ip, Types::String
33
32
  attribute :location, Location
34
33
  attribute :autonomous_system, AutonomousSystem
34
+ attribute :metadata, Types::Hash
35
35
 
36
36
  def self.from_dynamic!(d)
37
37
  d = Types::Hash[d]
38
38
  new(
39
39
  ip: d.fetch("ip"),
40
40
  location: Location.from_dynamic!(d.fetch("location")),
41
- autonomous_system: AutonomousSystem.from_dynamic!(d.fetch("autonomous_system"))
41
+ autonomous_system: AutonomousSystem.from_dynamic!(d.fetch("autonomous_system")),
42
+ metadata: d
42
43
  )
43
44
  end
44
45
  end
@@ -1,5 +1,4 @@
1
- require "json"
2
- require "dry/struct"
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Mihari
5
4
  module Structs
@@ -22,12 +21,14 @@ module Mihari
22
21
  class Datum < Dry::Struct
23
22
  attribute :ip, Types::String
24
23
  attribute :metadata, Metadata
24
+ attribute :metadata_, Types::Hash
25
25
 
26
26
  def self.from_dynamic!(d)
27
27
  d = Types::Hash[d]
28
28
  new(
29
29
  ip: d.fetch("ip"),
30
- metadata: Metadata.from_dynamic!(d.fetch("metadata"))
30
+ metadata: Metadata.from_dynamic!(d.fetch("metadata")),
31
+ metadata_: d
31
32
  )
32
33
  end
33
34
  end
@@ -1,5 +1,4 @@
1
- require "json"
2
- require "dry/struct"
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Mihari
5
4
  module Structs
@@ -1,5 +1,4 @@
1
- require "json"
2
- require "dry/struct"
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Mihari
5
4
  module Structs
@@ -8,6 +7,7 @@ module Mihari
8
7
  attribute :asn, Types::String
9
8
  attribute :country_code, Types::String.optional
10
9
  attribute :ip, Types::String
10
+ attribute :metadata, Types::Hash
11
11
 
12
12
  def self.from_dynamic!(d)
13
13
  d = Types::Hash[d]
@@ -15,7 +15,8 @@ module Mihari
15
15
  asn: d.fetch("asn"),
16
16
  ip: d.fetch("ip"),
17
17
  # Onyphe's country = 2-letter country code
18
- country_code: d["country"]
18
+ country_code: d["country"],
19
+ metadata: d
19
20
  )
20
21
  end
21
22
  end
@@ -24,7 +25,7 @@ module Mihari
24
25
  attribute :count, Types::Int
25
26
  attribute :error, Types::Int
26
27
  attribute :max_page, Types::Int
27
- attribute :page, Types::String
28
+ attribute :page, Types::Int
28
29
  attribute :results, Types.Array(Result)
29
30
  attribute :status, Types::String
30
31
  attribute :total, Types::Int
@@ -35,7 +36,7 @@ module Mihari
35
36
  count: d.fetch("count"),
36
37
  error: d.fetch("error"),
37
38
  max_page: d.fetch("max_page"),
38
- page: d.fetch("page"),
39
+ page: d.fetch("page").to_i,
39
40
  results: d.fetch("results").map { |x| Result.from_dynamic!(x) },
40
41
  status: d.fetch("status"),
41
42
  total: d.fetch("total")
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Structs
5
+ module Rule
6
+ class SearchFilter < Dry::Struct
7
+ attribute? :description, Types::String.optional
8
+ attribute? :tag_name, Types::String.optional
9
+ attribute? :title, Types::String.optional
10
+ attribute? :from_at, Types::DateTime.optional
11
+ attribute? :to_at, Types::DateTime.optional
12
+ end
13
+
14
+ class SearchFilterWithPagination < SearchFilter
15
+ attribute? :page, Types::Int.default(1)
16
+ attribute? :limit, Types::Int.default(10)
17
+
18
+ def without_pagination
19
+ SearchFilter.new(
20
+ description: description,
21
+ from_at: from_at,
22
+ tag_name: tag_name,
23
+ title: title,
24
+ to_at: to_at
25
+ )
26
+ end
27
+ end
28
+
29
+ class Rule
30
+ attr_reader :data, :errors
31
+
32
+ def initialize(data)
33
+ @data = data.deep_symbolize_keys
34
+ @errors = nil
35
+ @no_method_error = nil
36
+
37
+ validate
38
+ end
39
+
40
+ #
41
+ # @return [Boolean]
42
+ #
43
+ def errors?
44
+ return false if @errors.nil?
45
+
46
+ !@errors.empty?
47
+ end
48
+
49
+ #
50
+ # @return [Array<String>]
51
+ #
52
+ def error_messages
53
+ return [] if @errors.nil?
54
+
55
+ @errors.messages.map do |message|
56
+ path = message.path.map(&:to_s).join
57
+ "#{path} #{message.text}"
58
+ end
59
+ end
60
+
61
+ def validate
62
+ begin
63
+ contract = Schemas::RuleContract.new
64
+ result = contract.call(data)
65
+ rescue NoMethodError => e
66
+ @no_method_error = e
67
+ return
68
+ end
69
+
70
+ @data = result.to_h
71
+ @errors = result.errors
72
+ end
73
+
74
+ def validate!
75
+ raise RuleValidationError, "Data should be a hash" unless data.is_a?(Hash)
76
+
77
+ raise RuleValidationError, error_messages.join("\n") if errors?
78
+
79
+ raise RuleValidationError, "Something wrong with queries" unless @no_method_error.nil?
80
+ end
81
+
82
+ def [](key)
83
+ data[key.to_sym]
84
+ end
85
+
86
+ #
87
+ # @return [String]
88
+ #
89
+ def id
90
+ @id ||= data[:id] || UUIDTools::UUID.md5_create(UUIDTools::UUID_URL_NAMESPACE, data.to_yaml).to_s
91
+ end
92
+
93
+ #
94
+ # @return [String]
95
+ #
96
+ def title
97
+ @title ||= data[:title]
98
+ end
99
+
100
+ #
101
+ # @return [String]
102
+ #
103
+ def description
104
+ @description ||= data[:description]
105
+ end
106
+
107
+ #
108
+ # @return [Mihari::Rule]
109
+ #
110
+ def to_model
111
+ Mihari::Rule.new(
112
+ id: id,
113
+ title: title,
114
+ description: description,
115
+ data: data
116
+ )
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
@@ -1,18 +1,17 @@
1
- require "json"
2
- require "dry/struct"
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Mihari
5
4
  module Structs
6
5
  module Shodan
7
6
  class Location < Dry::Struct
8
- attribute :country_code, Types::String
9
- attribute :country_name, Types::String
7
+ attribute :country_code, Types::String.optional
8
+ attribute :country_name, Types::String.optional
10
9
 
11
10
  def self.from_dynamic!(d)
12
11
  d = Types::Hash[d]
13
12
  new(
14
- country_code: d.fetch("country_code"),
15
- country_name: d.fetch("country_name")
13
+ country_code: d["country_code"],
14
+ country_name: d["country_name"]
16
15
  )
17
16
  end
18
17
  end
@@ -23,6 +22,7 @@ module Mihari
23
22
  attribute :location, Location
24
23
  attribute :domains, Types.Array(Types::String)
25
24
  attribute :ip_str, Types::String
25
+ attribute :metadata, Types::Hash
26
26
 
27
27
  def self.from_dynamic!(d)
28
28
  d = Types::Hash[d]
@@ -31,7 +31,8 @@ module Mihari
31
31
  hostnames: d.fetch("hostnames"),
32
32
  location: Location.from_dynamic!(d.fetch("location")),
33
33
  domains: d.fetch("domains"),
34
- ip_str: d.fetch("ip_str")
34
+ ip_str: d.fetch("ip_str"),
35
+ metadata: d
35
36
  )
36
37
  end
37
38
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Structs
5
+ module Urlscan
6
+ class Page < Dry::Struct
7
+ attribute :domain, Types::String.optional
8
+ attribute :ip, Types::String.optional
9
+ attribute :url, Types::String
10
+
11
+ def self.from_dynamic!(d)
12
+ d = Types::Hash[d]
13
+ new(
14
+ domain: d["domain"],
15
+ ip: d["ip"],
16
+ url: d.fetch("url")
17
+ )
18
+ end
19
+ end
20
+
21
+ class Result < Dry::Struct
22
+ attribute :page, Page
23
+ attribute :id, Types::String
24
+ attribute :sort, Types.Array(Types::String | Types::Integer)
25
+
26
+ def self.from_dynamic!(d)
27
+ d = Types::Hash[d]
28
+ new(
29
+ page: Page.from_dynamic!(d.fetch("page")),
30
+ id: d.fetch("_id"),
31
+ sort: d.fetch("sort")
32
+ )
33
+ end
34
+ end
35
+
36
+ class Response < Dry::Struct
37
+ attribute :results, Types.Array(Result)
38
+ attribute :has_more, Types::Bool
39
+
40
+ def self.from_dynamic!(d)
41
+ d = Types::Hash[d]
42
+ new(
43
+ results: d.fetch("results").map { |x| Result.from_dynamic!(x) },
44
+ has_more: d.fetch("has_more")
45
+ )
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,4 @@
1
- require "json"
2
- require "dry/struct"
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Mihari
5
4
  module Structs
@@ -19,6 +18,7 @@ module Mihari
19
18
  attribute :type, Types::String
20
19
  attribute :id, Types::String
21
20
  attribute :context_attributes, ContextAttributes.optional
21
+ attribute :metadata, Types::Hash
22
22
 
23
23
  def value
24
24
  case type
@@ -42,7 +42,8 @@ module Mihari
42
42
  new(
43
43
  type: d.fetch("type"),
44
44
  id: d.fetch("id"),
45
- context_attributes: context_attributes
45
+ context_attributes: context_attributes,
46
+ metadata: d
46
47
  )
47
48
  end
48
49
  end
@@ -1,11 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "addressable/uri"
4
- require "dry-initializer"
5
- require "email_address"
6
- require "ipaddr"
7
- require "public_suffix"
8
-
9
3
  module Mihari
10
4
  class TypeChecker
11
5
  extend Dry::Initializer
@@ -16,6 +10,8 @@ module Mihari
16
10
  super
17
11
 
18
12
  raise ArgumentError if data.is_a?(Hash)
13
+
14
+ @data = data.to_s
19
15
  end
20
16
 
21
17
  # @return [Boolean]
data/lib/mihari/types.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "dry/types"
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
4
  module Types
@@ -8,17 +8,21 @@ module Mihari
8
8
  Nil = Strict::Nil
9
9
  Hash = Strict::Hash
10
10
  String = Strict::String
11
+ Bool = Strict::Bool
11
12
  Double = Strict::Float | Strict::Integer
12
13
  DateTime = Strict::DateTime
13
14
 
14
15
  DataTypes = Types::String.enum(*ALLOWED_DATA_TYPES)
15
16
 
17
+ UrlscanDataTypes = Types::String.enum("ip", "domain", "url")
18
+
16
19
  AnalyzerTypes = Types::String.enum(
17
20
  "binaryedge",
18
21
  "censys",
19
22
  "circl",
20
23
  "dnpedia",
21
24
  "dnstwister",
25
+ "feed",
22
26
  "greynoise",
23
27
  "onyphe",
24
28
  "otx",
@@ -33,5 +37,8 @@ module Mihari
33
37
  "vt_intel",
34
38
  "vt"
35
39
  )
40
+
41
+ FeedHttpRequestMethods = Types::String.enum("GET", "POST")
42
+ FeedHttpRequestPayloadTypes = Types::String.enum("application/json", "application/x-www-form-urlencoded")
36
43
  end
37
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "3.10.0"
4
+ VERSION = "4.0.0"
5
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Entities
2
4
  require "mihari/web/entities/message"
3
5
 
@@ -16,12 +18,15 @@ require "mihari/web/entities/artifact"
16
18
 
17
19
  require "mihari/web/entities/alert"
18
20
 
21
+ require "mihari/web/entities/rule"
22
+
19
23
  # Endpoints
20
24
  require "mihari/web/endpoints/alerts"
21
25
  require "mihari/web/endpoints/artifacts"
22
26
  require "mihari/web/endpoints/command"
23
27
  require "mihari/web/endpoints/configs"
24
28
  require "mihari/web/endpoints/ip_addresses"
29
+ require "mihari/web/endpoints/rules"
25
30
  require "mihari/web/endpoints/sources"
26
31
  require "mihari/web/endpoints/tags"
27
32
 
@@ -35,6 +40,7 @@ module Mihari
35
40
  mount Endpoints::Command
36
41
  mount Endpoints::Configs
37
42
  mount Endpoints::IPAddresses
43
+ mount Endpoints::Rules
38
44
  mount Endpoints::Sources
39
45
  mount Endpoints::Tags
40
46
 
@@ -11,6 +11,8 @@ require "grape-entity"
11
11
  require "grape-swagger"
12
12
  require "grape-swagger-entity"
13
13
 
14
+ require "mihari/web/middleware/connection_adapter"
15
+
14
16
  require "mihari/web/api"
15
17
 
16
18
  module Mihari
@@ -34,6 +36,8 @@ module Mihari
34
36
  end
35
37
  end
36
38
 
39
+ use Middleware::ConnectionAdapter
40
+
37
41
  run App.new
38
42
  end.to_app
39
43
  end
@@ -41,14 +45,8 @@ module Mihari
41
45
  def run!(port: 9292, host: "localhost", threads: "0:16", verbose: false)
42
46
  url = "http://#{host}:#{port}"
43
47
 
44
- Rack::Handler::Puma.run(instance, Port: port, Host: host, Threads: threads, Verbose: verbose) do |server|
48
+ Rack::Handler::Puma.run(instance, Port: port, Host: host, Threads: threads, Verbose: verbose) do |_launcher|
45
49
  Launchy.open(url) if ENV["RACK_ENV"] != "development"
46
-
47
- [:INT, :TERM].each do |sig|
48
- trap(sig) do
49
- server.shutdown
50
- end
51
- end
52
50
  end
53
51
  end
54
52
  end
@@ -7,14 +7,17 @@ module Mihari
7
7
  desc "Search alerts", {
8
8
  is_array: true,
9
9
  success: Entities::Alert,
10
- failure: [{ code: 404, message: "Not found", model: Entities::Message }]
10
+ failure: [{ code: 404, message: "Not found", model: Entities::Message }],
11
+ summary: "Search alerts"
11
12
  }
12
13
  params do
13
14
  optional :page, type: Integer
15
+
14
16
  optional :artifact, type: String
15
17
  optional :description, type: String
16
18
  optional :source, type: String
17
19
  optional :tag, type: String
20
+ optional :title, type: String
18
21
 
19
22
  optional :fromAt, type: DateTime
20
23
  optional :toAt, type: DateTime
@@ -38,7 +41,7 @@ module Mihari
38
41
  filter["tag_name"] = filter["tag"]
39
42
 
40
43
  # symbolize hash keys
41
- filter = filter.to_h.transform_keys(&:to_sym)
44
+ filter = filter.to_h.symbolize_keys
42
45
 
43
46
  search_filter_with_pagenation = Structs::Alert::SearchFilterWithPagination.new(**filter)
44
47
  alerts = Mihari::Alert.search(search_filter_with_pagenation)
@@ -49,7 +52,8 @@ module Mihari
49
52
 
50
53
  desc "Delete an alert", {
51
54
  success: Entities::Message,
52
- failure: [{ code: 404, message: "Not found", model: Entities::Message }]
55
+ failure: [{ code: 404, message: "Not found", model: Entities::Message }],
56
+ summary: "Delete an alert"
53
57
  }
54
58
  params do
55
59
  requires :id, type: Integer
@@ -6,7 +6,8 @@ module Mihari
6
6
  namespace :artifacts do
7
7
  desc "Get an artifact", {
8
8
  success: Entities::Artifact,
9
- failure: [{ code: 404, message: "Not found", model: Entities::Message }]
9
+ failure: [{ code: 404, message: "Not found", model: Entities::Message }],
10
+ summary: "Get an artifact"
10
11
  }
11
12
  params do
12
13
  requires :id, type: Integer
@@ -38,7 +39,8 @@ module Mihari
38
39
 
39
40
  desc "Enrich an artifact", {
40
41
  success: Entities::Message,
41
- failure: [{ code: 404, message: "Not found", model: Entities::Message }]
42
+ failure: [{ code: 404, message: "Not found", model: Entities::Message }],
43
+ summary: "Enrich an artifact"
42
44
  }
43
45
  params do
44
46
  requires :id, type: Integer
@@ -67,7 +69,8 @@ module Mihari
67
69
 
68
70
  desc "Delete an artifact", {
69
71
  success: Entities::Message,
70
- failure: [{ code: 404, message: "Not found", model: Entities::Message }]
72
+ failure: [{ code: 404, message: "Not found", model: Entities::Message }],
73
+ summary: "Delete an artifact"
71
74
  }
72
75
  params do
73
76
  requires :id, type: Integer
@@ -8,7 +8,8 @@ module Mihari
8
8
  namespace :command do
9
9
  desc "Run a command", {
10
10
  success: Entities::CommandResult,
11
- failure: [{ code: 400, message: "Bad request", model: Entities::Message }]
11
+ failure: [{ code: 400, message: "Bad request", model: Entities::Message }],
12
+ summary: "Run a command"
12
13
  }
13
14
  params do
14
15
  requires :command, type: String, documentation: { param_type: "body" }
@@ -6,7 +6,8 @@ module Mihari
6
6
  namespace :configs do
7
7
  desc "Get configs", {
8
8
  is_array: true,
9
- success: Entities::Config
9
+ success: Entities::Config,
10
+ summary: "Get configs"
10
11
  }
11
12
  get "/" do
12
13
  statuses = Status.check
@@ -6,7 +6,8 @@ module Mihari
6
6
  namespace :ip_addresses do
7
7
  desc "Get an IP address", {
8
8
  success: Entities::IPAddress,
9
- failure: [{ code: 404, message: "Not found", model: Entities::Message }]
9
+ failure: [{ code: 404, message: "Not found", model: Entities::Message }],
10
+ summary: "Get an IP address"
10
11
  }
11
12
  params do
12
13
  requires :ip, type: String, regexp: /\A[0-9.]+\z/