mihari 5.6.1 → 5.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/README.md +1 -0
- data/config.ru +1 -1
- data/docs/analyzers/fofa.md +31 -0
- data/docs/analyzers/index.md +1 -0
- data/frontend/package-lock.json +183 -186
- data/frontend/package.json +10 -10
- data/frontend/src/components/alert/Form.vue +1 -14
- data/frontend/src/components/artifact/AS.vue +2 -8
- data/frontend/src/components/artifact/DnsRecords.vue +2 -8
- data/frontend/src/components/artifact/ReverseDnsNames.vue +2 -10
- data/frontend/src/components/artifact/WhoisRecord.vue +1 -1
- data/lib/mihari/{base.rb → actor.rb} +27 -3
- data/lib/mihari/analyzers/base.rb +16 -20
- data/lib/mihari/analyzers/binaryedge.rb +4 -1
- data/lib/mihari/analyzers/censys.rb +5 -3
- data/lib/mihari/analyzers/circl.rb +4 -1
- data/lib/mihari/analyzers/crtsh.rb +4 -1
- data/lib/mihari/analyzers/dnstwister.rb +4 -1
- data/lib/mihari/analyzers/feed.rb +3 -0
- data/lib/mihari/analyzers/fofa.rb +65 -0
- data/lib/mihari/analyzers/greynoise.rb +4 -1
- data/lib/mihari/analyzers/hunterhow.rb +7 -2
- data/lib/mihari/analyzers/onyphe.rb +4 -1
- data/lib/mihari/analyzers/otx.rb +4 -1
- data/lib/mihari/analyzers/passivetotal.rb +5 -2
- data/lib/mihari/analyzers/pulsedive.rb +4 -1
- data/lib/mihari/analyzers/securitytrails.rb +5 -2
- data/lib/mihari/analyzers/shodan.rb +4 -1
- data/lib/mihari/analyzers/urlscan.rb +5 -2
- data/lib/mihari/analyzers/virustotal.rb +9 -6
- data/lib/mihari/analyzers/virustotal_intelligence.rb +4 -1
- data/lib/mihari/analyzers/zoomeye.rb +8 -5
- data/lib/mihari/cli/alert.rb +3 -0
- data/lib/mihari/cli/base.rb +3 -0
- data/lib/mihari/cli/database.rb +3 -0
- data/lib/mihari/cli/main.rb +3 -0
- data/lib/mihari/cli/rule.rb +3 -0
- data/lib/mihari/clients/base.rb +3 -0
- data/lib/mihari/clients/binaryedge.rb +5 -2
- data/lib/mihari/clients/censys.rb +7 -4
- data/lib/mihari/clients/circl.rb +3 -0
- data/lib/mihari/clients/crtsh.rb +5 -2
- data/lib/mihari/clients/dnstwister.rb +3 -0
- data/lib/mihari/clients/fofa.rb +83 -0
- data/lib/mihari/clients/greynoise.rb +5 -2
- data/lib/mihari/clients/hunterhow.rb +5 -2
- data/lib/mihari/clients/misp.rb +3 -0
- data/lib/mihari/clients/onyphe.rb +5 -2
- data/lib/mihari/clients/otx.rb +3 -0
- data/lib/mihari/clients/passivetotal.rb +7 -4
- data/lib/mihari/clients/publsedive.rb +4 -1
- data/lib/mihari/clients/securitytrails.rb +6 -3
- data/lib/mihari/clients/shodan.rb +5 -2
- data/lib/mihari/clients/the_hive.rb +3 -0
- data/lib/mihari/clients/urlscan.rb +7 -4
- data/lib/mihari/clients/virustotal.rb +5 -2
- data/lib/mihari/clients/zoomeye.rb +3 -0
- data/lib/mihari/commands/alert.rb +5 -14
- data/lib/mihari/commands/database.rb +3 -0
- data/lib/mihari/commands/rule.rb +11 -11
- data/lib/mihari/commands/search.rb +9 -6
- data/lib/mihari/commands/version.rb +3 -0
- data/lib/mihari/commands/web.rb +4 -1
- data/lib/mihari/config.rb +139 -150
- data/lib/mihari/constants.rb +1 -1
- data/lib/mihari/database.rb +6 -0
- data/lib/mihari/emitters/base.rb +16 -25
- data/lib/mihari/emitters/database.rb +10 -9
- data/lib/mihari/emitters/misp.rb +20 -41
- data/lib/mihari/emitters/slack.rb +16 -13
- data/lib/mihari/emitters/the_hive.rb +18 -46
- data/lib/mihari/emitters/webhook.rb +34 -23
- data/lib/mihari/enrichers/base.rb +16 -15
- data/lib/mihari/enrichers/google_public_dns.rb +6 -5
- data/lib/mihari/enrichers/ipinfo.rb +10 -8
- data/lib/mihari/enrichers/shodan.rb +4 -6
- data/lib/mihari/enrichers/whois.rb +13 -10
- data/lib/mihari/errors.rb +6 -0
- data/lib/mihari/feed/parser.rb +3 -0
- data/lib/mihari/feed/reader.rb +3 -0
- data/lib/mihari/http.rb +6 -0
- data/lib/mihari/mixins/autonomous_system.rb +3 -0
- data/lib/mihari/mixins/configurable.rb +3 -0
- data/lib/mihari/mixins/error_notification.rb +3 -0
- data/lib/mihari/mixins/falsepositive.rb +3 -0
- data/lib/mihari/mixins/refang.rb +3 -0
- data/lib/mihari/mixins/retriable.rb +6 -2
- data/lib/mihari/models/alert.rb +78 -73
- data/lib/mihari/models/artifact.rb +186 -178
- data/lib/mihari/models/autonomous_system.rb +25 -20
- data/lib/mihari/models/cpe.rb +24 -19
- data/lib/mihari/models/dns.rb +27 -22
- data/lib/mihari/models/geolocation.rb +25 -20
- data/lib/mihari/models/port.rb +24 -19
- data/lib/mihari/models/reverse_dns.rb +24 -19
- data/lib/mihari/models/rule.rb +71 -66
- data/lib/mihari/models/tag.rb +8 -3
- data/lib/mihari/models/tagging.rb +8 -3
- data/lib/mihari/models/whois.rb +20 -17
- data/lib/mihari/rule.rb +357 -0
- data/lib/mihari/schemas/alert.rb +3 -0
- data/lib/mihari/schemas/analyzer.rb +105 -87
- data/lib/mihari/schemas/emitter.rb +12 -5
- data/lib/mihari/schemas/enricher.rb +11 -4
- data/lib/mihari/schemas/macros.rb +4 -0
- data/lib/mihari/schemas/mixins.rb +20 -0
- data/lib/mihari/schemas/rule.rb +6 -10
- data/lib/mihari/service.rb +16 -0
- data/lib/mihari/services/alert_builder.rb +8 -5
- data/lib/mihari/services/alert_proxy.rb +16 -7
- data/lib/mihari/services/alert_runner.rb +10 -14
- data/lib/mihari/services/rule_builder.rb +10 -7
- data/lib/mihari/services/rule_runner.rb +11 -13
- data/lib/mihari/structs/binaryedge.rb +14 -29
- data/lib/mihari/structs/censys.rb +54 -133
- data/lib/mihari/structs/config.rb +20 -31
- data/lib/mihari/structs/filters.rb +38 -0
- data/lib/mihari/structs/fofa.rb +44 -0
- data/lib/mihari/structs/google_public_dns.rb +10 -28
- data/lib/mihari/structs/greynoise.rb +38 -89
- data/lib/mihari/structs/hunterhow.rb +27 -25
- data/lib/mihari/structs/ipinfo.rb +14 -35
- data/lib/mihari/structs/onyphe.rb +36 -81
- data/lib/mihari/structs/shodan.rb +53 -118
- data/lib/mihari/structs/urlscan.rb +27 -66
- data/lib/mihari/structs/virustotal_intelligence.rb +23 -59
- data/lib/mihari/type_checker.rb +4 -0
- data/lib/mihari/types.rb +3 -0
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/api.rb +15 -10
- data/lib/mihari/web/app.rb +59 -54
- data/lib/mihari/web/endpoints/alerts.rb +94 -89
- data/lib/mihari/web/endpoints/artifacts.rb +115 -110
- data/lib/mihari/web/endpoints/configs.rb +18 -13
- data/lib/mihari/web/endpoints/ip_addresses.rb +21 -16
- data/lib/mihari/web/endpoints/rules.rb +202 -204
- data/lib/mihari/web/endpoints/tags.rb +41 -36
- data/lib/mihari/web/middleware/connection_adapter.rb +16 -9
- data/lib/mihari/web/middleware/error_notification_adapter.rb +17 -10
- data/lib/mihari/web/public/assets/{index-9cc489e6.js → index-821134e2.js} +54 -54
- data/lib/mihari/web/public/assets/mode-yaml-24faa242.js +8 -0
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari.rb +30 -13
- data/mihari.gemspec +9 -3
- data/mkdocs.yml +3 -2
- data/requirements.txt +1 -1
- metadata +44 -26
- data/lib/mihari/analyzers/rule.rb +0 -232
- data/lib/mihari/services/rule_proxy.rb +0 -182
- data/lib/mihari/templates/rule.yml.erb +0 -5
- data/lib/mihari/web/public/assets/mode-yaml-a21faa53.js +0 -8
data/lib/mihari/emitters/misp.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
+
#
|
6
|
+
# MISP emitter
|
7
|
+
#
|
5
8
|
class MISP < Base
|
6
9
|
# @return [String, nil]
|
7
10
|
attr_reader :url
|
@@ -9,50 +12,39 @@ module Mihari
|
|
9
12
|
# @return [String, nil]
|
10
13
|
attr_reader :api_key
|
11
14
|
|
12
|
-
# @return [
|
13
|
-
attr_reader :artifacts
|
14
|
-
|
15
|
-
# @return [Mihari::Services::Rule]
|
15
|
+
# @return [Mihari::Rule]
|
16
16
|
attr_reader :rule
|
17
17
|
|
18
|
+
# @return [Array<Mihari::Models::Artifact>]
|
19
|
+
attr_accessor :artifacts
|
20
|
+
|
18
21
|
#
|
19
|
-
# @param [
|
20
|
-
# @param [Mihari::Services::Rule] rule
|
22
|
+
# @param [Mihari::Rule] rule
|
21
23
|
# @param [Hash, nil] options
|
22
|
-
# @param [Hash]
|
24
|
+
# @param [Hash, nil] params
|
23
25
|
#
|
24
|
-
def initialize(
|
25
|
-
super(
|
26
|
+
def initialize(rule:, options: nil, **params)
|
27
|
+
super(rule: rule, options: options)
|
26
28
|
|
27
29
|
@url = params[:url] || Mihari.config.misp_url
|
28
30
|
@api_key = params[:api_key] || Mihari.config.misp_api_key
|
31
|
+
|
32
|
+
@artifacts = []
|
29
33
|
end
|
30
34
|
|
35
|
+
#
|
31
36
|
# @return [Boolean]
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Mihari.logger.info("MISP API key is not set") unless api_key?
|
36
|
-
return false
|
37
|
-
end
|
38
|
-
|
39
|
-
unless ping?
|
40
|
-
Mihari.logger.info("MISP URL (#{url}) is not reachable")
|
41
|
-
return false
|
42
|
-
end
|
43
|
-
|
44
|
-
true
|
37
|
+
#
|
38
|
+
def configured?
|
39
|
+
api_key? && url?
|
45
40
|
end
|
46
41
|
|
47
42
|
#
|
48
43
|
# Create a MISP event
|
49
44
|
#
|
50
|
-
# @param [
|
51
|
-
# @param [Mihari::Services::Rule] rule
|
45
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
52
46
|
#
|
53
|
-
|
54
|
-
#
|
55
|
-
def emit
|
47
|
+
def call(artifacts)
|
56
48
|
return if artifacts.empty?
|
57
49
|
|
58
50
|
client.create_event({
|
@@ -77,7 +69,7 @@ module Mihari
|
|
77
69
|
#
|
78
70
|
# Build a MISP attribute
|
79
71
|
#
|
80
|
-
# @param [Mihari::Artifact] artifact
|
72
|
+
# @param [Mihari::Models::Artifact] artifact
|
81
73
|
#
|
82
74
|
# @return [Hash]
|
83
75
|
#
|
@@ -143,19 +135,6 @@ module Mihari
|
|
143
135
|
def api_key?
|
144
136
|
!api_key.nil? && !api_key.empty?
|
145
137
|
end
|
146
|
-
|
147
|
-
#
|
148
|
-
# Check whether a URL is reachable or not
|
149
|
-
#
|
150
|
-
# @return [Boolean]
|
151
|
-
#
|
152
|
-
def ping?
|
153
|
-
base_url = url.end_with?("/") ? url[0..-2] : url
|
154
|
-
login_url = "#{base_url}/users/login"
|
155
|
-
|
156
|
-
http = Net::Ping::HTTP.new(login_url)
|
157
|
-
http.ping?
|
158
|
-
end
|
159
138
|
end
|
160
139
|
end
|
161
140
|
end
|
@@ -131,18 +131,22 @@ module Mihari
|
|
131
131
|
# @return [String]
|
132
132
|
attr_reader :username
|
133
133
|
|
134
|
+
# @return [Array<Mihari::Models::Artifact>]
|
135
|
+
attr_accessor :artifacts
|
136
|
+
|
134
137
|
#
|
135
|
-
# @param [
|
136
|
-
# @param [Mihari::Services::Rule] rule
|
138
|
+
# @param [Mihari::Rule] rule
|
137
139
|
# @param [Hash, nil] options
|
138
|
-
# @param [Hash]
|
140
|
+
# @param [Hash, nil] params
|
139
141
|
#
|
140
|
-
def initialize(
|
141
|
-
super(
|
142
|
+
def initialize(rule:, options: nil, **params)
|
143
|
+
super(rule: rule, options: options)
|
142
144
|
|
143
145
|
@webhook_url = params[:webhook_url] || Mihari.config.slack_webhook_url
|
144
146
|
@channel = params[:channel] || Mihari.config.slack_channel || DEFAULT_CHANNEL
|
145
147
|
@username = DEFAULT_USERNAME
|
148
|
+
|
149
|
+
@artifacts = []
|
146
150
|
end
|
147
151
|
|
148
152
|
#
|
@@ -154,12 +158,10 @@ module Mihari
|
|
154
158
|
!webhook_url.nil?
|
155
159
|
end
|
156
160
|
|
157
|
-
#
|
158
|
-
# Check webhook URL is set. Alias of #webhook_url?
|
159
161
|
#
|
160
162
|
# @return [Boolean]
|
161
163
|
#
|
162
|
-
def
|
164
|
+
def configured?
|
163
165
|
webhook_url?
|
164
166
|
end
|
165
167
|
|
@@ -211,19 +213,20 @@ module Mihari
|
|
211
213
|
].join("\n")
|
212
214
|
end
|
213
215
|
|
214
|
-
|
216
|
+
#
|
217
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
218
|
+
#
|
219
|
+
def call(artifacts)
|
215
220
|
return if artifacts.empty?
|
216
221
|
|
222
|
+
@artifacts = artifacts
|
223
|
+
|
217
224
|
notifier.post(text: text, attachments: attachments, mrkdwn: true)
|
218
225
|
end
|
219
226
|
|
220
227
|
def configuration_keys
|
221
228
|
%w[slack_webhook_url slack_channel]
|
222
229
|
end
|
223
|
-
|
224
|
-
def configured?
|
225
|
-
valid?
|
226
|
-
end
|
227
230
|
end
|
228
231
|
end
|
229
232
|
end
|
@@ -12,45 +12,42 @@ module Mihari
|
|
12
12
|
# @return [String, nil]
|
13
13
|
attr_reader :api_version
|
14
14
|
|
15
|
+
# @return [Array<Mihari::Models::Artifact>]
|
16
|
+
attr_accessor :artifacts
|
17
|
+
|
15
18
|
#
|
16
|
-
# @param [
|
17
|
-
# @param [Mihari::Services::Rule] rule
|
19
|
+
# @param [Mihari::Rule] rule
|
18
20
|
# @param [Hash, nil] options
|
19
|
-
# @param [Hash]
|
21
|
+
# @param [Hash] params
|
20
22
|
#
|
21
|
-
def initialize(
|
22
|
-
super(
|
23
|
+
def initialize(rule:, options: nil, **params)
|
24
|
+
super(rule: rule, options: options)
|
23
25
|
|
24
26
|
@url = params[:url] || Mihari.config.thehive_url
|
25
27
|
@api_key = params[:api_key] || Mihari.config.thehive_api_key
|
26
28
|
@api_version = params[:api_version] || Mihari.config.thehive_api_version
|
29
|
+
|
30
|
+
@artifacts = []
|
27
31
|
end
|
28
32
|
|
33
|
+
#
|
29
34
|
# @return [Boolean]
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
Mihari.logger.info("TheHive API key is not set") unless api_key?
|
34
|
-
return false
|
35
|
-
end
|
36
|
-
|
37
|
-
unless ping?
|
38
|
-
Mihari.logger.info("TheHive URL (#{url}) is not reachable")
|
39
|
-
return false
|
40
|
-
end
|
41
|
-
|
42
|
-
true
|
35
|
+
#
|
36
|
+
def configured?
|
37
|
+
api_key? && url?
|
43
38
|
end
|
44
39
|
|
45
40
|
#
|
46
41
|
# Create a Hive alert
|
47
42
|
#
|
48
|
-
# @
|
43
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
49
44
|
#
|
50
|
-
def
|
45
|
+
def call(artifacts)
|
51
46
|
return if artifacts.empty?
|
52
47
|
|
53
|
-
|
48
|
+
@artifacts = artifacts
|
49
|
+
|
50
|
+
client.alert payload
|
54
51
|
end
|
55
52
|
|
56
53
|
#
|
@@ -146,31 +143,6 @@ module Mihari
|
|
146
143
|
source_ref: "1"
|
147
144
|
}
|
148
145
|
end
|
149
|
-
|
150
|
-
#
|
151
|
-
# Check whether a URL is reachable or not
|
152
|
-
#
|
153
|
-
# @return [Boolean]
|
154
|
-
#
|
155
|
-
def ping?
|
156
|
-
base_url = url.end_with?("/") ? url[0..-2] : url
|
157
|
-
|
158
|
-
if normalized_api_version.nil?
|
159
|
-
# for v4
|
160
|
-
base_url = url.end_with?("/") ? url[0..-2] : url
|
161
|
-
public_url = "#{base_url}/index.html"
|
162
|
-
else
|
163
|
-
# for v5
|
164
|
-
public_url = "#{base_url}/api/v1/status/public"
|
165
|
-
end
|
166
|
-
|
167
|
-
http = Net::Ping::HTTP.new(public_url)
|
168
|
-
|
169
|
-
# use GET for v5
|
170
|
-
http.get_request = true if normalized_api_version
|
171
|
-
|
172
|
-
http.ping?
|
173
|
-
end
|
174
146
|
end
|
175
147
|
end
|
176
148
|
end
|
@@ -57,23 +57,42 @@ module Mihari
|
|
57
57
|
# @return [String, nil]
|
58
58
|
attr_reader :template
|
59
59
|
|
60
|
+
# @return [Array<Mihari::Models::Artifact>]
|
61
|
+
attr_accessor :artifacts
|
62
|
+
|
60
63
|
#
|
61
|
-
# @param [
|
62
|
-
# @param [
|
63
|
-
# @param [Hash]
|
64
|
+
# @param [Mihari::Rule] rule
|
65
|
+
# @param [Hash, nil] options
|
66
|
+
# @param [Hash, nil] params
|
64
67
|
#
|
65
|
-
def initialize(
|
66
|
-
super(
|
68
|
+
def initialize(rule:, options: nil, **params)
|
69
|
+
super(rule: rule, options: options)
|
67
70
|
|
68
71
|
@url = Addressable::URI.parse(params[:url])
|
69
72
|
@headers = params[:headers] || {}
|
70
73
|
@method = params[:method] || "POST"
|
71
74
|
@template = params[:template]
|
75
|
+
|
76
|
+
@artifacts = []
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# @return [Boolean]
|
81
|
+
#
|
82
|
+
def configured?
|
83
|
+
return false if url.nil?
|
84
|
+
|
85
|
+
%w[http https].include? url.scheme.downcase
|
72
86
|
end
|
73
87
|
|
74
|
-
|
88
|
+
#
|
89
|
+
# @param [Array<Mihari::Models::Artifact>] artifacts
|
90
|
+
#
|
91
|
+
def call(artifacts)
|
75
92
|
return if artifacts.empty?
|
76
93
|
|
94
|
+
@artifacts = artifacts
|
95
|
+
|
77
96
|
# returns body to prevent Parallel issue (Parallel fails to handle HTTP:Response object)
|
78
97
|
case method
|
79
98
|
when "GET"
|
@@ -83,12 +102,6 @@ module Mihari
|
|
83
102
|
end
|
84
103
|
end
|
85
104
|
|
86
|
-
def valid?
|
87
|
-
return false if url.nil?
|
88
|
-
|
89
|
-
%w[http https].include? url.scheme.downcase
|
90
|
-
end
|
91
|
-
|
92
105
|
private
|
93
106
|
|
94
107
|
def http
|
@@ -101,17 +114,15 @@ module Mihari
|
|
101
114
|
# @return [String]
|
102
115
|
#
|
103
116
|
def rendered_template
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
out << payload_template.result
|
114
|
-
end.first
|
117
|
+
options = {}
|
118
|
+
options[:template] = File.read(template) unless template.nil?
|
119
|
+
|
120
|
+
payload_template = PayloadTemplate.new(
|
121
|
+
artifacts: artifacts,
|
122
|
+
rule: rule,
|
123
|
+
options: options
|
124
|
+
)
|
125
|
+
payload_template.result
|
115
126
|
end
|
116
127
|
|
117
128
|
#
|
@@ -2,33 +2,34 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Enrichers
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
include Dry::Monads[:result, :try]
|
10
|
-
|
5
|
+
#
|
6
|
+
# Base class for enrichers
|
7
|
+
#
|
8
|
+
class Base < Actor
|
11
9
|
def initialize(options: nil)
|
12
10
|
super(options: options)
|
13
11
|
end
|
14
12
|
|
15
|
-
|
13
|
+
#
|
14
|
+
# @param [String] value
|
15
|
+
#
|
16
|
+
def call(value)
|
17
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
|
22
|
+
#
|
23
|
+
def result(value)
|
16
24
|
Try[StandardError] do
|
17
25
|
retry_on_error(
|
18
26
|
times: retry_times,
|
19
27
|
interval: retry_interval,
|
20
28
|
exponential_backoff: retry_exponential_backoff
|
21
|
-
) {
|
29
|
+
) { call value }
|
22
30
|
end.to_result
|
23
31
|
end
|
24
32
|
|
25
|
-
#
|
26
|
-
# @param [String] value
|
27
|
-
#
|
28
|
-
def query(value)
|
29
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
30
|
-
end
|
31
|
-
|
32
33
|
class << self
|
33
34
|
def inherited(child)
|
34
35
|
super
|
@@ -1,18 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "net/https"
|
4
|
-
|
5
3
|
module Mihari
|
6
4
|
module Enrichers
|
5
|
+
#
|
6
|
+
# Google Public DNS enricher
|
7
|
+
#
|
7
8
|
class GooglePublicDNS < Base
|
8
9
|
#
|
9
10
|
# Query Google Public DNS
|
10
11
|
#
|
11
12
|
# @param [String] name
|
12
13
|
#
|
13
|
-
# @return [Array<Mihari::Structs::
|
14
|
+
# @return [Array<Mihari::Structs::GooglePublicDNS::Response>]
|
14
15
|
#
|
15
|
-
def
|
16
|
+
def call(name)
|
16
17
|
%w[A AAAA CNAME TXT NS].filter_map do |resource_type|
|
17
18
|
query_by_type(name, resource_type)
|
18
19
|
end
|
@@ -24,7 +25,7 @@ module Mihari
|
|
24
25
|
# @param [String] name
|
25
26
|
# @param [String] resource_type
|
26
27
|
#
|
27
|
-
# @return [Mihari::Structs::
|
28
|
+
# @return [Mihari::Structs::GooglePublicDNS::Response, nil]
|
28
29
|
#
|
29
30
|
def query_by_type(name, resource_type)
|
30
31
|
url = "https://dns.google/resolve"
|
@@ -1,23 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "net/https"
|
4
|
-
|
5
3
|
module Mihari
|
6
4
|
module Enrichers
|
5
|
+
#
|
6
|
+
# IPInfo enricher
|
7
|
+
#
|
7
8
|
class IPInfo < Base
|
8
|
-
include Memist::Memoizable
|
9
|
-
|
10
9
|
# @return [String, nil]
|
11
10
|
attr_reader :api_key
|
12
11
|
|
12
|
+
#
|
13
|
+
# @param [Hash, nil] options
|
14
|
+
# @param [String, nil] api_key
|
15
|
+
#
|
13
16
|
def initialize(options: nil, api_key: nil)
|
14
17
|
@api_key = api_key || Mihari.config.ipinfo_api_key
|
15
18
|
|
16
19
|
super(options: options)
|
17
20
|
end
|
18
21
|
|
19
|
-
private
|
20
|
-
|
21
22
|
def configuration_keys
|
22
23
|
%w[ipinfo_api_key]
|
23
24
|
end
|
@@ -29,14 +30,15 @@ module Mihari
|
|
29
30
|
#
|
30
31
|
# @return [Mihari::Structs::IPInfo::Response, nil]
|
31
32
|
#
|
32
|
-
def
|
33
|
+
def call(ip)
|
33
34
|
url = "https://ipinfo.io/#{ip}/json"
|
34
35
|
res = http.get(url)
|
35
36
|
data = JSON.parse(res.body.to_s)
|
36
37
|
|
37
38
|
Structs::IPInfo::Response.from_dynamic! data
|
38
39
|
end
|
39
|
-
|
40
|
+
|
41
|
+
private
|
40
42
|
|
41
43
|
def headers
|
42
44
|
authorization = api_key.nil? ? nil : "Bearer #{api_key}"
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "net/https"
|
4
|
-
|
5
3
|
module Mihari
|
6
4
|
module Enrichers
|
5
|
+
#
|
6
|
+
# Shodan enricher
|
7
|
+
#
|
7
8
|
class Shodan < Base
|
8
|
-
include Memist::Memoizable
|
9
|
-
|
10
9
|
#
|
11
10
|
# Query Shodan Internet DB
|
12
11
|
#
|
@@ -14,14 +13,13 @@ module Mihari
|
|
14
13
|
#
|
15
14
|
# @return [Mihari::Structs::Shodan::InternetDBResponse, nil]
|
16
15
|
#
|
17
|
-
def
|
16
|
+
def call(ip)
|
18
17
|
url = "https://internetdb.shodan.io/#{ip}"
|
19
18
|
res = http.get(url)
|
20
19
|
data = JSON.parse(res.body.to_s)
|
21
20
|
|
22
21
|
Structs::Shodan::InternetDBResponse.from_dynamic! data
|
23
22
|
end
|
24
|
-
memoize :query
|
25
23
|
|
26
24
|
private
|
27
25
|
|
@@ -4,6 +4,9 @@ require "whois-parser"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Enrichers
|
7
|
+
#
|
8
|
+
# Whois enricher
|
9
|
+
#
|
7
10
|
class Whois < Base
|
8
11
|
# @return [Hash]
|
9
12
|
attr_accessor :memo
|
@@ -20,11 +23,11 @@ module Mihari
|
|
20
23
|
#
|
21
24
|
# Query IAIA Whois API
|
22
25
|
#
|
23
|
-
# @param [String]
|
26
|
+
# @param [String] domain
|
24
27
|
#
|
25
|
-
# @return [Mihari::WhoisRecord, nil]
|
28
|
+
# @return [Mihari::Models::WhoisRecord, nil]
|
26
29
|
#
|
27
|
-
def
|
30
|
+
def call(domain)
|
28
31
|
domain = PublicSuffix.domain(domain)
|
29
32
|
|
30
33
|
# check memo
|
@@ -34,7 +37,7 @@ module Mihari
|
|
34
37
|
parser = record.parser
|
35
38
|
return nil if parser.available?
|
36
39
|
|
37
|
-
whois_record = WhoisRecord.new(
|
40
|
+
whois_record = Models::WhoisRecord.new(
|
38
41
|
domain: domain,
|
39
42
|
created_on: get_created_on(parser),
|
40
43
|
updated_on: get_updated_on(parser),
|
@@ -71,7 +74,7 @@ module Mihari
|
|
71
74
|
#
|
72
75
|
# Get created_on
|
73
76
|
#
|
74
|
-
# @param [::Whois::Parser
|
77
|
+
# @param [::Whois::Parser] parser
|
75
78
|
#
|
76
79
|
# @return [Date, nil]
|
77
80
|
#
|
@@ -84,7 +87,7 @@ module Mihari
|
|
84
87
|
#
|
85
88
|
# Get updated_on
|
86
89
|
#
|
87
|
-
# @param [::Whois::Parser
|
90
|
+
# @param [::Whois::Parser] parser
|
88
91
|
#
|
89
92
|
# @return [Date, nil]
|
90
93
|
#
|
@@ -97,7 +100,7 @@ module Mihari
|
|
97
100
|
#
|
98
101
|
# Get expires_on
|
99
102
|
#
|
100
|
-
# @param [::Whois::Parser
|
103
|
+
# @param [::Whois::Parser] parser
|
101
104
|
#
|
102
105
|
# @return [Date, nil]
|
103
106
|
#
|
@@ -110,7 +113,7 @@ module Mihari
|
|
110
113
|
#
|
111
114
|
# Get registrar
|
112
115
|
#
|
113
|
-
# @param [::Whois::Parser
|
116
|
+
# @param [::Whois::Parser] parser
|
114
117
|
#
|
115
118
|
# @return [Hash, nil]
|
116
119
|
#
|
@@ -123,9 +126,9 @@ module Mihari
|
|
123
126
|
#
|
124
127
|
# Get contacts
|
125
128
|
#
|
126
|
-
# @param [::Whois::Parser
|
129
|
+
# @param [::Whois::Parser] parser
|
127
130
|
#
|
128
|
-
# @return [Array
|
131
|
+
# @return [Array<Hash>, nil]
|
129
132
|
#
|
130
133
|
def get_contacts(parser)
|
131
134
|
parser.contacts.map(&:to_h)
|
data/lib/mihari/errors.rb
CHANGED
@@ -20,6 +20,9 @@ module Mihari
|
|
20
20
|
|
21
21
|
class TimeoutError < HTTPError; end
|
22
22
|
|
23
|
+
#
|
24
|
+
# HTTP status code error
|
25
|
+
#
|
23
26
|
class StatusCodeError < HTTPError
|
24
27
|
# @return [Integer]
|
25
28
|
attr_reader :status_code
|
@@ -40,6 +43,9 @@ module Mihari
|
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
46
|
+
#
|
47
|
+
# (dry-schema) Schema validation error
|
48
|
+
#
|
43
49
|
class ValidationError < Error
|
44
50
|
attr_reader :errors
|
45
51
|
|
data/lib/mihari/feed/parser.rb
CHANGED
data/lib/mihari/feed/reader.rb
CHANGED
data/lib/mihari/http.rb
CHANGED
@@ -4,6 +4,9 @@ require "http"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module HTTP
|
7
|
+
#
|
8
|
+
# Better error handling feature
|
9
|
+
#
|
7
10
|
class BetterError < ::HTTP::Feature
|
8
11
|
def wrap_response(response)
|
9
12
|
unless response.status.success?
|
@@ -24,6 +27,9 @@ module Mihari
|
|
24
27
|
::HTTP::Options.register_feature(:better_error, self)
|
25
28
|
end
|
26
29
|
|
30
|
+
#
|
31
|
+
# HTTP client factory
|
32
|
+
#
|
27
33
|
class Factory
|
28
34
|
class << self
|
29
35
|
#
|