mihari 5.3.2 → 5.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/mihari/config.rb CHANGED
@@ -1,86 +1,98 @@
1
1
  module Mihari
2
2
  class Config
3
3
  # @return [String, nil]
4
- attr_accessor :binaryedge_api_key
4
+ attr_reader :binaryedge_api_key
5
5
 
6
6
  # @return [String, nil]
7
- attr_accessor :censys_id
7
+ attr_reader :censys_id
8
8
 
9
9
  # @return [String, nil]
10
- attr_accessor :censys_secret
10
+ attr_reader :censys_secret
11
11
 
12
12
  # @return [String, nil]
13
- attr_accessor :circl_passive_password
13
+ attr_reader :circl_passive_password
14
14
 
15
15
  # @return [String, nil]
16
- attr_accessor :circl_passive_username
16
+ attr_reader :circl_passive_username
17
17
 
18
18
  # @return [URI]
19
- attr_accessor :database_url
19
+ attr_reader :database_url
20
20
 
21
21
  # @return [String, nil]
22
- attr_accessor :greynoise_api_key
22
+ attr_reader :greynoise_api_key
23
23
 
24
24
  # @return [String, nil]
25
- attr_accessor :ipinfo_api_key
25
+ attr_reader :hunterhow_api_key
26
26
 
27
27
  # @return [String, nil]
28
- attr_accessor :misp_url
28
+ attr_reader :ipinfo_api_key
29
29
 
30
30
  # @return [String, nil]
31
- attr_accessor :misp_api_key
31
+ attr_reader :misp_url
32
32
 
33
33
  # @return [String, nil]
34
- attr_accessor :onyphe_api_key
34
+ attr_reader :misp_api_key
35
35
 
36
36
  # @return [String, nil]
37
- attr_accessor :otx_api_key
37
+ attr_reader :onyphe_api_key
38
38
 
39
39
  # @return [String, nil]
40
- attr_accessor :passivetotal_api_key
40
+ attr_reader :otx_api_key
41
41
 
42
42
  # @return [String, nil]
43
- attr_accessor :passivetotal_username
43
+ attr_reader :passivetotal_api_key
44
44
 
45
45
  # @return [String, nil]
46
- attr_accessor :pulsedive_api_key
46
+ attr_reader :passivetotal_username
47
47
 
48
48
  # @return [String, nil]
49
- attr_accessor :securitytrails_api_key
49
+ attr_reader :pulsedive_api_key
50
50
 
51
51
  # @return [String, nil]
52
- attr_accessor :shodan_api_key
52
+ attr_reader :securitytrails_api_key
53
53
 
54
54
  # @return [String, nil]
55
- attr_accessor :slack_channel
55
+ attr_reader :shodan_api_key
56
56
 
57
57
  # @return [String, nil]
58
- attr_accessor :slack_webhook_url
58
+ attr_reader :slack_channel
59
59
 
60
60
  # @return [String, nil]
61
- attr_accessor :thehive_url
61
+ attr_reader :slack_webhook_url
62
62
 
63
63
  # @return [String, nil]
64
- attr_accessor :thehive_api_key
64
+ attr_reader :thehive_url
65
65
 
66
66
  # @return [String, nil]
67
- attr_accessor :thehive_api_version
67
+ attr_reader :thehive_api_key
68
68
 
69
69
  # @return [String, nil]
70
- attr_accessor :urlscan_api_key
70
+ attr_reader :thehive_api_version
71
71
 
72
72
  # @return [String, nil]
73
- attr_accessor :virustotal_api_key
73
+ attr_reader :urlscan_api_key
74
74
 
75
75
  # @return [String, nil]
76
- attr_accessor :zoomeye_api_key
76
+ attr_reader :virustotal_api_key
77
77
 
78
78
  # @return [String, nil]
79
- attr_accessor :sentry_dsn
79
+ attr_reader :zoomeye_api_key
80
80
 
81
81
  # @return [String, nil]
82
+ attr_reader :sentry_dsn
83
+
84
+ # @return [Boolean]
82
85
  attr_accessor :hide_config_values
83
86
 
87
+ # @return [Integer]
88
+ attr_reader :retry_interval
89
+
90
+ # @return [Integer]
91
+ attr_reader :retry_times
92
+
93
+ # @return [Integer]
94
+ attr_reader :pagination_limit
95
+
84
96
  def initialize
85
97
  @binaryedge_api_key = ENV.fetch("BINARYEDGE_API_KEY", nil)
86
98
 
@@ -96,6 +108,8 @@ module Mihari
96
108
 
97
109
  @ipinfo_api_key = ENV.fetch("IPINFO_API_KEY", nil)
98
110
 
111
+ @hunterhow_api_key = ENV.fetch("HUNTERHOW_API_KEY", nil)
112
+
99
113
  @misp_url = ENV.fetch("MISP_URL", nil)
100
114
  @misp_api_key = ENV.fetch("MISP_API_KEY", nil)
101
115
 
@@ -128,6 +142,11 @@ module Mihari
128
142
  @sentry_dsn = ENV.fetch("SENTRY_DSN", nil)
129
143
 
130
144
  @hide_config_values = ENV.fetch("HIDE_CONFIG_VALUES", false)
145
+
146
+ @retry_times = ENV.fetch("RETRY_TIMES", 3).to_i
147
+ @retry_interval = ENV.fetch("RETRY_INTERVAL", 5).to_i
148
+
149
+ @pagination_limit = ENV.fetch("PAGINATION_LIMIT", 1000).to_i
131
150
  end
132
151
  end
133
152
  end
@@ -9,7 +9,4 @@ module Mihari
9
9
 
10
10
  # @return [Array<Hash>]
11
11
  DEFAULT_ENRICHERS = %w[whois ipinfo shodan google_public_dns].map { |name| { enricher: name } }.freeze
12
-
13
- DEFAULT_RETRY_TIMES = 3
14
- DEFAULT_RETRY_INTERVAL = 5
15
12
  end
@@ -4,8 +4,9 @@ module Mihari
4
4
  module Schemas
5
5
  AnalyzerOptions = Dry::Schema.Params do
6
6
  optional(:interval).value(:integer)
7
- optional(:retry_times).value(:integer).default(DEFAULT_RETRY_TIMES)
8
- optional(:retry_interval).value(:integer).default(DEFAULT_RETRY_INTERVAL)
7
+ optional(:pagination_limit).value(:integer).default(Mihari.config.pagination_limit)
8
+ optional(:retry_times).value(:integer).default(Mihari.config.retry_times)
9
+ optional(:retry_interval).value(:integer).default(Mihari.config.retry_interval)
9
10
  end
10
11
 
11
12
  AnalyzerWithoutAPIKey = Dry::Schema.Params do
@@ -75,6 +76,15 @@ module Mihari
75
76
  optional(:options).hash(AnalyzerOptions)
76
77
  end
77
78
 
79
+ HunterHow = Dry::Schema.Params do
80
+ required(:analyzer).value(Types::String.enum("hunterhow"))
81
+ required(:query).value(:string)
82
+ required(:start_time).value(:date)
83
+ required(:end_time).value(:date)
84
+ optional(:api_key).value(:string)
85
+ optional(:options).hash(AnalyzerOptions)
86
+ end
87
+
78
88
  Feed = Dry::Schema.Params do
79
89
  required(:analyzer).value(Types::String.enum("feed"))
80
90
  required(:query).value(:string)
@@ -22,7 +22,7 @@ module Mihari
22
22
  optional(:updated_on).value(:date)
23
23
 
24
24
  required(:queries).value(:array).each do
25
- AnalyzerWithoutAPIKey | AnalyzerWithAPIKey | Censys | CIRCL | PassiveTotal | ZoomEye | Crtsh | Feed
25
+ AnalyzerWithoutAPIKey | AnalyzerWithAPIKey | Censys | CIRCL | PassiveTotal | ZoomEye | Crtsh | Feed | HunterHow
26
26
  end
27
27
 
28
28
  optional(:emitters).value(:array).each { Database | MISP | TheHive | Slack | Webhook }.default(DEFAULT_EMITTERS)
@@ -0,0 +1,104 @@
1
+ module Mihari
2
+ module Structs
3
+ module HunterHow
4
+ class ListItem < Dry::Struct
5
+ attribute :domain, Types::String
6
+ attribute :ip, Types::String
7
+ attribute :port, Types::Integer
8
+
9
+ #
10
+ # @return [String]
11
+ #
12
+ def ip
13
+ attributes[:ip]
14
+ end
15
+
16
+ #
17
+ # @return [Mihari::Artifact]
18
+ #
19
+ def artifact
20
+ Artifact.new(data: ip)
21
+ end
22
+
23
+ class << self
24
+ #
25
+ # @param [Hash] d
26
+ #
27
+ # @return [ListItem]
28
+ #
29
+ def from_dynamic!(d)
30
+ d = Types::Hash[d]
31
+ new(
32
+ domain: d.fetch("domain"),
33
+ ip: d.fetch("ip"),
34
+ port: d.fetch("port")
35
+ )
36
+ end
37
+ end
38
+ end
39
+
40
+ class DataClass < Dry::Struct
41
+ attribute :list, Types.Array(ListItem)
42
+ attribute :total, Types::Integer
43
+
44
+ #
45
+ # @return [Array<ListItem>]
46
+ #
47
+ def list
48
+ attributes[:list]
49
+ end
50
+
51
+ #
52
+ # @return [Array<Mihari::Artifact>]
53
+ #
54
+ def artifacts
55
+ list.map(&:artifact)
56
+ end
57
+
58
+ class << self
59
+ #
60
+ # @param [Hash] d
61
+ #
62
+ # @return [DataClass]
63
+ #
64
+ def from_dynamic!(d)
65
+ d = Types::Hash[d]
66
+ new(
67
+ list: d.fetch("list").map { |x| ListItem.from_dynamic!(x) },
68
+ total: d.fetch("total")
69
+ )
70
+ end
71
+ end
72
+ end
73
+
74
+ class Response < Dry::Struct
75
+ attribute :code, Types::Integer
76
+ attribute :data, DataClass
77
+ attribute :message, Types::String
78
+
79
+ #
80
+ # @return [DataClass]
81
+ #
82
+ def data
83
+ attributes[:data]
84
+ end
85
+
86
+ class << self
87
+ #
88
+ # @param [Hash] d
89
+ #
90
+ # @return [Response]
91
+ #
92
+ def from_dynamic!(d)
93
+ d = Types::Hash[d]
94
+ new(
95
+ code: d.fetch("code"),
96
+ data: DataClass.from_dynamic!(d.fetch("data")),
97
+ message: d.fetch("message")
98
+ )
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "5.3.2"
4
+ VERSION = "5.4.1"
5
5
  end