mihari 3.9.0 → 3.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Entities
5
+ class DnsRecord < Grape::Entity
6
+ expose :resource, documentation: { type: String, required: true }
7
+ expose :value, documentation: { type: String, required: true }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Entities
5
+ class Geolocation < Grape::Entity
6
+ expose :country, documentation: { type: String, required: true }
7
+ expose :country_code, documentation: { type: String, required: true }, as: :countryCode
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Entities
5
+ class IPAddress < Grape::Entity
6
+ expose :ip, documentation: { type: String, required: true }
7
+ expose :country_code, documentation: { type: String, required: true }, as: :countryCode
8
+ expose :hostname, documentation: { type: String, required: false }
9
+ expose :loc, documentation: { type: String, required: true }
10
+ expose :asn, documentation: { type: Integer, required: false }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Entities
5
+ class Message < Grape::Entity
6
+ expose :message, documentation: { type: String, required: true }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Entities
5
+ class ReverseDnsName < Grape::Entity
6
+ expose :name, documentation: { type: String, required: true }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Entities
5
+ class Sources < Grape::Entity
6
+ expose :sources, documentation: { type: Array[String], required: true }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Entities
5
+ class Tag < Grape::Entity
6
+ expose :name, documentation: { type: String, required: true }
7
+ end
8
+
9
+ class Tags < Grape::Entity
10
+ expose :tags, documentation: { type: Array[String], required: true }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ module Entities
5
+ class WhoisRecord < Grape::Entity
6
+ expose :domain, documentation: { type: String, required: true }
7
+ expose :created_on, documentation: { type: Date, required: false }, as: :createdOn
8
+ expose :updated_on, documentation: { type: Date, required: false }, as: :updatedOn
9
+ expose :expires_on, documentation: { type: Date, required: false }, as: :expiresOn
10
+ expose :registrar, documentation: { type: Hash, required: false }
11
+ expose :contacts, documentation: { type: Hash, is_array: true, required: true } do |whois_record, _options|
12
+ whois_record.contacts.map { |h| h.to_camelback_keys }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "launchy"
4
+ require "rack"
5
+ require "rack/contrib"
6
+ require "rack/handler/puma"
7
+ require "rack/cors"
8
+
9
+ require "grape"
10
+ require "grape-swagger"
11
+
12
+ require "mihari/web/apis/ping"
13
+
14
+ module Mihari
15
+ class API < Grape::API
16
+ prefix "api"
17
+ format :json
18
+ mount Apis::Ping
19
+ add_swagger_documentation api_version: "v1"
20
+ end
21
+
22
+ class GrapeApp
23
+ def initialize
24
+ @filenames = ["", ".html", "index.html", "/index.html"]
25
+ @rack_static = ::Rack::Static.new(
26
+ lambda { [404, {}, []] },
27
+ root: File.expand_path("public", __dir__),
28
+ urls: ["/"]
29
+ )
30
+ end
31
+
32
+ class << self
33
+ def instance
34
+ @instance ||= Rack::Builder.new do
35
+ run GrapeApp.new
36
+ end.to_app
37
+ end
38
+
39
+ def run!(port: 9292, host: "localhost", threads: "0:16", verbose: false)
40
+ url = "http://#{host}:#{port}"
41
+
42
+ Rack::Handler::Puma.run(instance, Port: port, Host: host, Threads: threads, Verbose: verbose) do |server|
43
+ p ENV["RACK_ENV"]
44
+ p instance.class
45
+
46
+ Launchy.open(url) if ENV["RACK_ENV"] != "development"
47
+
48
+ [:INT, :TERM].each do |sig|
49
+ trap(sig) do
50
+ server.shutdown
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ def call(env)
58
+ # api
59
+ p GrapeApp.instance
60
+ response = API.call(env)
61
+
62
+ # Check if the App wants us to pass the response along to others
63
+ if response[1]["X-Cascade"] == "pass"
64
+ # static files
65
+ request_path = env["PATH_INFO"]
66
+ @filenames.each do |path|
67
+ response = @rack_static.call(env.merge("PATH_INFO" => request_path + path))
68
+ return response if response[0] != 404
69
+ end
70
+ end
71
+ end
72
+ end
73
+ 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.378da3dc.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.378da3dc.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><link href="/static/js/app.6b636b62.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.6b636b62.js"></script></body></html>