mihari 5.6.2 → 5.7.1
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/lib/mihari/actor.rb +18 -2
- data/lib/mihari/analyzers/base.rb +13 -12
- data/lib/mihari/analyzers/binaryedge.rb +4 -1
- data/lib/mihari/analyzers/censys.rb +4 -2
- 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 +6 -1
- data/lib/mihari/analyzers/onyphe.rb +4 -1
- data/lib/mihari/analyzers/otx.rb +4 -1
- data/lib/mihari/analyzers/passivetotal.rb +4 -1
- data/lib/mihari/analyzers/pulsedive.rb +3 -0
- data/lib/mihari/analyzers/securitytrails.rb +4 -1
- data/lib/mihari/analyzers/shodan.rb +4 -1
- data/lib/mihari/analyzers/urlscan.rb +4 -1
- data/lib/mihari/analyzers/virustotal.rb +4 -1
- data/lib/mihari/analyzers/virustotal_intelligence.rb +4 -1
- data/lib/mihari/analyzers/zoomeye.rb +5 -2
- 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 +3 -0
- 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 +3 -0
- data/lib/mihari/clients/publsedive.rb +4 -1
- data/lib/mihari/clients/securitytrails.rb +3 -0
- 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 +9 -16
- data/lib/mihari/commands/database.rb +3 -0
- data/lib/mihari/commands/rule.rb +10 -1
- data/lib/mihari/commands/search.rb +13 -29
- 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 +13 -11
- data/lib/mihari/emitters/database.rb +4 -1
- data/lib/mihari/emitters/misp.rb +7 -4
- data/lib/mihari/emitters/slack.rb +3 -3
- data/lib/mihari/emitters/the_hive.rb +3 -3
- data/lib/mihari/emitters/webhook.rb +4 -3
- data/lib/mihari/enrichers/base.rb +15 -9
- data/lib/mihari/enrichers/google_public_dns.rb +6 -5
- data/lib/mihari/enrichers/ipinfo.rb +11 -9
- data/lib/mihari/enrichers/shodan.rb +4 -6
- data/lib/mihari/enrichers/whois.rb +12 -9
- data/lib/mihari/entities/tag.rb +1 -0
- 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 +7 -4
- data/lib/mihari/models/artifact.rb +6 -0
- data/lib/mihari/models/autonomous_system.rb +4 -1
- data/lib/mihari/models/cpe.rb +4 -1
- data/lib/mihari/models/dns.rb +4 -1
- data/lib/mihari/models/geolocation.rb +4 -1
- data/lib/mihari/models/port.rb +4 -1
- data/lib/mihari/models/reverse_dns.rb +4 -1
- data/lib/mihari/models/rule.rb +6 -3
- data/lib/mihari/models/tag.rb +3 -0
- data/lib/mihari/models/tagging.rb +3 -0
- data/lib/mihari/models/whois.rb +4 -3
- data/lib/mihari/rule.rb +31 -12
- data/lib/mihari/schemas/alert.rb +3 -0
- data/lib/mihari/schemas/analyzer.rb +11 -0
- data/lib/mihari/schemas/emitter.rb +3 -0
- data/lib/mihari/schemas/enricher.rb +3 -0
- data/lib/mihari/schemas/macros.rb +4 -0
- data/lib/mihari/schemas/mixins.rb +5 -0
- data/lib/mihari/schemas/rule.rb +3 -0
- data/lib/mihari/service.rb +26 -0
- data/lib/mihari/services/alert_builder.rb +85 -9
- data/lib/mihari/services/alert_runner.rb +8 -19
- data/lib/mihari/services/rule_builder.rb +13 -12
- data/lib/mihari/services/rule_runner.rb +7 -32
- data/lib/mihari/structs/binaryedge.rb +22 -28
- data/lib/mihari/structs/censys.rb +48 -141
- data/lib/mihari/structs/config.rb +19 -30
- data/lib/mihari/structs/filters.rb +38 -0
- data/lib/mihari/structs/fofa.rb +47 -0
- data/lib/mihari/structs/google_public_dns.rb +10 -32
- data/lib/mihari/structs/greynoise.rb +33 -90
- data/lib/mihari/structs/hunterhow.rb +24 -28
- data/lib/mihari/structs/ipinfo.rb +14 -37
- data/lib/mihari/structs/onyphe.rb +31 -80
- data/lib/mihari/structs/shodan.rb +47 -114
- data/lib/mihari/structs/urlscan.rb +24 -69
- data/lib/mihari/structs/virustotal_intelligence.rb +20 -64
- 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 +64 -56
- data/lib/mihari/web/endpoints/alerts.rb +127 -85
- data/lib/mihari/web/endpoints/artifacts.rb +91 -79
- data/lib/mihari/web/endpoints/configs.rb +18 -13
- data/lib/mihari/web/endpoints/ip_addresses.rb +35 -15
- data/lib/mihari/web/endpoints/rules.rb +236 -187
- data/lib/mihari/web/endpoints/tags.rb +42 -35
- 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-28d4c79d.js → index-07fafab5.js} +31 -30
- 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 +24 -6
- data/mihari.gemspec +9 -2
- data/mkdocs.yml +4 -2
- metadata +38 -133
- data/docs/alternatives.md +0 -5
- data/docs/analyzers/binaryedge.md +0 -26
- data/docs/analyzers/censys.md +0 -31
- data/docs/analyzers/circl.md +0 -37
- data/docs/analyzers/crtsh.md +0 -26
- data/docs/analyzers/dnstwister.md +0 -25
- data/docs/analyzers/feed.md +0 -73
- data/docs/analyzers/greynoise.md +0 -26
- data/docs/analyzers/hunterhow.md +0 -33
- data/docs/analyzers/index.md +0 -103
- data/docs/analyzers/onyphe.md +0 -26
- data/docs/analyzers/otx.md +0 -28
- data/docs/analyzers/passivetotal.md +0 -52
- data/docs/analyzers/pulsedive.md +0 -28
- data/docs/analyzers/securitytrails.md +0 -41
- data/docs/analyzers/shodan.md +0 -26
- data/docs/analyzers/urlscan.md +0 -28
- data/docs/analyzers/virustotal.md +0 -43
- data/docs/analyzers/virustotal_intelligence.md +0 -33
- data/docs/analyzers/zoomeye.md +0 -38
- data/docs/configuration.md +0 -35
- data/docs/emitters/database.md +0 -22
- data/docs/emitters/hive.md +0 -26
- data/docs/emitters/index.md +0 -36
- data/docs/emitters/misp.md +0 -21
- data/docs/emitters/slack.md +0 -21
- data/docs/emitters/webhook.md +0 -63
- data/docs/enrichers/google_public_dns.md +0 -19
- data/docs/enrichers/index.md +0 -35
- data/docs/enrichers/ipinfo.md +0 -26
- data/docs/enrichers/shodan.md +0 -22
- data/docs/enrichers/whois.md +0 -17
- data/docs/github_actions.md +0 -43
- data/docs/index.md +0 -11
- data/docs/installation.md +0 -31
- data/docs/requirements.md +0 -13
- data/docs/rule.md +0 -168
- data/docs/tags.md +0 -3
- data/docs/usage.md +0 -103
- data/frontend/.eslintrc.cjs +0 -22
- data/frontend/.gitignore +0 -31
- data/frontend/.prettierrc.json +0 -8
- data/frontend/README.md +0 -3
- data/frontend/env.d.ts +0 -5
- data/frontend/index.html +0 -21
- data/frontend/package-lock.json +0 -7219
- data/frontend/package.json +0 -67
- data/frontend/public/favicon.ico +0 -0
- data/frontend/scripts/swagger_doc_to_yaml.rb +0 -23
- data/frontend/src/App.vue +0 -27
- data/frontend/src/ace-config.ts +0 -6
- data/frontend/src/api-helper.ts +0 -111
- data/frontend/src/api.ts +0 -105
- data/frontend/src/components/ErrorMessage.vue +0 -31
- data/frontend/src/components/Loading.vue +0 -15
- data/frontend/src/components/Navbar.vue +0 -42
- data/frontend/src/components/Pagination.vue +0 -119
- data/frontend/src/components/alert/Alert.vue +0 -87
- data/frontend/src/components/alert/Alerts.vue +0 -63
- data/frontend/src/components/alert/AlertsWithPagination.vue +0 -90
- data/frontend/src/components/alert/AlertsWrapper.vue +0 -128
- data/frontend/src/components/alert/Form.vue +0 -182
- data/frontend/src/components/artifact/AS.vue +0 -29
- data/frontend/src/components/artifact/Artifact.vue +0 -287
- data/frontend/src/components/artifact/ArtifactTag.vue +0 -64
- data/frontend/src/components/artifact/ArtifactTags.vue +0 -29
- data/frontend/src/components/artifact/ArtifactWrapper.vue +0 -57
- data/frontend/src/components/artifact/CPEs.vue +0 -23
- data/frontend/src/components/artifact/DnsRecords.vue +0 -38
- data/frontend/src/components/artifact/Ports.vue +0 -23
- data/frontend/src/components/artifact/ReverseDnsNames.vue +0 -31
- data/frontend/src/components/artifact/Tags.vue +0 -29
- data/frontend/src/components/artifact/WhoisRecord.vue +0 -44
- data/frontend/src/components/config/Configs.vue +0 -65
- data/frontend/src/components/config/ConfigsWrapper.vue +0 -32
- data/frontend/src/components/link/Link.vue +0 -32
- data/frontend/src/components/link/Links.vue +0 -42
- data/frontend/src/components/rule/EditRule.vue +0 -72
- data/frontend/src/components/rule/EditRuleWrapper.vue +0 -48
- data/frontend/src/components/rule/Form.vue +0 -158
- data/frontend/src/components/rule/InputForm.vue +0 -45
- data/frontend/src/components/rule/NewRule.vue +0 -57
- data/frontend/src/components/rule/Rule.vue +0 -100
- data/frontend/src/components/rule/RuleWrapper.vue +0 -53
- data/frontend/src/components/rule/Rules.vue +0 -84
- data/frontend/src/components/rule/RulesWrapper.vue +0 -121
- data/frontend/src/components/rule/YAML.vue +0 -37
- data/frontend/src/components/tag/Tag.vue +0 -65
- data/frontend/src/components/tag/Tags.vue +0 -37
- data/frontend/src/countries.ts +0 -350
- data/frontend/src/index.ts +0 -20
- data/frontend/src/links/anyrun.ts +0 -19
- data/frontend/src/links/base.ts +0 -14
- data/frontend/src/links/censys.ts +0 -20
- data/frontend/src/links/crtsh.ts +0 -20
- data/frontend/src/links/dnslytics.ts +0 -38
- data/frontend/src/links/greynoise.ts +0 -20
- data/frontend/src/links/index.ts +0 -40
- data/frontend/src/links/intezer.ts +0 -20
- data/frontend/src/links/otx.ts +0 -33
- data/frontend/src/links/securitytrails.ts +0 -38
- data/frontend/src/links/shodan.ts +0 -20
- data/frontend/src/links/urlscan.ts +0 -50
- data/frontend/src/links/virustotal.ts +0 -72
- data/frontend/src/main.ts +0 -41
- data/frontend/src/router/index.ts +0 -57
- data/frontend/src/rule.ts +0 -14
- data/frontend/src/shims-vue.d.ts +0 -6
- data/frontend/src/swagger.yaml +0 -771
- data/frontend/src/types.ts +0 -188
- data/frontend/src/utils.ts +0 -54
- data/frontend/src/views/Alerts.vue +0 -20
- data/frontend/src/views/Artifact.vue +0 -39
- data/frontend/src/views/Configs.vue +0 -20
- data/frontend/src/views/EditRule.vue +0 -39
- data/frontend/src/views/NewRule.vue +0 -26
- data/frontend/src/views/Rule.vue +0 -39
- data/frontend/src/views/Rules.vue +0 -20
- data/frontend/tests/utils.spec.ts +0 -9
- data/frontend/tsconfig.app.json +0 -21
- data/frontend/tsconfig.json +0 -14
- data/frontend/tsconfig.node.json +0 -13
- data/frontend/tsconfig.vitest.json +0 -12
- data/frontend/vite.config.ts +0 -24
- data/frontend/vitest.config.ts +0 -21
- data/lib/mihari/services/alert_proxy.rb +0 -92
- data/lib/mihari/templates/rule.yml.erb +0 -5
- data/lib/mihari/web/public/assets/mode-yaml-a21faa53.js +0 -8
data/lib/mihari/clients/circl.rb
CHANGED
data/lib/mihari/clients/crtsh.rb
CHANGED
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "base64"
|
4
|
+
|
5
|
+
module Mihari
|
6
|
+
module Clients
|
7
|
+
#
|
8
|
+
# Fofa API client
|
9
|
+
#
|
10
|
+
class Fofa < Base
|
11
|
+
PAGE_SIZE = 10_000
|
12
|
+
|
13
|
+
# @return [String]
|
14
|
+
attr_reader :api_key
|
15
|
+
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :email
|
18
|
+
|
19
|
+
#
|
20
|
+
# @param [String] base_url
|
21
|
+
# @param [String, nil] api_key
|
22
|
+
# @param [String, nil] email
|
23
|
+
# @param [Hash] headers
|
24
|
+
# @param [Integer] pagination_interval
|
25
|
+
# @param [Integer, nil] timeout
|
26
|
+
#
|
27
|
+
# @param [Object] email
|
28
|
+
def initialize(
|
29
|
+
base_url = "https://fofa.info/",
|
30
|
+
api_key:,
|
31
|
+
email:,
|
32
|
+
headers: {},
|
33
|
+
pagination_interval: Mihari.config.pagination_interval,
|
34
|
+
timeout: nil
|
35
|
+
)
|
36
|
+
raise(ArgumentError, "api_key is required") unless api_key
|
37
|
+
raise(ArgumentError, "email is required") unless email
|
38
|
+
|
39
|
+
@api_key = api_key
|
40
|
+
@email = email
|
41
|
+
|
42
|
+
super(base_url, headers: headers, pagination_interval: pagination_interval, timeout: timeout)
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# @param [String] query
|
47
|
+
# @param [Integer] size
|
48
|
+
# @param [Integer] page
|
49
|
+
#
|
50
|
+
# @return [Mihari::Structs::Fofa::Response]
|
51
|
+
#
|
52
|
+
def search(query, page:, size: PAGE_SIZE)
|
53
|
+
qbase64 = Base64.urlsafe_encode64(query)
|
54
|
+
params = { qbase64: qbase64, size: size, page: page, email: email, key: api_key }.compact
|
55
|
+
res = get("/api/v1/search/all", params: params)
|
56
|
+
Structs::Fofa::Response.from_dynamic! JSON.parse(res.body.to_s)
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# @param [String] query
|
61
|
+
# @param [Integer] size
|
62
|
+
# @param [Integer] pagination_limit
|
63
|
+
#
|
64
|
+
# @return [Enumerable<Mihari::Structs::Fofa::Response>]
|
65
|
+
#
|
66
|
+
def search_with_pagination(query, size: PAGE_SIZE, pagination_limit: Mihari.config.pagination_limit)
|
67
|
+
Enumerator.new do |y|
|
68
|
+
(1..pagination_limit).each do |page|
|
69
|
+
res = search(query, page: page, size: size)
|
70
|
+
|
71
|
+
y.yield res
|
72
|
+
|
73
|
+
break if res.error
|
74
|
+
|
75
|
+
break if (res.results || []).length < size
|
76
|
+
|
77
|
+
sleep_pagination_interval
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Clients
|
5
|
+
#
|
6
|
+
# GreyNoise API client
|
7
|
+
#
|
5
8
|
class GreyNoise < Base
|
6
9
|
PAGE_SIZE = 10_000
|
7
10
|
|
@@ -32,7 +35,7 @@ module Mihari
|
|
32
35
|
# @param [Integer] size Maximum amount of results to grab
|
33
36
|
# @param [Integer, nil] scroll Scroll token to paginate through results
|
34
37
|
#
|
35
|
-
# @return [
|
38
|
+
# @return [Mihari::Structs::GreyNoise::Response]
|
36
39
|
#
|
37
40
|
def gnql_search(query, size: PAGE_SIZE, scroll: nil)
|
38
41
|
params = { query: query, size: size, scroll: scroll }.compact
|
@@ -45,7 +48,7 @@ module Mihari
|
|
45
48
|
# @param [Integer] size
|
46
49
|
# @param [Integer] pagination_limit
|
47
50
|
#
|
48
|
-
# @return [Enumerable<Structs::GreyNoise::Response>]
|
51
|
+
# @return [Enumerable<Mihari::Structs::GreyNoise::Response>]
|
49
52
|
#
|
50
53
|
def gnql_search_with_pagination(query, size: PAGE_SIZE, pagination_limit: Mihari.config.pagination_limit)
|
51
54
|
scroll = nil
|
@@ -4,6 +4,9 @@ require "base64"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Clients
|
7
|
+
#
|
8
|
+
# hunter.how API client
|
9
|
+
#
|
7
10
|
class HunterHow < Base
|
8
11
|
PAGE_SIZE = 100
|
9
12
|
|
@@ -38,7 +41,7 @@ module Mihari
|
|
38
41
|
# @param [String] start_time
|
39
42
|
# @param [String] end_time
|
40
43
|
#
|
41
|
-
# @return [Structs::HunterHow::Response]
|
44
|
+
# @return [Mihari::Structs::HunterHow::Response]
|
42
45
|
#
|
43
46
|
def search(query, start_time:, end_time:, page: 1, page_size: PAGE_SIZE)
|
44
47
|
params = {
|
@@ -60,7 +63,7 @@ module Mihari
|
|
60
63
|
# @param [String] start_time
|
61
64
|
# @param [String] end_time
|
62
65
|
#
|
63
|
-
# @return [Enumerable<Structs::HunterHow::Response>]
|
66
|
+
# @return [Enumerable<Mihari::Structs::HunterHow::Response>]
|
64
67
|
#
|
65
68
|
def search_with_pagination(
|
66
69
|
query,
|
data/lib/mihari/clients/misp.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Clients
|
5
|
+
#
|
6
|
+
# Onyphe API client
|
7
|
+
#
|
5
8
|
class Onyphe < Base
|
6
9
|
PAGE_SIZE = 10
|
7
10
|
|
@@ -33,7 +36,7 @@ module Mihari
|
|
33
36
|
# @param [String] query
|
34
37
|
# @param [Integer] page
|
35
38
|
#
|
36
|
-
# @return [Structs::Onyphe::Response]
|
39
|
+
# @return [Mihari::Structs::Onyphe::Response]
|
37
40
|
#
|
38
41
|
def datascan(query, page: 1)
|
39
42
|
params = { page: page, apikey: api_key }
|
@@ -45,7 +48,7 @@ module Mihari
|
|
45
48
|
# @param [String] query
|
46
49
|
# @param [Integer] pagination_limit
|
47
50
|
#
|
48
|
-
# @return [Enumerable<Structs::Onyphe::Response>]
|
51
|
+
# @return [Enumerable<Mihari::Structs::Onyphe::Response>]
|
49
52
|
#
|
50
53
|
def datascan_with_pagination(query, pagination_limit: Mihari.config.pagination_limit)
|
51
54
|
Enumerator.new do |y|
|
data/lib/mihari/clients/otx.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Clients
|
5
|
+
#
|
6
|
+
# PulseDive API client
|
7
|
+
#
|
5
8
|
class PulseDive < Base
|
6
9
|
# @return [String]
|
7
10
|
attr_reader :api_key
|
@@ -21,7 +24,7 @@ module Mihari
|
|
21
24
|
end
|
22
25
|
|
23
26
|
#
|
24
|
-
# @param [String]
|
27
|
+
# @param [String] ip_or_domain
|
25
28
|
#
|
26
29
|
# @return [Hash]
|
27
30
|
#
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Clients
|
5
|
+
#
|
6
|
+
# Shodan API client
|
7
|
+
#
|
5
8
|
class Shodan < Base
|
6
9
|
PAGE_SIZE = 100
|
7
10
|
|
@@ -34,7 +37,7 @@ module Mihari
|
|
34
37
|
# @param [Integer] page
|
35
38
|
# @param [Boolean] minify
|
36
39
|
#
|
37
|
-
# @return [Structs::Shodan::Result]
|
40
|
+
# @return [Mihari::Structs::Shodan::Result]
|
38
41
|
#
|
39
42
|
def search(query, page: 1, minify: true)
|
40
43
|
params = {
|
@@ -52,7 +55,7 @@ module Mihari
|
|
52
55
|
# @param [Boolean] minify
|
53
56
|
# @param [Integer] pagination_limit
|
54
57
|
#
|
55
|
-
# @return [Enumerable<Structs::Shodan::Response>]
|
58
|
+
# @return [Enumerable<Mihari::Structs::Shodan::Response>]
|
56
59
|
#
|
57
60
|
def search_with_pagination(query, minify: true, pagination_limit: Mihari.config.pagination_limit)
|
58
61
|
Enumerator.new do |y|
|
@@ -2,12 +2,15 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Clients
|
5
|
-
|
5
|
+
#
|
6
|
+
# urlscan.io API client
|
7
|
+
#
|
8
|
+
class Urlscan < Base
|
6
9
|
#
|
7
10
|
# @param [String] base_url
|
8
11
|
# @param [String, nil] api_key
|
9
12
|
# @param [Hash] headers
|
10
|
-
# @param [Integer, nil]
|
13
|
+
# @param [Integer, nil] pagination_interval
|
11
14
|
# @param [Integer, nil] timeout
|
12
15
|
#
|
13
16
|
def initialize(
|
@@ -29,7 +32,7 @@ module Mihari
|
|
29
32
|
# @param [Integer, nil] size
|
30
33
|
# @param [String, nil] search_after
|
31
34
|
#
|
32
|
-
# @return [Structs::Urlscan::Response]
|
35
|
+
# @return [Mihari::Structs::Urlscan::Response]
|
33
36
|
#
|
34
37
|
def search(q, size: nil, search_after: nil)
|
35
38
|
params = { q: q, size: size, search_after: search_after }.compact
|
@@ -42,7 +45,7 @@ module Mihari
|
|
42
45
|
# @param [Integer, nil] size
|
43
46
|
# @param [Integer] pagination_limit
|
44
47
|
#
|
45
|
-
# @return [Enumerable<Structs::Urlscan::Response>]
|
48
|
+
# @return [Enumerable<Mihari::Structs::Urlscan::Response>]
|
46
49
|
#
|
47
50
|
def search_with_pagination(q, size: nil, pagination_limit: Mihari.config.pagination_limit)
|
48
51
|
search_after = nil
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Clients
|
5
|
+
#
|
6
|
+
# VirusTotal API client
|
7
|
+
#
|
5
8
|
class VirusTotal < Base
|
6
9
|
#
|
7
10
|
# @param [String] base_url
|
@@ -46,7 +49,7 @@ module Mihari
|
|
46
49
|
# @param [String] query
|
47
50
|
# @param [String, nil] cursor
|
48
51
|
#
|
49
|
-
# @return [Structs::VirusTotalIntelligence::Response]
|
52
|
+
# @return [Mihari::Structs::VirusTotalIntelligence::Response]
|
50
53
|
#
|
51
54
|
def intel_search(query, cursor: nil)
|
52
55
|
params = { query: query, cursor: cursor }.compact
|
@@ -58,7 +61,7 @@ module Mihari
|
|
58
61
|
# @param [String] query
|
59
62
|
# @param [Integer] pagination_limit
|
60
63
|
#
|
61
|
-
# @return [Enumerable<Structs::VirusTotalIntelligence::Response>]
|
64
|
+
# @return [Enumerable<Mihari::Structs::VirusTotalIntelligence::Response>]
|
62
65
|
#
|
63
66
|
def intel_search_with_pagination(query, pagination_limit: Mihari.config.pagination_limit)
|
64
67
|
cursor = nil
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Commands
|
5
|
+
#
|
6
|
+
# Alert sub-commands
|
7
|
+
#
|
5
8
|
module Alert
|
6
9
|
class << self
|
7
10
|
def included(thor)
|
@@ -14,28 +17,18 @@ module Mihari
|
|
14
17
|
#
|
15
18
|
def add(path)
|
16
19
|
Mihari::Database.with_db_connection do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
result = Dry::Monads::Try[StandardError] do
|
21
|
+
# @type [Mihari::Services::AlertProxy]
|
22
|
+
proxy = Mihari::Services::AlertBuilder.call(path)
|
23
|
+
Mihari::Services::AlertRunner.call(proxy)
|
24
|
+
end.to_result
|
21
25
|
|
26
|
+
# @type [Mihari::Models::Alert]
|
22
27
|
alert = result.value!
|
23
28
|
data = Entities::Alert.represent(alert)
|
24
29
|
puts JSON.pretty_generate(data.as_json)
|
25
30
|
end
|
26
31
|
end
|
27
|
-
|
28
|
-
no_commands do
|
29
|
-
#
|
30
|
-
# @param [Mihari::Services::AlertProxy] proxy
|
31
|
-
#
|
32
|
-
def run_proxy(proxy)
|
33
|
-
Dry::Monads::Try[StandardError] do
|
34
|
-
runner = Services::AlertRunner.new(proxy)
|
35
|
-
runner.run
|
36
|
-
end.to_result
|
37
|
-
end
|
38
|
-
end
|
39
32
|
end
|
40
33
|
end
|
41
34
|
end
|
data/lib/mihari/commands/rule.rb
CHANGED
@@ -4,6 +4,9 @@ require "pathname"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Commands
|
7
|
+
#
|
8
|
+
# Rule sub-commands
|
9
|
+
#
|
7
10
|
module Rule
|
8
11
|
class << self
|
9
12
|
def included(thor)
|
@@ -48,7 +51,13 @@ module Mihari
|
|
48
51
|
# @return [nil]
|
49
52
|
#
|
50
53
|
def initialize_rule(path, files = Dry::Files.new)
|
51
|
-
rule = Mihari::Rule.
|
54
|
+
rule = Mihari::Rule.new(
|
55
|
+
id: SecureRandom.uuid,
|
56
|
+
title: "Title goes here",
|
57
|
+
description: "Description goes here",
|
58
|
+
created_on: Date.today,
|
59
|
+
queries: []
|
60
|
+
)
|
52
61
|
files.write(path, rule.yaml)
|
53
62
|
end
|
54
63
|
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Commands
|
5
|
+
#
|
6
|
+
# Search sub-commands
|
7
|
+
#
|
5
8
|
module Search
|
6
9
|
class << self
|
7
10
|
def included(thor)
|
@@ -17,43 +20,24 @@ module Mihari
|
|
17
20
|
#
|
18
21
|
def search(path_or_id)
|
19
22
|
Mihari::Database.with_db_connection do
|
20
|
-
|
23
|
+
result = Dry::Monads::Try[StandardError] do
|
24
|
+
# @type [Mihari::Rule]
|
25
|
+
rule = Services::RuleBuilder.call(path_or_id)
|
21
26
|
|
22
|
-
|
23
|
-
|
27
|
+
force_overwrite = options["force_overwrite"] || false
|
28
|
+
message = "There is a diff in the rule. Are you sure you want to overwrite the rule? (y/n)"
|
29
|
+
exit 0 if rule.diff? && !force_overwrite && !yes?(message)
|
24
30
|
|
25
|
-
|
31
|
+
rule.update_or_create
|
32
|
+
rule.call
|
33
|
+
end.to_result
|
26
34
|
|
35
|
+
# @type [Mihari::Models::Alert]
|
27
36
|
alert = result.value!
|
28
37
|
data = Entities::Alert.represent(alert)
|
29
38
|
puts JSON.pretty_generate(data.as_json)
|
30
39
|
end
|
31
40
|
end
|
32
|
-
|
33
|
-
no_commands do
|
34
|
-
#
|
35
|
-
# @param [Mihari::Services::RuleRunner] rule
|
36
|
-
#
|
37
|
-
def check_diff(rule)
|
38
|
-
force_overwrite = options["force_overwrite"] || false
|
39
|
-
message = "There is a diff in the rule. Are you sure you want to overwrite the rule? (y/n)"
|
40
|
-
runner = Services::RuleRunner.new(rule)
|
41
|
-
|
42
|
-
exit 0 if runner.diff? && !force_overwrite && !yes?(message)
|
43
|
-
|
44
|
-
Success runner
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# @param [Mihari::Services::RuleRunner] runner
|
49
|
-
#
|
50
|
-
def update_and_run(runner)
|
51
|
-
Dry::Monads::Try[StandardError] do
|
52
|
-
runner.update_or_create
|
53
|
-
runner.run
|
54
|
-
end.to_result
|
55
|
-
end
|
56
|
-
end
|
57
41
|
end
|
58
42
|
end
|
59
43
|
end
|
data/lib/mihari/commands/web.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Commands
|
5
|
+
#
|
6
|
+
# Web sub-commands
|
7
|
+
#
|
5
8
|
module Web
|
6
9
|
class << self
|
7
10
|
def included(thor)
|
@@ -20,7 +23,7 @@ module Mihari
|
|
20
23
|
Mihari.config.hide_config_values = options["hide_config_values"]
|
21
24
|
# set rack env as production
|
22
25
|
ENV["RACK_ENV"] ||= options["rack_env"]
|
23
|
-
Mihari::App.run!(
|
26
|
+
Mihari::Web::App.run!(
|
24
27
|
port: options["port"],
|
25
28
|
host: options["host"],
|
26
29
|
threads: options["threads"],
|