mihari 3.9.2 → 3.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) 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 +1 -1
  5. data/lib/mihari/analyzers/binaryedge.rb +5 -0
  6. data/lib/mihari/analyzers/censys.rb +5 -0
  7. data/lib/mihari/analyzers/feed.rb +39 -0
  8. data/lib/mihari/analyzers/greynoise.rb +65 -0
  9. data/lib/mihari/analyzers/onyphe.rb +5 -0
  10. data/lib/mihari/analyzers/rule.rb +8 -0
  11. data/lib/mihari/analyzers/shodan.rb +16 -5
  12. data/lib/mihari/analyzers/urlscan.rb +37 -13
  13. data/lib/mihari/analyzers/virustotal_intelligence.rb +5 -0
  14. data/lib/mihari/analyzers/zoomeye.rb +8 -0
  15. data/lib/mihari/cli/analyzer.rb +5 -0
  16. data/lib/mihari/commands/feed.rb +26 -0
  17. data/lib/mihari/commands/greynoise.rb +21 -0
  18. data/lib/mihari/commands/urlscan.rb +1 -2
  19. data/lib/mihari/database.rb +4 -4
  20. data/lib/mihari/enrichers/ipinfo.rb +2 -0
  21. data/lib/mihari/errors.rb +4 -0
  22. data/lib/mihari/feed/parser.rb +34 -0
  23. data/lib/mihari/feed/reader.rb +113 -0
  24. data/lib/mihari/mixins/autonomous_system.rb +2 -0
  25. data/lib/mihari/mixins/configuration.rb +2 -2
  26. data/lib/mihari/mixins/disallowed_data_value.rb +2 -0
  27. data/lib/mihari/mixins/rule.rb +2 -0
  28. data/lib/mihari/models/alert.rb +4 -5
  29. data/lib/mihari/models/artifact.rb +2 -3
  30. data/lib/mihari/models/dns.rb +2 -2
  31. data/lib/mihari/schemas/configuration.rb +3 -2
  32. data/lib/mihari/schemas/rule.rb +21 -2
  33. data/lib/mihari/status.rb +2 -2
  34. data/lib/mihari/structs/alert.rb +3 -1
  35. data/lib/mihari/structs/censys.rb +2 -0
  36. data/lib/mihari/structs/greynoise.rb +57 -0
  37. data/lib/mihari/structs/ipinfo.rb +2 -0
  38. data/lib/mihari/structs/onyphe.rb +2 -0
  39. data/lib/mihari/structs/shodan.rb +8 -6
  40. data/lib/mihari/structs/urlscan.rb +53 -0
  41. data/lib/mihari/structs/virustotal_intelligence.rb +2 -0
  42. data/lib/mihari/types.rb +10 -0
  43. data/lib/mihari/version.rb +1 -1
  44. data/lib/mihari/web/api.rb +2 -0
  45. data/lib/mihari/web/entities/artifact.rb +2 -2
  46. data/lib/mihari/web/entities/whois.rb +1 -1
  47. data/lib/mihari/web/public/index.html +1 -1
  48. data/lib/mihari/web/public/redoc-static.html +181 -183
  49. data/lib/mihari/web/public/static/js/app.0a0cc502.js +21 -0
  50. data/lib/mihari/web/public/static/js/app.0a0cc502.js.map +1 -0
  51. data/lib/mihari/web/public/static/js/app.5dc97aae.js +21 -0
  52. data/lib/mihari/web/public/static/js/app.5dc97aae.js.map +1 -0
  53. data/lib/mihari/web/public/static/js/app.f2b8890f.js +21 -0
  54. data/lib/mihari/web/public/static/js/app.f2b8890f.js.map +1 -0
  55. data/lib/mihari/web/public/static/js/app.fbc19869.js +21 -0
  56. data/lib/mihari/web/public/static/js/app.fbc19869.js.map +1 -0
  57. data/lib/mihari.rb +7 -2
  58. data/mihari.gemspec +22 -21
  59. data/sig/lib/mihari/analyzers/binaryedge.rbs +2 -0
  60. data/sig/lib/mihari/analyzers/censys.rbs +2 -0
  61. data/sig/lib/mihari/analyzers/feed.rbs +23 -0
  62. data/sig/lib/mihari/analyzers/onyphe.rbs +2 -0
  63. data/sig/lib/mihari/analyzers/shodan.rbs +2 -0
  64. data/sig/lib/mihari/analyzers/urlscan.rbs +5 -2
  65. data/sig/lib/mihari/analyzers/virustotal_intelligence.rbs +2 -0
  66. data/sig/lib/mihari/analyzers/zoomeye.rbs +2 -0
  67. data/sig/lib/mihari/cli/analyzer.rbs +4 -0
  68. data/sig/lib/mihari/commands/feed.rbs +7 -0
  69. data/sig/lib/mihari/feed/parser.rbs +11 -0
  70. data/sig/lib/mihari/feed/reader.rbs +56 -0
  71. data/sig/lib/mihari/structs/alert.rbs +1 -1
  72. data/sig/lib/mihari/structs/greynoise.rbs +30 -0
  73. data/sig/lib/mihari/structs/shodan.rbs +3 -3
  74. data/sig/lib/mihari/structs/urlscan.rbs +28 -0
  75. data/sig/lib/mihari/types.rbs +4 -0
  76. metadata +120 -84
data/lib/mihari.rb CHANGED
@@ -37,6 +37,8 @@ module Mihari
37
37
  setting :censys_secret, default: ENV["CENSYS_SECRET"]
38
38
  setting :circl_passive_password, default: ENV["CIRCL_PASSIVE_PASSWORD"]
39
39
  setting :circl_passive_username, default: ENV["CIRCL_PASSIVE_USERNAME"]
40
+ setting :database, default: ENV["DATABASE"] || "mihari.db"
41
+ setting :greynoise_api_key, default: ENV["GREYNOISE_API_KEY"]
40
42
  setting :ipinfo_api_key, default: ENV["IPINFO_API_KEY"]
41
43
  setting :misp_api_endpoint, default: ENV["MISP_API_ENDPOINT"]
42
44
  setting :misp_api_key, default: ENV["MISP_API_KEY"]
@@ -54,10 +56,9 @@ module Mihari
54
56
  setting :thehive_api_key, default: ENV["THEHIVE_API_KEY"]
55
57
  setting :urlscan_api_key, default: ENV["URLSCAN_API_KEY"]
56
58
  setting :virustotal_api_key, default: ENV["VIRUSTOTAL_API_KEY"]
57
- setting :zoomeye_api_key, default: ENV["ZOOMEYE_API_KEY"]
58
59
  setting :webhook_url, default: ENV["WEBHOOK_URL"]
59
60
  setting :webhook_use_json_body, constructor: ->(value = ENV["WEBHOOK_USE_JSON_BODY"]) { truthy?(value) }
60
- setting :database, default: ENV["DATABASE"] || "mihari.db"
61
+ setting :zoomeye_api_key, default: ENV["ZOOMEYE_API_KEY"]
61
62
 
62
63
  class << self
63
64
  include Mem
@@ -112,9 +113,11 @@ require "mihari/types"
112
113
  # Structs
113
114
  require "mihari/structs/alert"
114
115
  require "mihari/structs/censys"
116
+ require "mihari/structs/greynoise"
115
117
  require "mihari/structs/ipinfo"
116
118
  require "mihari/structs/onyphe"
117
119
  require "mihari/structs/shodan"
120
+ require "mihari/structs/urlscan"
118
121
  require "mihari/structs/virustotal_intelligence"
119
122
 
120
123
  # Schemas
@@ -147,6 +150,8 @@ require "mihari/analyzers/circl"
147
150
  require "mihari/analyzers/crtsh"
148
151
  require "mihari/analyzers/dnpedia"
149
152
  require "mihari/analyzers/dnstwister"
153
+ require "mihari/analyzers/feed"
154
+ require "mihari/analyzers/greynoise"
150
155
  require "mihari/analyzers/onyphe"
151
156
  require "mihari/analyzers/otx"
152
157
  require "mihari/analyzers/passivetotal"
data/mihari.gemspec CHANGED
@@ -25,9 +25,9 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_development_dependency "bundler", "~> 2.2"
28
+ spec.add_development_dependency "bundler", "~> 2.3"
29
29
  spec.add_development_dependency "coveralls_reborn", "~> 0.23"
30
- spec.add_development_dependency "fakefs", "~> 1.3"
30
+ spec.add_development_dependency "fakefs", "~> 1.4"
31
31
  spec.add_development_dependency "mysql2", "~> 0.5"
32
32
  spec.add_development_dependency "overcommit", "~> 0.58"
33
33
  spec.add_development_dependency "pg", "~> 1.2"
@@ -36,14 +36,13 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "rb-fsevent", "~> 0.11"
37
37
  spec.add_development_dependency "rerun", "~> 0.13"
38
38
  spec.add_development_dependency "rspec", "~> 3.10"
39
- spec.add_development_dependency "standard", "~> 1.3"
40
- spec.add_development_dependency "steep", "~> 0.46"
39
+ spec.add_development_dependency "standard", "~> 1.5"
40
+ spec.add_development_dependency "steep", "~> 0.47"
41
41
  spec.add_development_dependency "timecop", "~> 0.9"
42
42
  spec.add_development_dependency "vcr", "~> 6.0"
43
43
  spec.add_development_dependency "webmock", "~> 3.14"
44
44
 
45
- spec.add_dependency "activerecord", "~> 6.1"
46
- spec.add_dependency "activerecord-filter", "~> 6.1"
45
+ spec.add_dependency "activerecord", "7.0.0"
47
46
  spec.add_dependency "addressable", "~> 2.8"
48
47
  spec.add_dependency "awrence", "~> 1.2"
49
48
  spec.add_dependency "binaryedge", "~> 0.1"
@@ -54,19 +53,21 @@ Gem::Specification.new do |spec|
54
53
  spec.add_dependency "dnpedia", "~> 0.1"
55
54
  spec.add_dependency "dnstwister", "~> 0.1"
56
55
  spec.add_dependency "dotenv", "~> 2.7"
57
- spec.add_dependency "dry-configurable", "~> 0.13"
58
- spec.add_dependency "dry-container", "~> 0.9"
59
- spec.add_dependency "dry-files", "~> 0.1"
60
- spec.add_dependency "dry-initializer", "~> 3.0"
61
- spec.add_dependency "dry-struct", "~> 1.4"
62
- spec.add_dependency "dry-validation", "~> 1.7"
56
+ spec.add_dependency "dry-configurable", "0.13.0"
57
+ spec.add_dependency "dry-container", "0.9.0"
58
+ spec.add_dependency "dry-files", "0.1.0"
59
+ spec.add_dependency "dry-initializer", "3.0.4"
60
+ spec.add_dependency "dry-struct", "1.4.0"
61
+ spec.add_dependency "dry-validation", "1.7.0"
63
62
  spec.add_dependency "email_address", "~> 0.2"
64
- spec.add_dependency "grape", "~> 1.6"
65
- spec.add_dependency "grape-entity", "~> 0.10"
66
- spec.add_dependency "grape-swagger", "~> 1.4"
67
- spec.add_dependency "grape-swagger-entity", "~> 0.5"
63
+ spec.add_dependency "grape", "1.6.2"
64
+ spec.add_dependency "grape-entity", "0.10.1"
65
+ spec.add_dependency "grape-swagger", "1.4.2"
66
+ spec.add_dependency "grape-swagger-entity", "0.5.1"
67
+ spec.add_dependency "greynoise", "~> 0.1"
68
68
  spec.add_dependency "hachi", "~> 1.0"
69
69
  spec.add_dependency "http", "~> 5.0"
70
+ spec.add_dependency "jr-cli", "~> 0.5"
70
71
  spec.add_dependency "launchy", "~> 2.5"
71
72
  spec.add_dependency "mem", "~> 0.1"
72
73
  spec.add_dependency "memist", "~> 2.0"
@@ -81,9 +82,9 @@ Gem::Specification.new do |spec|
81
82
  spec.add_dependency "plissken", "~> 1.4"
82
83
  spec.add_dependency "public_suffix", "~> 4.0"
83
84
  spec.add_dependency "pulsedive", "~> 0.1"
84
- spec.add_dependency "puma", "~> 5.5"
85
- spec.add_dependency "rack", "~> 2.2"
86
- spec.add_dependency "rack-contrib", "~> 2.3"
85
+ spec.add_dependency "puma", "5.5.2"
86
+ spec.add_dependency "rack", "2.2.3"
87
+ spec.add_dependency "rack-contrib", "2.3.0"
87
88
  spec.add_dependency "rack-cors", "~> 1.1"
88
89
  spec.add_dependency "safe_shell", "~> 1.1"
89
90
  spec.add_dependency "securitytrails", "~> 1.0"
@@ -91,9 +92,9 @@ Gem::Specification.new do |spec|
91
92
  spec.add_dependency "slack-notifier", "~> 2.4"
92
93
  spec.add_dependency "spysex", "~> 0.2"
93
94
  spec.add_dependency "sqlite3", "~> 1.4"
94
- spec.add_dependency "thor", "~> 1.1"
95
+ spec.add_dependency "thor", "1.1.0"
95
96
  spec.add_dependency "thread_safe", "~> 0.3"
96
- spec.add_dependency "urlscan", "~> 0.7"
97
+ spec.add_dependency "urlscan", "~> 0.8"
97
98
  spec.add_dependency "uuidtools", "~> 2.2"
98
99
  spec.add_dependency "virustotalx", "~> 1.2"
99
100
  spec.add_dependency "whois", "~> 5.0"
@@ -7,6 +7,8 @@ module Mihari
7
7
  attr_reader description: String
8
8
  attr_reader tags: Array[String]
9
9
 
10
+ attr_reader interval: ::Integer
11
+
10
12
  def artifacts: () -> (Array[String] | Array[Mihari::Artifact])
11
13
 
12
14
  private
@@ -6,6 +6,8 @@ module Mihari
6
6
  attr_reader description: String
7
7
  attr_reader tags: Array[String]
8
8
 
9
+ attr_reader interval: ::Integer
10
+
9
11
  def artifacts: () -> (Array[String] | Array[Mihari::Artifact])
10
12
 
11
13
  private
@@ -0,0 +1,23 @@
1
+ module Mihari
2
+ module Analyzers
3
+ class Feed < Base
4
+ attr_reader query: String
5
+ attr_reader title: String
6
+ attr_reader description: String
7
+ attr_reader tags: Array[String]
8
+
9
+ attr_reader http_request_headers: Hash[(String | Symbol), untyped]
10
+ attr_reader http_request_method: String
11
+ attr_reader http_request_payload_type: String?
12
+ attr_reader http_request_payload: Hash[(String | Symbol), untyped]
13
+
14
+ attr_reader selector: String
15
+
16
+ def artifacts: () -> (Array[String] | Array[Mihari::Artifact])
17
+
18
+ private
19
+
20
+ def data: () -> Array[Hash]
21
+ end
22
+ end
23
+ end
@@ -6,6 +6,8 @@ module Mihari
6
6
  attr_reader description: String
7
7
  attr_reader tags: Array[String]
8
8
 
9
+ attr_reader interval: ::Integer
10
+
9
11
  def artifacts: () -> (Array[String] | Array[Mihari::Artifact])
10
12
 
11
13
  private
@@ -6,6 +6,8 @@ module Mihari
6
6
  attr_reader description: String
7
7
  attr_reader tags: Array[String]
8
8
 
9
+ attr_reader interval: ::Integer
10
+
9
11
  def artifacts: () -> (Array[String] | Array[Mihari::Artifact])
10
12
 
11
13
  private
@@ -8,7 +8,8 @@ module Mihari
8
8
  attr_reader description: String
9
9
  attr_reader tags: Array[String]
10
10
  attr_reader allowed_data_types: Array[String]
11
- attr_reader use_similarity: bool
11
+
12
+ attr_reader interval: ::Integer
12
13
 
13
14
  def initialize: (*untyped args, **untyped kwargs) -> void
14
15
 
@@ -20,7 +21,9 @@ module Mihari
20
21
 
21
22
  def api: () -> untyped
22
23
 
23
- def search: () -> Array[Hash[(String | Symbol), untyped]]
24
+ def search_with_search_after: (search_after: String?) -> Array[Hash[(String | Symbol), untyped]]
25
+
26
+ def search: () -> Array[Mihari::Structs::Urlscan::Response]
24
27
 
25
28
  def valid_alllowed_data_types?: () -> bool
26
29
  end
@@ -6,6 +6,8 @@ module Mihari
6
6
  attr_reader description: String
7
7
  attr_reader tags: Array[String]
8
8
 
9
+ attr_reader interval: ::Integer
10
+
9
11
  def initialize: (*untyped args, **untyped kwargs) -> void
10
12
 
11
13
  def artifacts: () -> (Array[String] | Array[Mihari::Artifact])
@@ -7,6 +7,8 @@ module Mihari
7
7
  attr_reader tags: Array[String]
8
8
  attr_reader type: String
9
9
 
10
+ attr_reader interval: ::Integer
11
+
10
12
  def artifacts: () -> (Array[String] | Array[Mihari::Artifact])
11
13
 
12
14
  private
@@ -13,6 +13,10 @@ module Mihari
13
13
 
14
14
  include Mihari::Commands::DNSTwister
15
15
 
16
+ include Mihari::Commands::Feed
17
+
18
+ include Mihari::Commands::GreyNoise
19
+
16
20
  include Mihari::Commands::JSON
17
21
 
18
22
  include Mihari::Commands::Onyphe
@@ -0,0 +1,7 @@
1
+ module Mihari
2
+ module Commands
3
+ module Feed
4
+ def self.included: (untyped thor) -> untyped
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module Mihari
2
+ module Feed
3
+ class Parser
4
+ attr_reader data: Array[Hash] | Array[Array[String]]
5
+
6
+ def initialize: (Array[Hash] | Array[Array[String]] data) -> void
7
+
8
+ def parse: (String selector) -> Array[String]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,56 @@
1
+ module Mihari
2
+ class FeedReader
3
+ attr_reader uri: URI
4
+
5
+ attr_reader http_request_headers: Hash[(String | Symbol), untyped]
6
+
7
+ attr_reader http_request_method: String
8
+
9
+ attr_reader http_request_payload_type: String?
10
+
11
+ attr_reader http_request_payload: Hash[(String | Symbol), untyped]
12
+
13
+ def initialize: (
14
+ String url,
15
+ ?http_request_headers: Hash[(String | Symbol), untyped]] http_request_headers,
16
+ ?http_request_method: ::String http_request_method,
17
+ ?http_request_payload_type: String? http_request_payload_type,
18
+ ?http_request_payload: Hash[(String | Symbol), untyped] http_request_payload
19
+ ) -> void
20
+
21
+ def read: () -> Array[Hash]
22
+
23
+ def get: () -> Array[Hash]
24
+
25
+ def post: () -> Array[Hash]
26
+
27
+ #
28
+ # Convert text as JSON
29
+ #
30
+ # @param [String] text
31
+ #
32
+ # @return [Array<Hash>]
33
+ #
34
+ def convert_as_json: (String text) -> Array[Hash]
35
+
36
+ #
37
+ # Convert text as CSV
38
+ #
39
+ # @param [String] text
40
+ #
41
+ # @return [Array<Hash>]
42
+ #
43
+ def convert_as_csv: (String text) -> Array[Hash]
44
+
45
+ def https_options: () -> ({ use_ssl: ::TrueClass } | ::Hash[untyped, untyped])
46
+
47
+ #
48
+ # Make a HTTP request
49
+ #
50
+ # @param [Net::HTTPRequest] req
51
+ #
52
+ # @return [Array<Hash>]
53
+ #
54
+ def request: (Net::HTTPRequest req) -> Array[Hash]
55
+ end
56
+ end
@@ -13,7 +13,7 @@ module Mihari
13
13
  attr_reader dns_record: String?
14
14
  attr_reader reverse_dns_name: String?
15
15
 
16
- def has_valid_artifact_filters: () -> bool
16
+ def valid_artifact_filters?: () -> bool
17
17
  end
18
18
 
19
19
  class SearchFilterWithPagination
@@ -0,0 +1,30 @@
1
+ module Mihari
2
+ module Structs
3
+ module GreyNoise
4
+ class Metadata < Dry::Struct
5
+ attr_reader country: String
6
+ attr_reader country_code: String
7
+ attr_reader asn: String
8
+
9
+ def self.from_dynamic!: (Hash[(String | Symbol), untyped] d) -> Mihari::Structs::GreyNoise::Metadata
10
+ end
11
+
12
+ class Datum < Dry::Struct
13
+ attr_reader ip: String
14
+ attr_reader metadata: Mihari::Structs::GreyNoise::Metadata
15
+
16
+ def self.from_dynamic!: (Hash[(String | Symbol), untyped] d) -> Mihari::Structs::GreyNoise::Datum
17
+ end
18
+
19
+ class Response < Dry::Struct
20
+ attr_reader complete: Boolean
21
+ attr_reader count: Integer
22
+ attr_reader data: Array[Mihari::Structs::GreyNoise::Danum]
23
+ attr_reader message: String
24
+ attr_reader query: String
25
+
26
+ def self.from_dynamic!: (Hash[(String | Symbol), untyped] d) -> Mihari::Structs::GreyNoise::Response
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,14 +2,14 @@ module Mihari
2
2
  module Structs
3
3
  module Shodan
4
4
  class Location
5
- attr_reader country_code: String
6
- attr_reader country_name: String
5
+ attr_reader country_code: String?
6
+ attr_reader country_name: String?
7
7
 
8
8
  def self.from_dynamic!: (Hash[(String | Symbol), untyped] d) -> Mihari::Structs::Shodan::Location
9
9
  end
10
10
 
11
11
  class Match
12
- attr_reader asn: String
12
+ attr_reader asn: String?
13
13
  attr_reader hostnames: Array[String]
14
14
  attr_reader location: Mihari::Structs::Shodan::Location
15
15
  attr_reader domains: Array[String]
@@ -0,0 +1,28 @@
1
+ module Mihari
2
+ module Structs
3
+ module Urlscan
4
+ class Page < Dry::Struct
5
+ attr_reader domain: String?
6
+ attr_reader ip: String?
7
+ attr_reader url: String
8
+
9
+ def self.from_dynamic!: (Hash[(String | Symbol), untyped] d) -> Mihari::Structs::Urlscan::Page
10
+ end
11
+
12
+ class Result < Dry::Struct
13
+ attr_reader page: Mihari::Structs::Urlscan::Page
14
+ attr_reader id: String
15
+ attr_reader sort: Array[Integer | String]
16
+
17
+ def self.from_dynamic!: (Hash[(String | Symbol), untyped] d) -> Mihari::Structs::Urlscan::Result
18
+ end
19
+
20
+ class Response < Dry::Struct
21
+ attr_reader results: Array[Mihari::Structs::Urlscan::Result]
22
+ attr_reader has_more: Boolean
23
+
24
+ def self.from_dynamic!: (Hash[(String | Symbol), untyped] d) -> Mihari::Structs::Urlscan::Response
25
+ end
26
+ end
27
+ end
28
+ end
@@ -13,5 +13,9 @@ module Mihari
13
13
  DataTypes: Array[String]
14
14
 
15
15
  AnalyzerTypes: Array[String]
16
+
17
+ FeedHttpRequestMethods: Array[String]
18
+
19
+ FeedHttpRequestPayloadTypes: Array[String]
16
20
  end
17
21
  end