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/config.rb
CHANGED
@@ -1,178 +1,167 @@
|
|
1
|
-
|
2
|
-
class Config
|
3
|
-
# @return [String, nil]
|
4
|
-
attr_reader :binaryedge_api_key
|
5
|
-
|
6
|
-
# @return [String, nil]
|
7
|
-
attr_reader :censys_id
|
8
|
-
|
9
|
-
# @return [String, nil]
|
10
|
-
attr_reader :censys_secret
|
11
|
-
|
12
|
-
# @return [String, nil]
|
13
|
-
attr_reader :circl_passive_password
|
14
|
-
|
15
|
-
# @return [String, nil]
|
16
|
-
attr_reader :circl_passive_username
|
17
|
-
|
18
|
-
# @return [URI]
|
19
|
-
attr_reader :database_url
|
20
|
-
|
21
|
-
# @return [String, nil]
|
22
|
-
attr_reader :greynoise_api_key
|
23
|
-
|
24
|
-
# @return [String, nil]
|
25
|
-
attr_reader :hunterhow_api_key
|
26
|
-
|
27
|
-
# @return [String, nil]
|
28
|
-
attr_reader :ipinfo_api_key
|
29
|
-
|
30
|
-
# @return [String, nil]
|
31
|
-
attr_reader :misp_url
|
32
|
-
|
33
|
-
# @return [String, nil]
|
34
|
-
attr_reader :misp_api_key
|
35
|
-
|
36
|
-
# @return [String, nil]
|
37
|
-
attr_reader :onyphe_api_key
|
38
|
-
|
39
|
-
# @return [String, nil]
|
40
|
-
attr_reader :otx_api_key
|
41
|
-
|
42
|
-
# @return [String, nil]
|
43
|
-
attr_reader :passivetotal_api_key
|
44
|
-
|
45
|
-
# @return [String, nil]
|
46
|
-
attr_reader :passivetotal_username
|
47
|
-
|
48
|
-
# @return [String, nil]
|
49
|
-
attr_reader :pulsedive_api_key
|
50
|
-
|
51
|
-
# @return [String, nil]
|
52
|
-
attr_reader :securitytrails_api_key
|
53
|
-
|
54
|
-
# @return [String, nil]
|
55
|
-
attr_reader :shodan_api_key
|
56
|
-
|
57
|
-
# @return [String, nil]
|
58
|
-
attr_reader :slack_channel
|
59
|
-
|
60
|
-
# @return [String, nil]
|
61
|
-
attr_reader :slack_webhook_url
|
62
|
-
|
63
|
-
# @return [String, nil]
|
64
|
-
attr_reader :thehive_url
|
1
|
+
# frozen_string_literal: true
|
65
2
|
|
66
|
-
|
67
|
-
attr_reader :thehive_api_key
|
3
|
+
require "anyway_config"
|
68
4
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
@greynoise_api_key = ENV.fetch("GREYNOISE_API_KEY", nil)
|
121
|
-
|
122
|
-
@ipinfo_api_key = ENV.fetch("IPINFO_API_KEY", nil)
|
123
|
-
|
124
|
-
@hunterhow_api_key = ENV.fetch("HUNTERHOW_API_KEY", nil)
|
5
|
+
module Mihari
|
6
|
+
class Config < Anyway::Config
|
7
|
+
config_name :mihari
|
8
|
+
env_prefix ""
|
9
|
+
|
10
|
+
attr_config(
|
11
|
+
# analyzers, emitters & enrichers
|
12
|
+
binaryedge_api_key: nil,
|
13
|
+
censys_id: nil,
|
14
|
+
censys_secret: nil,
|
15
|
+
circl_passive_password: nil,
|
16
|
+
circl_passive_username: nil,
|
17
|
+
database_url: URI("sqlite3:///mihari.db"),
|
18
|
+
fofa_api_key: nil,
|
19
|
+
fofa_email: nil,
|
20
|
+
greynoise_api_key: nil,
|
21
|
+
hunterhow_api_key: nil,
|
22
|
+
ipinfo_api_key: nil,
|
23
|
+
misp_api_key: nil,
|
24
|
+
misp_url: nil,
|
25
|
+
onyphe_api_key: nil,
|
26
|
+
otx_api_key: nil,
|
27
|
+
passivetotal_api_key: nil,
|
28
|
+
passivetotal_username: nil,
|
29
|
+
pulsedive_api_key: nil,
|
30
|
+
securitytrails_api_key: nil,
|
31
|
+
shodan_api_key: nil,
|
32
|
+
slack_channel: nil,
|
33
|
+
slack_webhook_url: nil,
|
34
|
+
thehive_api_key: nil,
|
35
|
+
thehive_api_version: nil,
|
36
|
+
thehive_url: nil,
|
37
|
+
urlscan_api_key: nil,
|
38
|
+
virustotal_api_key: nil,
|
39
|
+
zoomeye_api_key: nil,
|
40
|
+
# others
|
41
|
+
hide_config_values: true,
|
42
|
+
ignore_error: false,
|
43
|
+
pagination_interval: 0,
|
44
|
+
pagination_limit: 100,
|
45
|
+
retry_exponential_backoff: true,
|
46
|
+
retry_interval: 5,
|
47
|
+
retry_times: 3,
|
48
|
+
sentry_dsn: nil
|
49
|
+
)
|
50
|
+
|
51
|
+
# @!attribute [r] binaryedge_api_key
|
52
|
+
# @return [String, nil]
|
53
|
+
|
54
|
+
# @!attribute [r] censys_id
|
55
|
+
# @return [String, nil]
|
125
56
|
|
126
|
-
|
127
|
-
|
57
|
+
# @!attribute [r] circl_passive_password
|
58
|
+
# @return [String, nil]
|
59
|
+
|
60
|
+
# @!attribute [r] circl_passive_username
|
61
|
+
# @return [String, nil]
|
62
|
+
|
63
|
+
# @!attribute [r] database_url
|
64
|
+
# @return [String, nil]
|
65
|
+
|
66
|
+
# @!attribute [r] fofa_api_key
|
67
|
+
# @return [String, nil]
|
68
|
+
|
69
|
+
# @!attribute [r] fofa_email
|
70
|
+
# @return [String, nil]
|
71
|
+
|
72
|
+
# @!attribute [r] greynoise_api_key
|
73
|
+
# @return [String, nil]
|
74
|
+
|
75
|
+
# @!attribute [r] hunterhow_api_key
|
76
|
+
# @return [String, nil]
|
77
|
+
|
78
|
+
# @!attribute [r] ipinfo_api_key
|
79
|
+
# @return [String, nil]
|
80
|
+
|
81
|
+
# @!attribute [r] misp_url
|
82
|
+
# @return [String, nil]
|
83
|
+
|
84
|
+
# @!attribute [r] misp_api_key
|
85
|
+
# @return [String, nil]
|
86
|
+
|
87
|
+
# @!attribute [r] onyphe_api_key
|
88
|
+
# @return [String, nil]
|
89
|
+
|
90
|
+
# @!attribute [r] otx_api_key
|
91
|
+
# @return [String, nil]
|
92
|
+
|
93
|
+
# @!attribute [r] passivetotal_api_key
|
94
|
+
# @return [String, nil]
|
95
|
+
|
96
|
+
# @!attribute [r] passivetotal_username
|
97
|
+
# @return [String, nil]
|
98
|
+
|
99
|
+
# @!attribute [r] pulsedive_api_key
|
100
|
+
# @return [String, nil]
|
101
|
+
|
102
|
+
# @!attribute [r] securitytrails_api_key
|
103
|
+
# @return [String, nil]
|
104
|
+
|
105
|
+
# @!attribute [r] shodan_api_key
|
106
|
+
# @return [String, nil]
|
128
107
|
|
129
|
-
|
108
|
+
# @!attribute [r] slack_channel
|
109
|
+
# @return [String, nil]
|
110
|
+
|
111
|
+
# @!attribute [r] slack_webhook_url
|
112
|
+
# @return [String, nil]
|
130
113
|
|
131
|
-
|
114
|
+
# @!attribute [r] thehive_url
|
115
|
+
# @return [String, nil]
|
132
116
|
|
133
|
-
|
134
|
-
|
117
|
+
# @!attribute [r] thehive_api_key
|
118
|
+
# @return [String, nil]
|
135
119
|
|
136
|
-
|
120
|
+
# @!attribute [r] thehive_api_version
|
121
|
+
# @return [String, nil]
|
137
122
|
|
138
|
-
|
123
|
+
# @!attribute [r] urlscan_api_key
|
124
|
+
# @return [String, nil]
|
139
125
|
|
140
|
-
|
126
|
+
# @!attribute [r] virustotal_api_key
|
127
|
+
# @return [String, nil]
|
141
128
|
|
142
|
-
|
143
|
-
|
129
|
+
# @!attribute [r] zoomeye_api_key
|
130
|
+
# @return [String, nil]
|
144
131
|
|
145
|
-
|
146
|
-
|
147
|
-
@thehive_api_version = ENV.fetch("THEHIVE_API_VERSION", nil)
|
132
|
+
# @!attribute [r] sentry_dsn
|
133
|
+
# @return [String, nil]
|
148
134
|
|
149
|
-
|
135
|
+
# @!attribute [r] retry_interval
|
136
|
+
# @return [Integer]
|
150
137
|
|
151
|
-
|
138
|
+
# @!attribute [r] retry_times
|
139
|
+
# @return [Integer]
|
152
140
|
|
153
|
-
|
141
|
+
# @!attribute [r] retry_exponential_backoff
|
142
|
+
# @return [Boolean]
|
154
143
|
|
155
|
-
|
144
|
+
# @!attribute [r] pagination_interval
|
145
|
+
# @return [Integer]
|
156
146
|
|
157
|
-
|
147
|
+
# @!attribute [r] pagination_limit
|
148
|
+
# @return [Integer]
|
158
149
|
|
159
|
-
|
160
|
-
|
161
|
-
@retry_exponential_backoff = ENV.fetch("RETRY_EXPONENTIAL_BACKOFF", true).to_s.downcase == "true"
|
150
|
+
# @!attribute [r] ignore_error
|
151
|
+
# @return [Boolean]
|
162
152
|
|
163
|
-
|
164
|
-
|
153
|
+
# @!attribute [rw] hide_config_values
|
154
|
+
# @return [Boolean]
|
165
155
|
|
166
|
-
|
156
|
+
def database_url=(val)
|
157
|
+
super URI(val.to_s)
|
167
158
|
end
|
168
159
|
|
169
160
|
#
|
170
161
|
# @return [Array<String>]
|
171
162
|
#
|
172
163
|
def keys
|
173
|
-
|
174
|
-
key[1..].to_s.upcase
|
175
|
-
end
|
164
|
+
to_h.keys.map(&:to_s).map(&:upcase)
|
176
165
|
end
|
177
166
|
end
|
178
167
|
end
|
data/lib/mihari/constants.rb
CHANGED
@@ -5,7 +5,7 @@ module Mihari
|
|
5
5
|
DEFAULT_DATA_TYPES = Types::DataTypes.values.freeze
|
6
6
|
|
7
7
|
# @return [Array<Hash>]
|
8
|
-
DEFAULT_EMITTERS =
|
8
|
+
DEFAULT_EMITTERS = Emitters::Database.class_keys.map { |name| { emitter: name } }.freeze
|
9
9
|
|
10
10
|
# @return [Array<Hash>]
|
11
11
|
DEFAULT_ENRICHERS = Mihari.enricher_to_class.keys.map { |name| { enricher: name.downcase } }.freeze
|
data/lib/mihari/database.rb
CHANGED
@@ -13,6 +13,9 @@ def development_env?
|
|
13
13
|
env == "development"
|
14
14
|
end
|
15
15
|
|
16
|
+
#
|
17
|
+
# Mihari v5 DB schema
|
18
|
+
#
|
16
19
|
class V5Schema < ActiveRecord::Migration[7.1]
|
17
20
|
def change
|
18
21
|
create_table :rules, id: :string, if_not_exists: true do |t|
|
@@ -125,6 +128,9 @@ def schemas
|
|
125
128
|
end
|
126
129
|
|
127
130
|
module Mihari
|
131
|
+
#
|
132
|
+
# Database
|
133
|
+
#
|
128
134
|
class Database
|
129
135
|
class << self
|
130
136
|
#
|
data/lib/mihari/emitters/base.rb
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
+
#
|
6
|
+
# Base class for emitters
|
7
|
+
#
|
5
8
|
class Base < Actor
|
6
9
|
# @return [Mihari::Rule]
|
7
10
|
attr_reader :rule
|
@@ -9,9 +12,8 @@ module Mihari
|
|
9
12
|
#
|
10
13
|
# @param [Mihari::Rule] rule
|
11
14
|
# @param [Hash, nil] options
|
12
|
-
# @param [Hash] **_params
|
13
15
|
#
|
14
|
-
def initialize(rule:, options: nil
|
16
|
+
def initialize(rule:, options: nil)
|
15
17
|
super(options: options)
|
16
18
|
|
17
19
|
@rule = rule
|
@@ -20,23 +22,23 @@ module Mihari
|
|
20
22
|
#
|
21
23
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
22
24
|
#
|
23
|
-
def
|
25
|
+
def call(artifacts)
|
26
|
+
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# @return [Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure]
|
31
|
+
#
|
32
|
+
def result(artifacts)
|
24
33
|
Try[StandardError] do
|
25
34
|
retry_on_error(
|
26
35
|
times: retry_times,
|
27
36
|
interval: retry_interval,
|
28
37
|
exponential_backoff: retry_exponential_backoff
|
29
|
-
) {
|
38
|
+
) { call(artifacts) }
|
30
39
|
end.to_result
|
31
40
|
end
|
32
41
|
|
33
|
-
#
|
34
|
-
# @param [Array<Mihari::Models::Artifact>] artifacts
|
35
|
-
#
|
36
|
-
def emit(artifacts)
|
37
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
38
|
-
end
|
39
|
-
|
40
42
|
class << self
|
41
43
|
def inherited(child)
|
42
44
|
super
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Emitters
|
5
|
+
#
|
6
|
+
# Database emitter
|
7
|
+
#
|
5
8
|
class Database < Base
|
6
9
|
#
|
7
10
|
# Create an alert
|
@@ -10,7 +13,7 @@ module Mihari
|
|
10
13
|
#
|
11
14
|
# @return [Mihari::Models::Alert, nil]
|
12
15
|
#
|
13
|
-
def
|
16
|
+
def call(artifacts)
|
14
17
|
return if artifacts.empty?
|
15
18
|
|
16
19
|
tags = rule.tags.filter_map { |name| Models::Tag.find_or_create_by(name: name) }.uniq
|
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,16 +12,16 @@ module Mihari
|
|
9
12
|
# @return [String, nil]
|
10
13
|
attr_reader :api_key
|
11
14
|
|
12
|
-
# @return [Mihari::
|
15
|
+
# @return [Mihari::Rule]
|
13
16
|
attr_reader :rule
|
14
17
|
|
15
18
|
# @return [Array<Mihari::Models::Artifact>]
|
16
19
|
attr_accessor :artifacts
|
17
20
|
|
18
21
|
#
|
19
|
-
# @param [Mihari::
|
22
|
+
# @param [Mihari::Rule] rule
|
20
23
|
# @param [Hash, nil] options
|
21
|
-
# @param [Hash]
|
24
|
+
# @param [Hash, nil] params
|
22
25
|
#
|
23
26
|
def initialize(rule:, options: nil, **params)
|
24
27
|
super(rule: rule, options: options)
|
@@ -41,7 +44,7 @@ module Mihari
|
|
41
44
|
#
|
42
45
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
43
46
|
#
|
44
|
-
def
|
47
|
+
def call(artifacts)
|
45
48
|
return if artifacts.empty?
|
46
49
|
|
47
50
|
client.create_event({
|
@@ -135,9 +135,9 @@ module Mihari
|
|
135
135
|
attr_accessor :artifacts
|
136
136
|
|
137
137
|
#
|
138
|
-
# @param [Mihari::
|
138
|
+
# @param [Mihari::Rule] rule
|
139
139
|
# @param [Hash, nil] options
|
140
|
-
# @param [Hash]
|
140
|
+
# @param [Hash, nil] params
|
141
141
|
#
|
142
142
|
def initialize(rule:, options: nil, **params)
|
143
143
|
super(rule: rule, options: options)
|
@@ -216,7 +216,7 @@ module Mihari
|
|
216
216
|
#
|
217
217
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
218
218
|
#
|
219
|
-
def
|
219
|
+
def call(artifacts)
|
220
220
|
return if artifacts.empty?
|
221
221
|
|
222
222
|
@artifacts = artifacts
|
@@ -16,9 +16,9 @@ module Mihari
|
|
16
16
|
attr_accessor :artifacts
|
17
17
|
|
18
18
|
#
|
19
|
-
# @param [Mihari::
|
19
|
+
# @param [Mihari::Rule] rule
|
20
20
|
# @param [Hash, nil] options
|
21
|
-
# @param [Hash]
|
21
|
+
# @param [Hash] params
|
22
22
|
#
|
23
23
|
def initialize(rule:, options: nil, **params)
|
24
24
|
super(rule: rule, options: options)
|
@@ -42,7 +42,7 @@ module Mihari
|
|
42
42
|
#
|
43
43
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
44
44
|
#
|
45
|
-
def
|
45
|
+
def call(artifacts)
|
46
46
|
return if artifacts.empty?
|
47
47
|
|
48
48
|
@artifacts = artifacts
|
@@ -61,8 +61,9 @@ module Mihari
|
|
61
61
|
attr_accessor :artifacts
|
62
62
|
|
63
63
|
#
|
64
|
-
# @param [Mihari::
|
65
|
-
# @param [Hash]
|
64
|
+
# @param [Mihari::Rule] rule
|
65
|
+
# @param [Hash, nil] options
|
66
|
+
# @param [Hash, nil] params
|
66
67
|
#
|
67
68
|
def initialize(rule:, options: nil, **params)
|
68
69
|
super(rule: rule, options: options)
|
@@ -87,7 +88,7 @@ module Mihari
|
|
87
88
|
#
|
88
89
|
# @param [Array<Mihari::Models::Artifact>] artifacts
|
89
90
|
#
|
90
|
-
def
|
91
|
+
def call(artifacts)
|
91
92
|
return if artifacts.empty?
|
92
93
|
|
93
94
|
@artifacts = artifacts
|
@@ -2,28 +2,34 @@
|
|
2
2
|
|
3
3
|
module Mihari
|
4
4
|
module Enrichers
|
5
|
+
#
|
6
|
+
# Base class for enrichers
|
7
|
+
#
|
5
8
|
class Base < Actor
|
6
9
|
def initialize(options: nil)
|
7
10
|
super(options: options)
|
8
11
|
end
|
9
12
|
|
10
|
-
|
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)
|
11
24
|
Try[StandardError] do
|
12
25
|
retry_on_error(
|
13
26
|
times: retry_times,
|
14
27
|
interval: retry_interval,
|
15
28
|
exponential_backoff: retry_exponential_backoff
|
16
|
-
) {
|
29
|
+
) { call value }
|
17
30
|
end.to_result
|
18
31
|
end
|
19
32
|
|
20
|
-
#
|
21
|
-
# @param [String] value
|
22
|
-
#
|
23
|
-
def query(value)
|
24
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
25
|
-
end
|
26
|
-
|
27
33
|
class << self
|
28
34
|
def inherited(child)
|
29
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
|
@@ -27,16 +28,17 @@ module Mihari
|
|
27
28
|
#
|
28
29
|
# @param [String] ip
|
29
30
|
#
|
30
|
-
# @return [Mihari::Structs::IPInfo::Response
|
31
|
+
# @return [Mihari::Structs::IPInfo::Response]
|
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
|
|