mihari 3.9.0 → 3.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +6 -7
  3. data/config.ru +1 -1
  4. data/lib/mihari/errors.rb +2 -0
  5. data/lib/mihari/mixins/configuration.rb +12 -2
  6. data/lib/mihari/models/alert.rb +1 -8
  7. data/lib/mihari/models/artifact.rb +3 -0
  8. data/lib/mihari/structs/ipinfo.rb +3 -4
  9. data/lib/mihari/version.rb +1 -1
  10. data/lib/mihari/web/api.rb +43 -0
  11. data/lib/mihari/web/app.rb +47 -29
  12. data/lib/mihari/web/endpoints/alerts.rb +74 -0
  13. data/lib/mihari/web/endpoints/artifacts.rb +92 -0
  14. data/lib/mihari/web/endpoints/command.rb +32 -0
  15. data/lib/mihari/web/endpoints/configs.rb +22 -0
  16. data/lib/mihari/web/endpoints/ip_addresses.rb +27 -0
  17. data/lib/mihari/web/endpoints/sources.rb +18 -0
  18. data/lib/mihari/web/endpoints/tags.rb +38 -0
  19. data/lib/mihari/web/entities/alert.rb +23 -0
  20. data/lib/mihari/web/entities/artifact.rb +24 -0
  21. data/lib/mihari/web/entities/autonomous_system.rb +9 -0
  22. data/lib/mihari/web/entities/command.rb +14 -0
  23. data/lib/mihari/web/entities/config.rb +16 -0
  24. data/lib/mihari/web/entities/dns.rb +10 -0
  25. data/lib/mihari/web/entities/geolocation.rb +10 -0
  26. data/lib/mihari/web/entities/ip_address.rb +13 -0
  27. data/lib/mihari/web/entities/message.rb +9 -0
  28. data/lib/mihari/web/entities/reverse_dns.rb +9 -0
  29. data/lib/mihari/web/entities/source.rb +9 -0
  30. data/lib/mihari/web/entities/tag.rb +13 -0
  31. data/lib/mihari/web/entities/whois.rb +16 -0
  32. data/lib/mihari/web/public/grape.rb +73 -0
  33. data/lib/mihari/web/public/index.html +1 -1
  34. data/lib/mihari/web/public/redoc-static.html +53 -27
  35. data/lib/mihari/web/public/static/js/app.6b636b62.js +50 -0
  36. data/lib/mihari/web/public/static/js/app.6b636b62.js.map +1 -0
  37. data/lib/mihari.rb +2 -12
  38. data/mihari.gemspec +7 -5
  39. data/sig/lib/mihari/web/app.rbs +1 -1
  40. metadata +108 -74
  41. data/lib/mihari/serializers/alert.rb +0 -14
  42. data/lib/mihari/serializers/artifact.rb +0 -18
  43. data/lib/mihari/serializers/autonomous_system.rb +0 -9
  44. data/lib/mihari/serializers/dns.rb +0 -11
  45. data/lib/mihari/serializers/geolocation.rb +0 -11
  46. data/lib/mihari/serializers/reverse_dns.rb +0 -11
  47. data/lib/mihari/serializers/tag.rb +0 -11
  48. data/lib/mihari/serializers/whois.rb +0 -11
  49. data/lib/mihari/web/controllers/alerts_controller.rb +0 -67
  50. data/lib/mihari/web/controllers/analyzers_controller.rb +0 -38
  51. data/lib/mihari/web/controllers/artifacts_controller.rb +0 -94
  52. data/lib/mihari/web/controllers/base_controller.rb +0 -22
  53. data/lib/mihari/web/controllers/command_controller.rb +0 -26
  54. data/lib/mihari/web/controllers/config_controller.rb +0 -13
  55. data/lib/mihari/web/controllers/ip_address_controller.rb +0 -21
  56. data/lib/mihari/web/controllers/sources_controller.rb +0 -12
  57. data/lib/mihari/web/controllers/tags_controller.rb +0 -30
  58. data/lib/mihari/web/helpers/json.rb +0 -53
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rack/contrib/json_body_parser"
4
- require "sinatra"
5
- require "sinatra/param"
6
-
7
- module Mihari
8
- module Controllers
9
- class BaseController < Sinatra::Base
10
- helpers Sinatra::Param
11
-
12
- use Rack::JSONBodyParser
13
-
14
- set :show_exceptions, false
15
- set :raise_sinatra_param_exceptions, true
16
-
17
- error Sinatra::Param::InvalidParameterError do
18
- json({ error: "#{env["sinatra.error"].param} is invalid" })
19
- end
20
- end
21
- end
22
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "safe_shell"
4
-
5
- module Mihari
6
- module Controllers
7
- class CommandController < BaseController
8
- post "/api/command" do
9
- param :command, String, required: true
10
-
11
- command = params["command"]
12
- if command.nil?
13
- status 400
14
- return json({ message: "command is required" })
15
- end
16
-
17
- command = command.split
18
-
19
- output = SafeShell.execute("mihari", *command)
20
- success = $?.success?
21
-
22
- json({ output: output, success: success })
23
- end
24
- end
25
- end
26
- end
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mihari
4
- module Controllers
5
- class ConfigController < BaseController
6
- get "/api/config" do
7
- report = Status.check
8
-
9
- json report.to_camelback_keys
10
- end
11
- end
12
- end
13
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mihari
4
- module Controllers
5
- class IPAddressController < BaseController
6
- get "/api/ip_addresses/:ip" do
7
- param :ip, String, required: true
8
-
9
- ip = params["ip"].to_s
10
-
11
- data = Enrichers::IPInfo.query(ip)
12
- if data.nil?
13
- status 404
14
- json({ message: "IP:#{ip} is not found" })
15
- else
16
- json data.to_hash
17
- end
18
- end
19
- end
20
- end
21
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mihari
4
- module Controllers
5
- class SourcesController < BaseController
6
- get "/api/sources" do
7
- sources = Mihari::Alert.distinct.pluck(:source)
8
- json sources
9
- end
10
- end
11
- end
12
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Mihari
4
- module Controllers
5
- class TagsController < BaseController
6
- get "/api/tags" do
7
- tags = Mihari::Tag.distinct.pluck(:name)
8
- json tags
9
- end
10
-
11
- delete "/api/tags/:name" do
12
- param :name, String, required: true
13
-
14
- name = params["name"].to_s
15
-
16
- begin
17
- Mihari::Tag.where(name: name).destroy_all
18
-
19
- status 204
20
- body ""
21
- rescue ActiveRecord::RecordNotFound
22
- status 404
23
-
24
- message = { message: "Name:#{name} is not found" }
25
- json message
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "awrence"
4
- require "multi_json"
5
- require "sinatra/base"
6
-
7
- module Sinatra
8
- module JSON
9
- class << self
10
- def encode(object)
11
- ::MultiJson.dump(object)
12
- end
13
- end
14
-
15
- def json(object, options = {})
16
- object = object.to_camelback_keys
17
-
18
- content_type resolve_content_type(options)
19
- resolve_encoder_action object, resolve_encoder(options)
20
- end
21
-
22
- private
23
-
24
- def resolve_content_type(options = {})
25
- options[:content_type] || settings.json_content_type
26
- end
27
-
28
- def resolve_encoder(options = {})
29
- options[:json_encoder] || settings.json_encoder
30
- end
31
-
32
- def resolve_encoder_action(object, encoder)
33
- [:encode, :generate].each do |method|
34
- return encoder.send(method, object) if encoder.respond_to? method
35
- end
36
-
37
- if encoder.is_a? Symbol
38
- object.__send__(encoder)
39
- else
40
- fail "#{encoder} does not respond to #generate nor #encode"
41
- end
42
- end
43
- end
44
-
45
- Base.set :json_encoder do
46
- ::MultiJson
47
- end
48
-
49
- Base.set :json_content_type, :json
50
-
51
- # Load the JSON helpers in modular style automatically
52
- Base.helpers JSON
53
- end