mihari 6.2.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -10
- data/.rubocop.yml +2 -0
- data/Dockerfile +13 -0
- data/config.ru +5 -3
- data/docker-compose.yml +62 -0
- data/exe/mihari +2 -1
- data/lefthook.yml +8 -0
- data/lib/mihari/actor.rb +4 -4
- data/lib/mihari/analyzers/base.rb +16 -0
- data/lib/mihari/analyzers/binaryedge.rb +4 -2
- data/lib/mihari/analyzers/censys.rb +7 -5
- data/lib/mihari/analyzers/circl.rb +5 -3
- data/lib/mihari/analyzers/crtsh.rb +4 -1
- data/lib/mihari/analyzers/dnstwister.rb +1 -1
- data/lib/mihari/analyzers/feed.rb +12 -20
- data/lib/mihari/analyzers/fofa.rb +6 -8
- data/lib/mihari/analyzers/greynoise.rb +4 -2
- data/lib/mihari/analyzers/hunterhow.rb +4 -2
- data/lib/mihari/analyzers/onyphe.rb +4 -2
- data/lib/mihari/analyzers/otx.rb +5 -3
- data/lib/mihari/analyzers/passivetotal.rb +29 -12
- data/lib/mihari/analyzers/pulsedive.rb +5 -3
- data/lib/mihari/analyzers/securitytrails.rb +32 -8
- data/lib/mihari/analyzers/shodan.rb +4 -2
- data/lib/mihari/analyzers/urlscan.rb +4 -2
- data/lib/mihari/analyzers/virustotal.rb +5 -5
- data/lib/mihari/analyzers/virustotal_intelligence.rb +4 -2
- data/lib/mihari/analyzers/zoomeye.rb +4 -2
- data/lib/mihari/cli/{main.rb → application.rb} +17 -5
- data/lib/mihari/cli/artifact.rb +14 -0
- data/lib/mihari/cli/config.rb +14 -0
- data/lib/mihari/cli/rule.rb +1 -0
- data/lib/mihari/cli/tag.rb +14 -0
- data/lib/mihari/clients/base.rb +2 -2
- data/lib/mihari/clients/binaryedge.rb +2 -2
- data/lib/mihari/clients/crtsh.rb +2 -9
- data/lib/mihari/clients/fofa.rb +1 -1
- data/lib/mihari/clients/hunterhow.rb +1 -1
- data/lib/mihari/clients/mmdb.rb +28 -0
- data/lib/mihari/clients/passivetotal.rb +7 -20
- data/lib/mihari/clients/securitytrails.rb +19 -43
- data/lib/mihari/clients/shodan_internet_db.rb +28 -0
- data/lib/mihari/clients/the_hive.rb +7 -5
- data/lib/mihari/commands/alert.rb +53 -11
- data/lib/mihari/commands/artifact.rb +66 -0
- data/lib/mihari/commands/config.rb +23 -0
- data/lib/mihari/commands/database.rb +1 -1
- data/lib/mihari/commands/rule.rb +40 -27
- data/lib/mihari/commands/search.rb +10 -11
- data/lib/mihari/commands/sidekiq.rb +31 -0
- data/lib/mihari/commands/tag.rb +46 -0
- data/lib/mihari/commands/web.rb +6 -7
- data/lib/mihari/{mixins/autonomous_system.rb → concerns/autonomous_system_normalizable.rb} +5 -3
- data/lib/mihari/concerns/configurable.rb +72 -0
- data/lib/mihari/concerns/database_connectable.rb +16 -0
- data/lib/mihari/{mixins/unwrap_error.rb → concerns/error_unwrappable.rb} +5 -3
- data/lib/mihari/{mixins/falsepositive.rb → concerns/falsepositive_validatable.rb} +5 -3
- data/lib/mihari/{mixins/refang.rb → concerns/refangable.rb} +5 -3
- data/lib/mihari/{mixins → concerns}/retriable.rb +4 -2
- data/lib/mihari/config.rb +13 -12
- data/lib/mihari/database.rb +30 -42
- data/lib/mihari/emitters/database.rb +5 -6
- data/lib/mihari/emitters/misp.rb +4 -11
- data/lib/mihari/emitters/slack.rb +7 -5
- data/lib/mihari/emitters/the_hive.rb +8 -58
- data/lib/mihari/emitters/webhook.rb +6 -6
- data/lib/mihari/enrichers/google_public_dns.rb +1 -1
- data/lib/mihari/enrichers/mmdb.rb +28 -0
- data/lib/mihari/enrichers/shodan.rb +3 -5
- data/lib/mihari/enrichers/whois.rb +3 -3
- data/lib/mihari/entities/alert.rb +3 -10
- data/lib/mihari/entities/artifact.rb +9 -9
- data/lib/mihari/entities/config.rb +2 -2
- data/lib/mihari/entities/cpe.rb +1 -0
- data/lib/mihari/entities/dns.rb +1 -0
- data/lib/mihari/entities/geolocation.rb +1 -0
- data/lib/mihari/entities/ip_address.rb +1 -3
- data/lib/mihari/entities/messages.rb +17 -0
- data/lib/mihari/entities/pagination.rb +11 -0
- data/lib/mihari/entities/port.rb +1 -0
- data/lib/mihari/entities/reverse_dns.rb +1 -0
- data/lib/mihari/entities/rule.rb +2 -20
- data/lib/mihari/entities/tag.rb +2 -2
- data/lib/mihari/entities/whois.rb +1 -0
- data/lib/mihari/errors.rb +2 -4
- data/lib/mihari/http.rb +4 -0
- data/lib/mihari/models/alert.rb +21 -76
- data/lib/mihari/models/artifact.rb +51 -31
- data/lib/mihari/models/autonomous_system.rb +5 -13
- data/lib/mihari/models/concerns/searchable.rb +50 -0
- data/lib/mihari/models/cpe.rb +3 -10
- data/lib/mihari/models/dns.rb +2 -6
- data/lib/mihari/models/geolocation.rb +7 -12
- data/lib/mihari/models/port.rb +3 -10
- data/lib/mihari/models/reverse_dns.rb +3 -8
- data/lib/mihari/models/rule.rb +16 -60
- data/lib/mihari/models/tag.rb +17 -1
- data/lib/mihari/models/tagging.rb +1 -1
- data/lib/mihari/models/whois.rb +1 -4
- data/lib/mihari/rule.rb +35 -24
- data/lib/mihari/schemas/alert.rb +1 -0
- data/lib/mihari/schemas/analyzer.rb +2 -2
- data/lib/mihari/schemas/concerns/orrable.rb +24 -0
- data/lib/mihari/schemas/emitter.rb +1 -2
- data/lib/mihari/schemas/enricher.rb +3 -4
- data/lib/mihari/schemas/macros.rb +1 -1
- data/lib/mihari/schemas/options.rb +0 -2
- data/lib/mihari/schemas/rule.rb +1 -2
- data/lib/mihari/services/{rule_builder.rb → builders.rb} +1 -6
- data/lib/mihari/services/creators.rb +22 -0
- data/lib/mihari/services/destroyers.rb +41 -0
- data/lib/mihari/services/enrichers.rb +25 -0
- data/lib/mihari/services/feed.rb +107 -0
- data/lib/mihari/services/getters.rb +58 -0
- data/lib/mihari/services/initializers.rb +22 -0
- data/lib/mihari/services/{alert_builder.rb → proxies.rb} +10 -40
- data/lib/mihari/services/searchers.rb +91 -0
- data/lib/mihari/sidekiq/application.rb +13 -0
- data/lib/mihari/sidekiq/jobs.rb +36 -0
- data/lib/mihari/structs/censys.rb +1 -1
- data/lib/mihari/structs/config.rb +10 -10
- data/lib/mihari/structs/filters.rb +12 -86
- data/lib/mihari/structs/google_public_dns.rb +1 -1
- data/lib/mihari/structs/greynoise.rb +1 -1
- data/lib/mihari/structs/mmdb.rb +115 -0
- data/lib/mihari/structs/onyphe.rb +1 -1
- data/lib/mihari/structs/shodan.rb +2 -2
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/{app.rb → application.rb} +28 -15
- data/lib/mihari/web/endpoints/alerts.rb +34 -81
- data/lib/mihari/web/endpoints/artifacts.rb +43 -63
- data/lib/mihari/web/endpoints/configs.rb +3 -5
- data/lib/mihari/web/endpoints/ip_addresses.rb +14 -15
- data/lib/mihari/web/endpoints/rules.rb +58 -137
- data/lib/mihari/web/endpoints/tags.rb +21 -17
- data/lib/mihari/web/middleware/capture_exceptions.rb +25 -0
- data/lib/mihari/web/middleware/{connection_adapter.rb → connection.rb} +4 -2
- data/lib/mihari/web/public/assets/index-cQUcyII5.js +1766 -0
- data/lib/mihari/web/public/assets/index-dVaNxqTC.css +1 -0
- data/lib/mihari/web/public/index.html +2 -3
- data/lib/mihari/web/public/redoc-static.html +385 -381
- data/lib/mihari.rb +56 -28
- data/mihari.gemspec +16 -8
- data/mkdocs.yml +5 -2
- data/requirements.txt +1 -1
- metadata +173 -42
- data/lib/mihari/commands/mixins.rb +0 -11
- data/lib/mihari/enrichers/ipinfo.rb +0 -52
- data/lib/mihari/entities/message.rb +0 -9
- data/lib/mihari/feed/parser.rb +0 -38
- data/lib/mihari/feed/reader.rb +0 -111
- data/lib/mihari/mixins/configurable.rb +0 -68
- data/lib/mihari/schemas/mixins.rb +0 -20
- data/lib/mihari/services/alert_runner.rb +0 -20
- data/lib/mihari/structs/ipinfo.rb +0 -53
- data/lib/mihari/web/middleware/error_notification_adapter.rb +0 -35
- data/lib/mihari/web/public/assets/index-1d77cd61.js +0 -1756
- data/lib/mihari/web/public/assets/index-4c8509ee.css +0 -1
- /data/lib/mihari/web/public/assets/{mode-yaml-24faa242.js → mode-yaml-BC4MIiYj.js} +0 -0
@@ -7,92 +7,22 @@ module Mihari
|
|
7
7
|
# Alert API endpoint
|
8
8
|
#
|
9
9
|
class Alerts < Grape::API
|
10
|
-
class AlertSearcher < Mihari::Service
|
11
|
-
class ResultValue
|
12
|
-
# @return [Array<Mihari::Models::Alert>]
|
13
|
-
attr_reader :alerts
|
14
|
-
|
15
|
-
# @return [Integer]
|
16
|
-
attr_reader :total
|
17
|
-
|
18
|
-
# @return [Mihari::Structs::Filters::Alert::SearchFilterWithPagination]
|
19
|
-
attr_reader :filter
|
20
|
-
|
21
|
-
#
|
22
|
-
# @param [Array<Mihari::Models::Alert>] alerts
|
23
|
-
# @param [Integer] total
|
24
|
-
# @param [Mihari::Structs::Filters::Alert::SearchFilterWithPagination] filter
|
25
|
-
#
|
26
|
-
def initialize(alerts:, total:, filter:)
|
27
|
-
@alerts = alerts
|
28
|
-
@total = total
|
29
|
-
@filter = filter
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
#
|
34
|
-
# @param [Hash] params
|
35
|
-
#
|
36
|
-
# @return [ResultValue]
|
37
|
-
#
|
38
|
-
def call(params)
|
39
|
-
filter = params.to_h.to_snake_keys
|
40
|
-
|
41
|
-
# normalize keys
|
42
|
-
filter["artifact_data"] = filter["artifact"]
|
43
|
-
filter["tag_name"] = filter["tag"]
|
44
|
-
# symbolize hash keys
|
45
|
-
filter = filter.to_h.symbolize_keys
|
46
|
-
|
47
|
-
search_filter_with_pagination = Structs::Filters::Alert::SearchFilterWithPagination.new(**filter)
|
48
|
-
alerts = Mihari::Models::Alert.search(search_filter_with_pagination)
|
49
|
-
total = Mihari::Models::Alert.count(search_filter_with_pagination.without_pagination)
|
50
|
-
|
51
|
-
ResultValue.new(alerts: alerts, total: total, filter: filter)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
class AlertCreator < Service
|
56
|
-
#
|
57
|
-
# @param [Hash] params
|
58
|
-
#
|
59
|
-
# @return [Mihari::Models::Alert]
|
60
|
-
#
|
61
|
-
def call(params)
|
62
|
-
proxy = Services::AlertProxy.new(**params.to_snake_keys)
|
63
|
-
Services::AlertRunner.call proxy
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
class AlertDestroyer < Service
|
68
|
-
#
|
69
|
-
# @param [String] id
|
70
|
-
#
|
71
|
-
def call(id)
|
72
|
-
Mihari::Models::Alert.find(id).destroy
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
10
|
namespace :alerts do
|
77
|
-
desc "
|
11
|
+
desc "List/search alerts", {
|
78
12
|
is_array: true,
|
79
13
|
success: Entities::AlertsWithPagination,
|
80
|
-
summary: "
|
14
|
+
summary: "List/search alerts"
|
81
15
|
}
|
82
16
|
params do
|
17
|
+
optional :q, type: String, default: ""
|
83
18
|
optional :page, type: Integer, default: 1
|
84
19
|
optional :limit, type: Integer, default: 10
|
85
|
-
optional :artifact, type: String
|
86
|
-
optional :rule_id, type: String
|
87
|
-
optional :tag, type: String
|
88
|
-
optional :fromAt, type: DateTime
|
89
|
-
optional :toAt, type: DateTime
|
90
20
|
end
|
91
21
|
get "/" do
|
92
|
-
value = AlertSearcher.call(params.to_h)
|
22
|
+
value = Services::AlertSearcher.call(params.to_h)
|
93
23
|
present(
|
94
24
|
{
|
95
|
-
|
25
|
+
results: value.results,
|
96
26
|
total: value.total,
|
97
27
|
current_page: value.filter[:page].to_i,
|
98
28
|
page_size: value.filter[:limit].to_i
|
@@ -101,9 +31,29 @@ module Mihari
|
|
101
31
|
)
|
102
32
|
end
|
103
33
|
|
34
|
+
desc "Get an alert", {
|
35
|
+
success: Entities::Alert,
|
36
|
+
failure: [{ code: 404, model: Entities::ErrorMessage }],
|
37
|
+
summary: "Get an alert"
|
38
|
+
}
|
39
|
+
params do
|
40
|
+
requires :id, type: Integer
|
41
|
+
end
|
42
|
+
get "/:id" do
|
43
|
+
id = params[:id].to_i
|
44
|
+
result = Services::AlertGetter.result(id)
|
45
|
+
return present(result.value!, with: Entities::Alert) if result.success?
|
46
|
+
|
47
|
+
case result.failure
|
48
|
+
when ActiveRecord::RecordNotFound
|
49
|
+
error!({ message: "ID:#{id} not found" }, 404)
|
50
|
+
end
|
51
|
+
raise result.failure
|
52
|
+
end
|
53
|
+
|
104
54
|
desc "Delete an alert", {
|
105
55
|
success: { code: 204, model: Entities::Message },
|
106
|
-
failure: [{ code: 404, model: Entities::
|
56
|
+
failure: [{ code: 404, model: Entities::ErrorMessage }],
|
107
57
|
summary: "Delete an alert"
|
108
58
|
}
|
109
59
|
params do
|
@@ -113,34 +63,37 @@ module Mihari
|
|
113
63
|
status 204
|
114
64
|
|
115
65
|
id = params["id"].to_i
|
116
|
-
result = AlertDestroyer.result(id)
|
66
|
+
result = Services::AlertDestroyer.result(id)
|
117
67
|
return present({ message: "" }, with: Entities::Message) if result.success?
|
118
68
|
|
119
69
|
case result.failure
|
120
70
|
when ActiveRecord::RecordNotFound
|
121
|
-
error!({ message: "ID:#{id}
|
71
|
+
error!({ message: "ID:#{id} not found" }, 404)
|
122
72
|
end
|
123
73
|
raise result.failure
|
124
74
|
end
|
125
75
|
|
126
76
|
desc "Create an alert", {
|
127
77
|
success: { code: 201, model: Entities::Alert },
|
128
|
-
failure: [
|
78
|
+
failure: [
|
79
|
+
{ code: 404, model: Entities::ErrorMessage }
|
80
|
+
],
|
129
81
|
summary: "Create an alert"
|
130
82
|
}
|
131
83
|
params do
|
132
84
|
requires :ruleId, type: String, documentation: { param_type: "body" }
|
133
85
|
requires :artifacts, type: Array, documentation: { type: String, is_array: true, param_type: "body" }
|
86
|
+
optional :source, type: String, documentation: { param_type: "body" }
|
134
87
|
end
|
135
88
|
post "/" do
|
136
89
|
status 201
|
137
90
|
|
138
|
-
result = AlertCreator.result(params)
|
91
|
+
result = Services::AlertCreator.result(params)
|
139
92
|
return present(result.value!, with: Entities::Alert) if result.success?
|
140
93
|
|
141
94
|
case result.failure
|
142
95
|
when ActiveRecord::RecordNotFound
|
143
|
-
error!({ message: "Rule:#{params["ruleId"]}
|
96
|
+
error!({ message: "Rule:#{params["ruleId"]} not found" }, 404)
|
144
97
|
end
|
145
98
|
raise result.failure
|
146
99
|
end
|
@@ -7,64 +7,33 @@ module Mihari
|
|
7
7
|
# Artifact API endpoint
|
8
8
|
#
|
9
9
|
class Artifacts < Grape::API
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
:whois_record,
|
21
|
-
:dns_records,
|
22
|
-
:reverse_dns_names
|
23
|
-
).find(id)
|
24
|
-
# TODO: improve queries
|
25
|
-
alert_ids = Mihari::Models::Artifact.where(data: artifact.data).pluck(:alert_id)
|
26
|
-
tag_ids = Mihari::Models::Tagging.where(alert_id: alert_ids).pluck(:tag_id)
|
27
|
-
tags = Mihari::Models::Tag.where(id: tag_ids)
|
28
|
-
|
29
|
-
artifact.tags = tags
|
30
|
-
|
31
|
-
artifact
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
class ArtifactEnricher < Service
|
36
|
-
#
|
37
|
-
# @param [String] id
|
38
|
-
#
|
39
|
-
def call(id)
|
40
|
-
artifact = Mihari::Models::Artifact.includes(
|
41
|
-
:autonomous_system,
|
42
|
-
:geolocation,
|
43
|
-
:whois_record,
|
44
|
-
:dns_records,
|
45
|
-
:reverse_dns_names,
|
46
|
-
:cpes,
|
47
|
-
:ports
|
48
|
-
).find(id)
|
49
|
-
|
50
|
-
artifact.enrich_all
|
51
|
-
artifact.save
|
10
|
+
namespace :artifacts do
|
11
|
+
desc "List/search artifacts", {
|
12
|
+
is_array: true,
|
13
|
+
success: Entities::ArtifactsWithPagination,
|
14
|
+
summary: "List/search artifacts"
|
15
|
+
}
|
16
|
+
params do
|
17
|
+
optional :q, type: String, default: ""
|
18
|
+
optional :page, type: Integer, default: 1
|
19
|
+
optional :limit, type: Integer, default: 10
|
52
20
|
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
21
|
+
get "/" do
|
22
|
+
value = Services::ArtifactSearcher.call(params.to_h)
|
23
|
+
present(
|
24
|
+
{
|
25
|
+
results: value.results,
|
26
|
+
total: value.total,
|
27
|
+
current_page: value.filter[:page].to_i,
|
28
|
+
page_size: value.filter[:limit].to_i
|
29
|
+
},
|
30
|
+
with: Entities::ArtifactsWithPagination
|
31
|
+
)
|
61
32
|
end
|
62
|
-
end
|
63
33
|
|
64
|
-
namespace :artifacts do
|
65
34
|
desc "Get an artifact", {
|
66
35
|
success: Entities::Artifact,
|
67
|
-
failure: [{ code: 404, model: Entities::
|
36
|
+
failure: [{ code: 404, model: Entities::ErrorMessage }],
|
68
37
|
summary: "Get an artifact"
|
69
38
|
}
|
70
39
|
params do
|
@@ -72,41 +41,52 @@ module Mihari
|
|
72
41
|
end
|
73
42
|
get "/:id" do
|
74
43
|
id = params[:id].to_i
|
75
|
-
result = ArtifactGetter.result(id)
|
44
|
+
result = Services::ArtifactGetter.result(id)
|
76
45
|
return present(result.value!, with: Entities::Artifact) if result.success?
|
77
46
|
|
78
47
|
case result.failure
|
79
48
|
when ActiveRecord::RecordNotFound
|
80
|
-
error!({ message: "ID:#{id}
|
49
|
+
error!({ message: "ID:#{id} not found" }, 404)
|
81
50
|
end
|
82
51
|
raise result.failure
|
83
52
|
end
|
84
53
|
|
85
54
|
desc "Enrich an artifact", {
|
86
55
|
success: { code: 201, model: Entities::Message },
|
87
|
-
failure: [{ code: 404, model: Entities::
|
56
|
+
failure: [{ code: 404, model: Entities::ErrorMessage }],
|
88
57
|
summary: "Enrich an artifact"
|
89
58
|
}
|
90
59
|
params do
|
91
60
|
requires :id, type: Integer
|
92
61
|
end
|
93
|
-
|
62
|
+
post "/:id/enrich" do
|
94
63
|
status 201
|
95
64
|
|
96
65
|
id = params["id"].to_i
|
97
|
-
|
98
|
-
|
66
|
+
|
67
|
+
queued = true
|
68
|
+
result = Dry::Monads::Try[StandardError] do
|
69
|
+
if Mihari.sidekiq?
|
70
|
+
Jobs::ArtifactEnrichJob.perform_async id
|
71
|
+
else
|
72
|
+
Services::ArtifactEnricher.call id
|
73
|
+
queued = false
|
74
|
+
end
|
75
|
+
end.to_result
|
76
|
+
|
77
|
+
message = queued ? "ID:#{id}'s enrichment has been queued" : "ID:#{id}'s enrichment has been succeeded"
|
78
|
+
return present({ message: message, queued: queued }, with: Entities::QueueMessage) if result.success?
|
99
79
|
|
100
80
|
case result.failure
|
101
81
|
when ActiveRecord::RecordNotFound
|
102
|
-
error!({ message: "ID:#{id}
|
82
|
+
error!({ message: "ID:#{id} not found" }, 404)
|
103
83
|
end
|
104
84
|
raise result.failure
|
105
85
|
end
|
106
86
|
|
107
87
|
desc "Delete an artifact", {
|
108
88
|
success: { code: 204, model: Entities::Message },
|
109
|
-
failure: [{ code: 404, model: Entities::
|
89
|
+
failure: [{ code: 404, model: Entities::ErrorMessage }],
|
110
90
|
summary: "Delete an artifact"
|
111
91
|
}
|
112
92
|
params do
|
@@ -116,12 +96,12 @@ module Mihari
|
|
116
96
|
status 204
|
117
97
|
|
118
98
|
id = params["id"].to_i
|
119
|
-
result = ArtifactDestroyer.result(id)
|
99
|
+
result = Services::ArtifactDestroyer.result(id)
|
120
100
|
return present({ message: "" }, with: Entities::Message) if result.success?
|
121
101
|
|
122
102
|
case result.failure
|
123
103
|
when ActiveRecord::RecordNotFound
|
124
|
-
error!({ message: "ID:#{id}
|
104
|
+
error!({ message: "ID:#{id} not found" }, 404)
|
125
105
|
end
|
126
106
|
raise result.failure
|
127
107
|
end
|
@@ -8,15 +8,13 @@ module Mihari
|
|
8
8
|
#
|
9
9
|
class Configs < Grape::API
|
10
10
|
namespace :configs do
|
11
|
-
desc "
|
11
|
+
desc "list configs", {
|
12
12
|
is_array: true,
|
13
13
|
success: Entities::Config,
|
14
|
-
summary: "
|
14
|
+
summary: "List configs"
|
15
15
|
}
|
16
16
|
get "/" do
|
17
|
-
configs =
|
18
|
-
Mihari::Structs::Config.from_class(klass)
|
19
|
-
end
|
17
|
+
configs = Services::ConfigSearcher.call
|
20
18
|
present(configs, with: Entities::Config)
|
21
19
|
end
|
22
20
|
end
|
@@ -7,21 +7,10 @@ module Mihari
|
|
7
7
|
# IP address API endpoint
|
8
8
|
#
|
9
9
|
class IPAddresses < Grape::API
|
10
|
-
class IPGetter < Service
|
11
|
-
#
|
12
|
-
# @param [String] ip
|
13
|
-
#
|
14
|
-
# @return [Mihari::Structs::IPInfo::Response]
|
15
|
-
#
|
16
|
-
def call(ip)
|
17
|
-
Mihari::Enrichers::IPInfo.new.call ip
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
10
|
namespace :ip_addresses do
|
22
11
|
desc "Get an IP address", {
|
23
12
|
success: Entities::IPAddress,
|
24
|
-
failure: [{ code: 404, model: Entities::
|
13
|
+
failure: [{ code: 404, model: Entities::ErrorMessage }],
|
25
14
|
summary: "Get an IP address"
|
26
15
|
}
|
27
16
|
params do
|
@@ -29,13 +18,23 @@ module Mihari
|
|
29
18
|
end
|
30
19
|
get "/:ip", requirements: { ip: %r{[^/]+} } do
|
31
20
|
ip = params[:ip].to_s
|
32
|
-
result = IPGetter.result(ip)
|
33
|
-
|
21
|
+
result = Services::IPGetter.result(ip)
|
22
|
+
if result.success?
|
23
|
+
value = result.value!
|
24
|
+
return present(
|
25
|
+
{
|
26
|
+
country_code: value.country_code,
|
27
|
+
asn: value.asn,
|
28
|
+
loc: value.loc
|
29
|
+
},
|
30
|
+
with: Entities::IPAddress
|
31
|
+
)
|
32
|
+
end
|
34
33
|
|
35
34
|
failure = result.failure
|
36
35
|
case failure
|
37
36
|
when Mihari::StatusCodeError
|
38
|
-
error!({ message: "ID:#{id}
|
37
|
+
error!({ message: "ID:#{id} not found" }, 404) if failure.status_code == 404
|
39
38
|
end
|
40
39
|
raise failure
|
41
40
|
end
|