mihari 4.1.1 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +26 -4
  3. data/README.md +1 -1
  4. data/lib/mihari/analyzers/base.rb +18 -10
  5. data/lib/mihari/analyzers/rule.rb +50 -7
  6. data/lib/mihari/cli/base.rb +0 -4
  7. data/lib/mihari/commands/init.rb +1 -1
  8. data/lib/mihari/commands/search.rb +11 -58
  9. data/lib/mihari/commands/validator.rb +1 -2
  10. data/lib/mihari/constants.rb +2 -0
  11. data/lib/mihari/emitters/base.rb +8 -2
  12. data/lib/mihari/emitters/http.rb +127 -0
  13. data/lib/mihari/emitters/slack.rb +40 -4
  14. data/lib/mihari/emitters/webhook.rb +7 -16
  15. data/lib/mihari/enrichers/base.rb +5 -2
  16. data/lib/mihari/enrichers/ipinfo.rb +4 -3
  17. data/lib/mihari/{web/entities → entities}/alert.rb +0 -0
  18. data/lib/mihari/{web/entities → entities}/artifact.rb +0 -0
  19. data/lib/mihari/{web/entities → entities}/autonomous_system.rb +0 -0
  20. data/lib/mihari/{web/entities → entities}/command.rb +0 -0
  21. data/lib/mihari/{web/entities → entities}/config.rb +0 -0
  22. data/lib/mihari/{web/entities → entities}/dns.rb +0 -0
  23. data/lib/mihari/{web/entities → entities}/geolocation.rb +0 -0
  24. data/lib/mihari/{web/entities → entities}/ip_address.rb +0 -0
  25. data/lib/mihari/{web/entities → entities}/message.rb +0 -0
  26. data/lib/mihari/{web/entities → entities}/reverse_dns.rb +0 -0
  27. data/lib/mihari/{web/entities → entities}/rule.rb +5 -0
  28. data/lib/mihari/{web/entities → entities}/source.rb +0 -0
  29. data/lib/mihari/{web/entities → entities}/tag.rb +0 -0
  30. data/lib/mihari/{web/entities → entities}/whois.rb +0 -0
  31. data/lib/mihari/errors.rb +2 -0
  32. data/lib/mihari/feed/reader.rb +16 -58
  33. data/lib/mihari/http.rb +99 -0
  34. data/lib/mihari/mixins/error_notification.rb +20 -0
  35. data/lib/mihari/mixins/retriable.rb +12 -2
  36. data/lib/mihari/mixins/rule.rb +1 -2
  37. data/lib/mihari/schemas/rule.rb +30 -4
  38. data/lib/mihari/structs/ipinfo.rb +2 -3
  39. data/lib/mihari/structs/rule.rb +31 -0
  40. data/lib/mihari/structs/shodan.rb +9 -1
  41. data/lib/mihari/types.rb +11 -3
  42. data/lib/mihari/version.rb +1 -1
  43. data/lib/mihari/web/api.rb +0 -20
  44. data/lib/mihari/web/app.rb +2 -2
  45. data/lib/mihari/web/endpoints/rules.rb +3 -1
  46. data/lib/mihari/web/middleware/error_notification_adapter.rb +19 -0
  47. data/lib/mihari/web/public/index.html +1 -1
  48. data/lib/mihari/web/public/redoc-static.html +1888 -166
  49. data/lib/mihari/web/public/static/css/app.0de4b715.css +1 -0
  50. data/lib/mihari/web/public/static/css/app.43138058.css +1 -0
  51. data/lib/mihari/web/public/static/css/chunk-vendors.3ed9b08e.css +7 -0
  52. data/lib/mihari/web/public/static/css/chunk-vendors.c57bb3fd.css +7 -0
  53. data/lib/mihari/web/public/static/fonts/fa-brands-400.1fd0b4d7.ttf +0 -0
  54. data/lib/mihari/web/public/static/fonts/fa-brands-400.5d5236fb.woff2 +0 -0
  55. data/lib/mihari/web/public/static/fonts/fa-brands-400.edf40f86.woff2 +0 -0
  56. data/lib/mihari/web/public/static/fonts/fa-brands-400.f7223235.ttf +0 -0
  57. data/lib/mihari/web/public/static/fonts/fa-regular-400.3665ebc7.woff2 +0 -0
  58. data/lib/mihari/web/public/static/fonts/fa-regular-400.64b3730e.woff2 +0 -0
  59. data/lib/mihari/web/public/static/fonts/fa-regular-400.95a8a8af.ttf +0 -0
  60. data/lib/mihari/web/public/static/fonts/fa-regular-400.a7fde52b.ttf +0 -0
  61. data/lib/mihari/web/public/static/fonts/fa-solid-900.0d2abd43.woff2 +0 -0
  62. data/lib/mihari/web/public/static/fonts/fa-solid-900.5b03221c.ttf +0 -0
  63. data/lib/mihari/web/public/static/fonts/fa-solid-900.6115ad71.woff2 +0 -0
  64. data/lib/mihari/web/public/static/fonts/fa-solid-900.f0203cfc.ttf +0 -0
  65. data/lib/mihari/web/public/static/fonts/fa-v4compatibility.42932bea.ttf +0 -0
  66. data/lib/mihari/web/public/static/fonts/fa-v4compatibility.e1023515.ttf +0 -0
  67. data/lib/mihari/web/public/static/js/app-legacy.46b666f0.js +2 -0
  68. data/lib/mihari/web/public/static/js/app-legacy.46b666f0.js.map +1 -0
  69. data/lib/mihari/web/public/static/js/app-legacy.e451304b.js +2 -0
  70. data/lib/mihari/web/public/static/js/app-legacy.e451304b.js.map +1 -0
  71. data/lib/mihari/web/public/static/js/app.4818aedd.js +2 -0
  72. data/lib/mihari/web/public/static/js/app.4818aedd.js.map +1 -0
  73. data/lib/mihari/web/public/static/js/app.e74e91d7.js +2 -0
  74. data/lib/mihari/web/public/static/js/app.e74e91d7.js.map +1 -0
  75. data/lib/mihari/web/public/static/js/chunk-vendors-legacy.41357cdf.js +25 -0
  76. data/lib/mihari/web/public/static/js/chunk-vendors-legacy.41357cdf.js.map +1 -0
  77. data/lib/mihari/web/public/static/js/chunk-vendors-legacy.c99e452e.js +17 -0
  78. data/lib/mihari/web/public/static/js/chunk-vendors-legacy.c99e452e.js.map +1 -0
  79. data/lib/mihari/web/public/static/js/chunk-vendors.15e84e22.js +23 -0
  80. data/lib/mihari/web/public/static/js/chunk-vendors.15e84e22.js.map +1 -0
  81. data/lib/mihari/web/public/static/js/chunk-vendors.c5525f1e.js +31 -0
  82. data/lib/mihari/web/public/static/js/chunk-vendors.c5525f1e.js.map +1 -0
  83. data/lib/mihari.rb +71 -21
  84. data/mihari.gemspec +16 -11
  85. data/sig/lib/mihari/constants.rbs +2 -0
  86. data/sig/lib/mihari/emitters/http.rbs +35 -0
  87. data/sig/lib/mihari/emitters/slack.rbs +29 -1
  88. data/sig/lib/mihari/feed/reader.rbs +2 -2
  89. data/sig/lib/mihari/http.rbs +64 -0
  90. data/sig/lib/mihari/mixins/error_notification.rbs +12 -0
  91. data/sig/lib/mihari/structs/rule.rbs +4 -0
  92. data/sig/lib/mihari/types.rbs +2 -0
  93. data/sig/lib/mihari.rbs +4 -8
  94. metadata +137 -62
  95. data/lib/mihari/cli/mixins/utils.rb +0 -72
  96. data/lib/mihari/emitters/stdout.rb +0 -22
  97. data/lib/mihari/notifiers/base.rb +0 -24
  98. data/lib/mihari/notifiers/exception_notifier.rb +0 -126
  99. data/lib/mihari/notifiers/slack.rb +0 -63
  100. data/sig/lib/mihari/cli/mixins/utils.rbs +0 -50
  101. data/sig/lib/mihari/notifiers/base.rbs +0 -18
  102. data/sig/lib/mihari/notifiers/exception_notifier.rbs +0 -75
  103. data/sig/lib/mihari/notifiers/slack.rbs +0 -50
File without changes
File without changes
@@ -8,6 +8,10 @@ module Mihari
8
8
  expose :interval, documentation: { type: Integer, required: false }
9
9
  end
10
10
 
11
+ class Emitter < Grape::Entity
12
+ expose :emitter, documentation: { type: String, required: true }
13
+ end
14
+
11
15
  class Rule < Grape::Entity
12
16
  expose :id, documentation: { type: String, required: true }
13
17
 
@@ -16,6 +20,7 @@ module Mihari
16
20
  expose :title, documentation: { type: String, required: true }
17
21
  expose :description, documentation: { type: String, required: true }
18
22
  expose :queries, using: Entities::Query, documentation: { type: Entities::Query, is_array: true, required: true }
23
+ expose :emitters, using: Entities::Emitter, documentation: { type: Entities::Emitter, is_array: true, required: false }
19
24
  expose :tags, documentation: { type: String, is_array: true }
20
25
  expose :allowed_data_types, documentation: { type: String, is_array: true }, as: :allowedDtaTypes
21
26
  expose :disallowed_data_values, documentation: { type: String, is_array: true }, as: :disallowedDataValues
File without changes
File without changes
File without changes
data/lib/mihari/errors.rb CHANGED
@@ -14,4 +14,6 @@ module Mihari
14
14
  class FeedParseError < Error; end
15
15
 
16
16
  class RuleValidationError < Error; end
17
+
18
+ class ConfigurationError < Error; end
17
19
  end
@@ -1,46 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "csv"
4
+ require "insensitive_hash"
4
5
 
5
6
  module Mihari
6
7
  module Feed
7
8
  class Reader
8
- attr_reader :uri, :http_request_headers, :http_request_method, :http_request_payload_type, :http_request_payload
9
+ attr_reader :uri, :http_request_headers, :http_request_method, :http_request_payload
9
10
 
10
11
  def initialize(uri, http_request_headers: {}, http_request_method: "GET", http_request_payload_type: nil, http_request_payload: {})
11
12
  @uri = Addressable::URI.parse(uri)
12
- @http_request_headers = http_request_headers
13
+ @http_request_headers = http_request_headers.insensitive
13
14
  @http_request_method = http_request_method
14
- @http_request_payload_type = http_request_payload_type
15
15
  @http_request_payload = http_request_payload
16
+
17
+ http_request_headers["content-type"] = http_request_payload_type if http_request_payload_type
16
18
  end
17
19
 
18
20
  def read
19
21
  return read_file(uri.path) if uri.scheme == "file"
20
22
 
21
- return get if http_request_method == "GET"
22
-
23
- post
24
- end
25
-
26
- def get
27
- uri.query = Addressable::URI.form_encode(http_request_payload)
28
- get = Net::HTTP::Get.new(uri)
23
+ res = nil
24
+ client = HTTP.new(uri, headers: http_request_headers, payload: http_request_payload)
29
25
 
30
- request(get)
31
- end
26
+ res = client.get if http_request_method == "GET"
27
+ res = client.post if http_request_method == "POST"
32
28
 
33
- def post
34
- post = Net::HTTP::Post.new(uri)
29
+ return [] if res.nil?
35
30
 
36
- case http_request_payload_type
37
- when "application/json"
38
- post.body = JSON.generate(http_request_payload)
39
- when "application/x-www-form-urlencoded"
40
- post.set_form_data(http_request_payload)
31
+ body = res.body
32
+ content_type = res["Content-Type"].to_s
33
+ if content_type.include?("application/json")
34
+ convert_as_json(body)
35
+ else
36
+ convert_as_csv(body)
41
37
  end
42
-
43
- request(post)
44
38
  end
45
39
 
46
40
  #
@@ -70,42 +64,6 @@ module Mihari
70
64
  CSV.new(text_without_comments).to_a.reject(&:empty?)
71
65
  end
72
66
 
73
- def https_options
74
- return { use_ssl: true } if uri.scheme == "https"
75
-
76
- {}
77
- end
78
-
79
- #
80
- # Make a HTTP request
81
- #
82
- # @param [Net::HTTPRequest] req
83
- #
84
- # @return [Array<Hash>]
85
- #
86
- def request(req)
87
- Net::HTTP.start(uri.host, uri.port, https_options) do |http|
88
- # set headers
89
- http_request_headers.each do |k, v|
90
- req[k] = v
91
- end
92
-
93
- response = http.request(req)
94
-
95
- code = response.code.to_i
96
- raise HttpError, "Unsupported response code returned: #{code}" if code != 200
97
-
98
- body = response.body
99
-
100
- content_type = response["Content-Type"].to_s
101
- if content_type.include?("application/json")
102
- convert_as_json(body)
103
- else
104
- convert_as_csv(body)
105
- end
106
- end
107
- end
108
-
109
67
  #
110
68
  # Read & convert a file
111
69
  #
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "insensitive_hash"
4
+
5
+ module Mihari
6
+ class HTTP
7
+ attr_reader :uri, :headers, :payload
8
+
9
+ def initialize(uri, headers: {}, payload: {})
10
+ @uri = uri.is_a?(Addressable::URI) ? uri : Addressable::URI.parse(uri)
11
+ @headers = headers.insensitive
12
+ @payload = payload
13
+ end
14
+
15
+ #
16
+ # Make a GET request
17
+ #
18
+ # @return [Net::HTTPResponse]
19
+ #
20
+ def get
21
+ uri.query = Addressable::URI.form_encode(payload)
22
+ get = Net::HTTP::Get.new(uri)
23
+
24
+ request(get)
25
+ end
26
+
27
+ #
28
+ # Make a POST request
29
+ #
30
+ # @return [Net::HTTPResponse]
31
+ #
32
+ def post
33
+ post = Net::HTTP::Post.new(uri)
34
+
35
+ case content_type
36
+ when "application/json"
37
+ post.body = JSON.generate(payload)
38
+ when "application/x-www-form-urlencoded"
39
+ post.set_form_data(payload)
40
+ end
41
+
42
+ request(post)
43
+ end
44
+
45
+ class << self
46
+ def get(uri, headers: {}, payload: {})
47
+ client = new(uri, headers: headers, payload: payload)
48
+ client.get
49
+ end
50
+
51
+ def post(uri, headers: {}, payload: {})
52
+ client = new(uri, headers: headers, payload: payload)
53
+ client.post
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def content_type
60
+ headers["content-type"] || "application/json"
61
+ end
62
+
63
+ #
64
+ # Get options for HTTP request
65
+ #
66
+ # @return [Hahs]
67
+ #
68
+ def https_options
69
+ return { use_ssl: true } if uri.scheme == "https"
70
+
71
+ {}
72
+ end
73
+
74
+ #
75
+ # Make a HTTP request
76
+ #
77
+ # @param [Net::HTTPRequest] req
78
+ #
79
+ # @return [Net::HTTPResponse]
80
+ #
81
+ def request(req)
82
+ Net::HTTP.start(uri.host, uri.port, https_options) do |http|
83
+ # set headers
84
+ headers.each do |k, v|
85
+ req[k] = v
86
+ end
87
+
88
+ res = http.request(req)
89
+
90
+ unless res.is_a?(Net::HTTPSuccess)
91
+ code = res.code.to_i
92
+ raise HttpError, "Unsuccessful response code returned: #{code}"
93
+ end
94
+
95
+ res
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Mixins
5
+ module ErrorNotification
6
+ #
7
+ # Send an exception notification if there is any error in a block
8
+ #
9
+ # @return [Nil]
10
+ #
11
+ def with_error_notification
12
+ yield
13
+ rescue StandardError => e
14
+ Mihari.logger.error e
15
+
16
+ Sentry.capture_exception(e) if Sentry.initialized?
17
+ end
18
+ end
19
+ end
20
+ end
@@ -3,20 +3,30 @@
3
3
  module Mihari
4
4
  module Mixins
5
5
  module Retriable
6
+ DEFAULT_ON = [
7
+ Errno::ECONNRESET,
8
+ Errno::ECONNABORTED,
9
+ Errno::EPIPE,
10
+ OpenSSL::SSL::SSLError,
11
+ Timeout::Error,
12
+ RetryableError
13
+ ]
14
+
6
15
  #
7
16
  # Retry on error
8
17
  #
9
18
  # @param [Integer] times
10
19
  # @param [Integer] interval
20
+ # @param [Array<StandardError>] on
11
21
  #
12
22
  # @return [nil]
13
23
  #
14
- def retry_on_error(times: 3, interval: 10)
24
+ def retry_on_error(times: 3, interval: 5, on: DEFAULT_ON)
15
25
  try = 0
16
26
  begin
17
27
  try += 1
18
28
  yield
19
- rescue Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, OpenSSL::SSL::SSLError, Timeout::Error, RetryableError => e
29
+ rescue *on => e
20
30
  sleep interval
21
31
  retry if try < times
22
32
  raise e
@@ -48,8 +48,7 @@ module Mihari
48
48
  def validate_rule!(rule)
49
49
  rule.validate!
50
50
  rescue RuleValidationError => e
51
- error_message = "Failed to parse the input as a rule:\n#{e.message}"
52
- puts error_message.colorize(:red)
51
+ Mihari.logger.error "Failed to parse the input as a rule"
53
52
  raise e
54
53
  end
55
54
 
@@ -42,14 +42,26 @@ module Mihari
42
42
  Feed = Dry::Schema.Params do
43
43
  required(:analyzer).value(Types::String.enum("feed"))
44
44
  required(:query).value(:string)
45
- required(:http_request_method).value(Types::FeedHttpRequestMethods).default("GET")
46
- required(:http_request_headers).value(:hash).default({})
47
- required(:http_request_payload).value(:hash).default({})
48
45
  required(:selector).value(:string)
49
- optional(:http_request_payload_type).value(Types::FeedHttpRequestPayloadTypes)
46
+ optional(:http_request_method).value(Types::HttpRequestMethods).default("GET")
47
+ optional(:http_request_headers).value(:hash).default({})
48
+ optional(:http_request_payload).value(:hash).default({})
49
+ optional(:http_request_payload_type).value(Types::HttpRequestPayloadTypes)
50
50
  optional(:options).hash(AnalyzerOptions)
51
51
  end
52
52
 
53
+ Emitter = Dry::Schema.Params do
54
+ required(:emitter).value(Types::EmitterTypes)
55
+ end
56
+
57
+ HTTP = Dry::Schema.Params do
58
+ required(:emitter).value(Types::String.enum("http"))
59
+ required(:url).value(:string)
60
+ optional(:http_request_method).value(Types::HttpRequestMethods).default("POST")
61
+ optional(:http_request_headers).value(:hash).default({})
62
+ optional(:template).value(:string)
63
+ end
64
+
53
65
  Rule = Dry::Schema.Params do
54
66
  required(:title).value(:string)
55
67
  required(:description).value(:string)
@@ -63,11 +75,25 @@ module Mihari
63
75
 
64
76
  required(:queries).value(:array).each { Analyzer | Spyse | ZoomEye | Urlscan | Crtsh | Feed }
65
77
 
78
+ optional(:emitters).value(:array).each { Emitter | HTTP }
79
+
66
80
  optional(:allowed_data_types).value(array[Types::DataTypes]).default(ALLOWED_DATA_TYPES)
67
81
  optional(:disallowed_data_values).value(array[:string]).default([])
68
82
 
69
83
  optional(:ignore_old_artifacts).value(:bool).default(false)
70
84
  optional(:ignore_threshold).value(:integer).default(0)
85
+
86
+ before(:key_coercer) do |result|
87
+ # it looks like that dry-schema v1.9.1 has an issue with setting an array of schemas as a default value
88
+ # e.g. optional(:emitters).value(:array).each { Emitter | HTTP }.default(DEFAULT_EMITTERS) does not work well
89
+ # so let's do a dirty hack...
90
+ h = result.to_h
91
+
92
+ emitters = h[:emitters]
93
+ h[:emitters] = emitters || DEFAULT_EMITTERS
94
+
95
+ h
96
+ end
71
97
  end
72
98
 
73
99
  class RuleContract < Dry::Validation::Contract
@@ -14,13 +14,12 @@ module Mihari
14
14
  include Mixins::AutonomousSystem
15
15
 
16
16
  def from_dynamic!(d)
17
+ d = d.deep_stringify_keys
17
18
  d = Types::Hash[d]
18
19
 
19
20
  asn = nil
20
21
  asn_ = d.dig("asn", "asn")
21
- unless asn_.nil?
22
- asn = normalize_asn(asn_)
23
- end
22
+ asn = normalize_asn(asn_) unless asn_.nil?
24
23
 
25
24
  new(
26
25
  ip: d.fetch("ip"),
@@ -121,6 +121,37 @@ module Mihari
121
121
  data: data
122
122
  )
123
123
  end
124
+
125
+ #
126
+ # @return [Mihari::Analyzers::Rule]
127
+ #
128
+ def to_analyzer
129
+ analyzer = Mihari::Analyzers::Rule.new(
130
+ title: self[:title],
131
+ description: self[:description],
132
+ tags: self[:tags],
133
+ queries: self[:queries],
134
+ allowed_data_types: self[:allowed_data_types],
135
+ disallowed_data_values: self[:disallowed_data_values],
136
+ emitters: self[:emitters],
137
+ id: id
138
+ )
139
+ analyzer.ignore_old_artifacts = self[:ignore_old_artifacts]
140
+ analyzer.ignore_threshold = self[:ignore_threshold]
141
+
142
+ analyzer
143
+ end
144
+
145
+ class << self
146
+ #
147
+ # @param [Mihari::Rule] model
148
+ #
149
+ # @return [Mihari::Structs::Rule::Rule]
150
+ #
151
+ def from_model(model)
152
+ Structs::Rule::Rule.new(model.data)
153
+ end
154
+ end
124
155
  end
125
156
  end
126
157
  end
@@ -26,9 +26,17 @@ module Mihari
26
26
 
27
27
  def self.from_dynamic!(d)
28
28
  d = Types::Hash[d]
29
+
30
+ # hostnames should be an array of string but sometimes Shodan returns a string
31
+ # e.g. "hostnames": "set(['149.28.146.131.vultr.com', 'rebs.ga'])",
32
+ # https://github.com/ninoseki/mihari/issues/424
33
+ # so use an empty array if hostnames is a string
34
+ hostnames = d.fetch("hostnames")
35
+ hostnames = [] if hostnames.is_a?(String)
36
+
29
37
  new(
30
38
  asn: d["asn"],
31
- hostnames: d.fetch("hostnames"),
39
+ hostnames: hostnames,
32
40
  location: Location.from_dynamic!(d.fetch("location")),
33
41
  domains: d.fetch("domains"),
34
42
  ip_str: d.fetch("ip_str"),
data/lib/mihari/types.rb CHANGED
@@ -22,7 +22,6 @@ module Mihari
22
22
  "circl",
23
23
  "dnpedia",
24
24
  "dnstwister",
25
- "feed",
26
25
  "greynoise",
27
26
  "onyphe",
28
27
  "otx",
@@ -38,7 +37,16 @@ module Mihari
38
37
  "vt"
39
38
  )
40
39
 
41
- FeedHttpRequestMethods = Types::String.enum("GET", "POST")
42
- FeedHttpRequestPayloadTypes = Types::String.enum("application/json", "application/x-www-form-urlencoded")
40
+ HttpRequestMethods = Types::String.enum("GET", "POST")
41
+ HttpRequestPayloadTypes = Types::String.enum("application/json", "application/x-www-form-urlencoded")
42
+
43
+ EmitterTypes = Types::String.enum(
44
+ "database",
45
+ "http",
46
+ "misp",
47
+ "slack",
48
+ "the_hive",
49
+ "webhook"
50
+ )
43
51
  end
44
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "4.1.1"
4
+ VERSION = "4.3.0"
5
5
  end
@@ -1,25 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Entities
4
- require "mihari/web/entities/message"
5
-
6
- require "mihari/web/entities/autonomous_system"
7
- require "mihari/web/entities/command"
8
- require "mihari/web/entities/config"
9
- require "mihari/web/entities/dns"
10
- require "mihari/web/entities/geolocation"
11
- require "mihari/web/entities/ip_address"
12
- require "mihari/web/entities/reverse_dns"
13
- require "mihari/web/entities/source"
14
- require "mihari/web/entities/tag"
15
- require "mihari/web/entities/whois"
16
-
17
- require "mihari/web/entities/artifact"
18
-
19
- require "mihari/web/entities/alert"
20
-
21
- require "mihari/web/entities/rule"
22
-
23
3
  # Endpoints
24
4
  require "mihari/web/endpoints/alerts"
25
5
  require "mihari/web/endpoints/artifacts"
@@ -6,12 +6,11 @@ require "rack/contrib"
6
6
  require "rack/handler/puma"
7
7
  require "rack/cors"
8
8
 
9
- require "grape"
10
- require "grape-entity"
11
9
  require "grape-swagger"
12
10
  require "grape-swagger-entity"
13
11
 
14
12
  require "mihari/web/middleware/connection_adapter"
13
+ require "mihari/web/middleware/error_notification_adapter"
15
14
 
16
15
  require "mihari/web/api"
17
16
 
@@ -37,6 +36,7 @@ module Mihari
37
36
  end
38
37
 
39
38
  use Middleware::ConnectionAdapter
39
+ use Middleware::ErrorNotificationAdapter
40
40
 
41
41
  run App.new
42
42
  end.to_app
@@ -79,7 +79,9 @@ module Mihari
79
79
  error!({ message: "ID:#{id} is not found" }, 404)
80
80
  end
81
81
 
82
- Mihari::CLI::Main.start ["search", rule.id]
82
+ struct = Mihari::Structs::Rule::Rule.from_model(rule)
83
+ analyzer = struct.to_analyzer
84
+ analyzer.run
83
85
 
84
86
  status 201
85
87
  present({ message: "ID:#{id} is ran successfully" }, with: Entities::Message)
@@ -0,0 +1,19 @@
1
+ module Mihari
2
+ module Middleware
3
+ class ErrorNotificationAdapter
4
+ include Mixins::ErrorNotification
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ with_error_notification do
12
+ status, headers, body = @app.call(env)
13
+
14
+ [status, headers, body]
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1 +1 @@
1
- <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/static/favicon.ico"><title>Mihari</title><link href="/static/js/app.b88ce341.js" rel="preload" as="script"></head><body><noscript><strong>We're sorry but Mihari doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/static/js/app.b88ce341.js"></script></body></html>
1
+ <!doctype html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="icon" href="/static/favicon.ico"/><title>Mihari</title><script defer="defer" type="module" src="/static/js/chunk-vendors.c5525f1e.js"></script><script defer="defer" type="module" src="/static/js/app.e74e91d7.js"></script><link href="/static/css/chunk-vendors.c57bb3fd.css" rel="stylesheet"><link href="/static/css/app.0de4b715.css" rel="stylesheet"><script defer="defer" src="/static/js/chunk-vendors-legacy.41357cdf.js" nomodule></script><script defer="defer" src="/static/js/app-legacy.e451304b.js" nomodule></script></head><body><noscript><strong>We're sorry but Mihari doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>