mihari 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/README.md +1 -1
- data/Rakefile +5 -0
- data/config.ru +0 -1
- data/lib/mihari/analyzers/base.rb +18 -10
- data/lib/mihari/analyzers/rule.rb +1 -1
- data/lib/mihari/cli/base.rb +0 -4
- data/lib/mihari/commands/init.rb +1 -1
- data/lib/mihari/commands/search.rb +11 -58
- data/lib/mihari/commands/validator.rb +1 -2
- data/lib/mihari/database.rb +1 -1
- data/lib/mihari/emitters/base.rb +5 -2
- data/lib/mihari/emitters/slack.rb +40 -4
- data/lib/mihari/enrichers/base.rb +5 -2
- data/lib/mihari/enrichers/ipinfo.rb +4 -3
- data/lib/mihari/{web/entities → entities}/alert.rb +0 -0
- data/lib/mihari/{web/entities → entities}/artifact.rb +0 -0
- data/lib/mihari/{web/entities → entities}/autonomous_system.rb +0 -0
- data/lib/mihari/{web/entities → entities}/command.rb +0 -0
- data/lib/mihari/{web/entities → entities}/config.rb +0 -0
- data/lib/mihari/{web/entities → entities}/dns.rb +0 -0
- data/lib/mihari/{web/entities → entities}/geolocation.rb +0 -0
- data/lib/mihari/{web/entities → entities}/ip_address.rb +0 -0
- data/lib/mihari/{web/entities → entities}/message.rb +0 -0
- data/lib/mihari/{web/entities → entities}/reverse_dns.rb +0 -0
- data/lib/mihari/{web/entities → entities}/rule.rb +0 -0
- data/lib/mihari/{web/entities → entities}/source.rb +0 -0
- data/lib/mihari/{web/entities → entities}/tag.rb +0 -0
- data/lib/mihari/{web/entities → entities}/whois.rb +0 -0
- data/lib/mihari/errors.rb +2 -0
- data/lib/mihari/feed/reader.rb +11 -55
- data/lib/mihari/http.rb +94 -0
- data/lib/mihari/mixins/error_notification.rb +20 -0
- data/lib/mihari/mixins/retriable.rb +12 -2
- data/lib/mihari/mixins/rule.rb +1 -2
- data/lib/mihari/structs/ipinfo.rb +2 -3
- data/lib/mihari/structs/rule.rb +30 -0
- data/lib/mihari/structs/shodan.rb +9 -1
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/api.rb +0 -20
- data/lib/mihari/web/app.rb +3 -3
- data/lib/mihari/web/endpoints/rules.rb +3 -1
- data/lib/mihari/web/middleware/error_notification_adapter.rb +19 -0
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari/web/public/redoc-static.html +1881 -165
- data/lib/mihari/web/public/static/css/app.43138058.css +1 -0
- data/lib/mihari/web/public/static/css/chunk-vendors.3ed9b08e.css +7 -0
- data/lib/mihari/web/public/static/fonts/fa-brands-400.1fd0b4d7.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-brands-400.5d5236fb.woff2 +0 -0
- data/lib/mihari/web/public/static/fonts/fa-regular-400.64b3730e.woff2 +0 -0
- data/lib/mihari/web/public/static/fonts/fa-regular-400.95a8a8af.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-solid-900.6115ad71.woff2 +0 -0
- data/lib/mihari/web/public/static/fonts/fa-solid-900.f0203cfc.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-v4compatibility.e1023515.ttf +0 -0
- data/lib/mihari/web/public/static/js/app-legacy.46b666f0.js +2 -0
- data/lib/mihari/web/public/static/js/app-legacy.46b666f0.js.map +1 -0
- data/lib/mihari/web/public/static/js/app.4818aedd.js +2 -0
- data/lib/mihari/web/public/static/js/app.4818aedd.js.map +1 -0
- data/lib/mihari/web/public/static/js/app.b88ce341.js +35 -0
- data/lib/mihari/web/public/static/js/app.b88ce341.js.map +1 -0
- data/lib/mihari/web/public/static/js/chunk-vendors-legacy.c99e452e.js +17 -0
- data/lib/mihari/web/public/static/js/chunk-vendors-legacy.c99e452e.js.map +1 -0
- data/lib/mihari/web/public/static/js/chunk-vendors.15e84e22.js +23 -0
- data/lib/mihari/web/public/static/js/chunk-vendors.15e84e22.js.map +1 -0
- data/lib/mihari.rb +63 -15
- data/mihari.gemspec +12 -12
- data/sig/lib/mihari/emitters/slack.rbs +29 -1
- data/sig/lib/mihari/feed/reader.rbs +2 -2
- data/sig/lib/mihari/http.rbs +65 -0
- data/sig/lib/mihari/mixins/error_notification.rbs +12 -0
- data/sig/lib/mihari/structs/rule.rbs +6 -0
- data/sig/lib/mihari.rbs +4 -8
- metadata +88 -73
- data/lib/mihari/cli/mixins/utils.rb +0 -72
- data/lib/mihari/emitters/stdout.rb +0 -22
- data/lib/mihari/notifiers/base.rb +0 -24
- data/lib/mihari/notifiers/exception_notifier.rb +0 -126
- data/lib/mihari/notifiers/slack.rb +0 -63
- data/sig/lib/mihari/cli/mixins/utils.rbs +0 -50
- data/sig/lib/mihari/notifiers/base.rbs +0 -18
- data/sig/lib/mihari/notifiers/exception_notifier.rbs +0 -75
- data/sig/lib/mihari/notifiers/slack.rbs +0 -50
data/lib/mihari.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# standard libs
|
4
|
+
require "ipaddr"
|
5
|
+
require "json"
|
6
|
+
require "net/http"
|
7
|
+
require "net/https"
|
8
|
+
require "resolv"
|
9
|
+
require "yaml"
|
10
|
+
|
11
|
+
# Active Support & Active Record
|
3
12
|
require "active_support"
|
4
13
|
|
5
14
|
require "active_support/core_ext/hash"
|
@@ -17,23 +26,22 @@ require "dry/struct"
|
|
17
26
|
require "dry/types"
|
18
27
|
require "dry/validation"
|
19
28
|
|
20
|
-
#
|
29
|
+
# Grape
|
30
|
+
require "grape"
|
31
|
+
require "grape-entity"
|
32
|
+
|
33
|
+
# Other utility libs
|
21
34
|
require "addressable/uri"
|
22
35
|
require "awrence"
|
23
|
-
require "colorize"
|
24
36
|
require "email_address"
|
25
|
-
require "ipaddr"
|
26
|
-
require "json"
|
27
37
|
require "memist"
|
28
|
-
require "net/http"
|
29
|
-
require "net/https"
|
30
38
|
require "net/ping"
|
39
|
+
require "parallel"
|
31
40
|
require "plissken"
|
32
41
|
require "public_suffix"
|
33
|
-
require "
|
42
|
+
require "semantic_logger"
|
43
|
+
require "sentry-ruby"
|
34
44
|
require "uuidtools"
|
35
|
-
require "yaml"
|
36
|
-
require "parallel"
|
37
45
|
|
38
46
|
# Load .env
|
39
47
|
require "dotenv/load"
|
@@ -47,6 +55,7 @@ require "mihari/mixins/autonomous_system"
|
|
47
55
|
require "mihari/mixins/configurable"
|
48
56
|
require "mihari/mixins/database"
|
49
57
|
require "mihari/mixins/disallowed_data_value"
|
58
|
+
require "mihari/mixins/error_notification"
|
50
59
|
require "mihari/mixins/refang"
|
51
60
|
require "mihari/mixins/retriable"
|
52
61
|
require "mihari/mixins/rule"
|
@@ -88,6 +97,7 @@ module Mihari
|
|
88
97
|
setting :webhook_url, default: ENV["WEBHOOK_URL"]
|
89
98
|
setting :webhook_use_json_body, constructor: ->(value = ENV["WEBHOOK_USE_JSON_BODY"]) { truthy?(value) }
|
90
99
|
setting :zoomeye_api_key, default: ENV["ZOOMEYE_API_KEY"]
|
100
|
+
setting :sentry_dsn, default: ENV["SENTRY_DSN"]
|
91
101
|
|
92
102
|
class << self
|
93
103
|
include Memist::Memoizable
|
@@ -106,12 +116,32 @@ module Mihari
|
|
106
116
|
[]
|
107
117
|
end
|
108
118
|
memoize :enrichers
|
119
|
+
|
120
|
+
def logger
|
121
|
+
SemanticLogger.default_level = :info
|
122
|
+
SemanticLogger.add_appender(io: $stderr, formatter: :color)
|
123
|
+
SemanticLogger["Mihari"]
|
124
|
+
end
|
125
|
+
memoize :logger
|
126
|
+
|
127
|
+
def initialize_sentry
|
128
|
+
return if Mihari.config.sentry_dsn.nil?
|
129
|
+
return if Sentry.initialized?
|
130
|
+
|
131
|
+
Sentry.init do |config|
|
132
|
+
config.dsn = Mihari.config.sentry_dsn
|
133
|
+
|
134
|
+
config.traces_sample_rate = 0.5
|
135
|
+
end
|
136
|
+
end
|
109
137
|
end
|
110
138
|
end
|
111
139
|
|
112
140
|
require "mihari/database"
|
113
141
|
require "mihari/type_checker"
|
114
142
|
|
143
|
+
require "mihari/http"
|
144
|
+
|
115
145
|
# Constants
|
116
146
|
require "mihari/constants"
|
117
147
|
|
@@ -175,20 +205,35 @@ require "mihari/analyzers/virustotal"
|
|
175
205
|
require "mihari/analyzers/zoomeye"
|
176
206
|
require "mihari/analyzers/rule"
|
177
207
|
|
178
|
-
# Notifiers
|
179
|
-
require "mihari/notifiers/base"
|
180
|
-
require "mihari/notifiers/slack"
|
181
|
-
require "mihari/notifiers/exception_notifier"
|
182
|
-
|
183
208
|
# Emitters
|
184
209
|
require "mihari/emitters/base"
|
185
210
|
require "mihari/emitters/database"
|
186
211
|
require "mihari/emitters/misp"
|
187
212
|
require "mihari/emitters/slack"
|
188
|
-
require "mihari/emitters/stdout"
|
189
213
|
require "mihari/emitters/the_hive"
|
190
214
|
require "mihari/emitters/webhook"
|
191
215
|
|
216
|
+
# Entities
|
217
|
+
|
218
|
+
require "mihari/entities/message"
|
219
|
+
|
220
|
+
require "mihari/entities/autonomous_system"
|
221
|
+
require "mihari/entities/command"
|
222
|
+
require "mihari/entities/config"
|
223
|
+
require "mihari/entities/dns"
|
224
|
+
require "mihari/entities/geolocation"
|
225
|
+
require "mihari/entities/ip_address"
|
226
|
+
require "mihari/entities/reverse_dns"
|
227
|
+
require "mihari/entities/source"
|
228
|
+
require "mihari/entities/tag"
|
229
|
+
require "mihari/entities/whois"
|
230
|
+
|
231
|
+
require "mihari/entities/artifact"
|
232
|
+
|
233
|
+
require "mihari/entities/alert"
|
234
|
+
|
235
|
+
require "mihari/entities/rule"
|
236
|
+
|
192
237
|
# Status checker
|
193
238
|
require "mihari/status"
|
194
239
|
|
@@ -197,3 +242,6 @@ require "mihari/web/app"
|
|
197
242
|
|
198
243
|
# CLIs
|
199
244
|
require "mihari/cli/main"
|
245
|
+
|
246
|
+
# initialize Sentry
|
247
|
+
Mihari.initialize_sentry
|
data/mihari.gemspec
CHANGED
@@ -30,24 +30,23 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "fakefs", "~> 1.4"
|
31
31
|
spec.add_development_dependency "mysql2", "~> 0.5"
|
32
32
|
spec.add_development_dependency "overcommit", "~> 0.58"
|
33
|
-
spec.add_development_dependency "pg", "~> 1.
|
33
|
+
spec.add_development_dependency "pg", "~> 1.3"
|
34
34
|
spec.add_development_dependency "rack-test", "~> 1.1"
|
35
35
|
spec.add_development_dependency "rake", "~> 13.0"
|
36
36
|
spec.add_development_dependency "rb-fsevent", "~> 0.11"
|
37
37
|
spec.add_development_dependency "rerun", "~> 0.13"
|
38
|
-
spec.add_development_dependency "rspec", "~> 3.
|
39
|
-
spec.add_development_dependency "standard", "~> 1.
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.11"
|
39
|
+
spec.add_development_dependency "standard", "~> 1.7"
|
40
40
|
spec.add_development_dependency "steep", "~> 0.47"
|
41
41
|
spec.add_development_dependency "timecop", "~> 0.9"
|
42
42
|
spec.add_development_dependency "vcr", "~> 6.0"
|
43
43
|
spec.add_development_dependency "webmock", "~> 3.14"
|
44
44
|
|
45
|
-
spec.add_dependency "activerecord", "7.0.
|
45
|
+
spec.add_dependency "activerecord", "7.0.2.2"
|
46
46
|
spec.add_dependency "addressable", "~> 2.8"
|
47
|
-
spec.add_dependency "awrence", "~>
|
47
|
+
spec.add_dependency "awrence", "~> 2.0"
|
48
48
|
spec.add_dependency "binaryedge", "~> 0.1"
|
49
49
|
spec.add_dependency "censysx", "~> 0.1"
|
50
|
-
spec.add_dependency "colorize", "~> 0.8"
|
51
50
|
spec.add_dependency "crtsh-rb", "~> 0.3"
|
52
51
|
spec.add_dependency "dnpedia", "~> 0.1"
|
53
52
|
spec.add_dependency "dnstwister", "~> 0.1"
|
@@ -57,7 +56,7 @@ Gem::Specification.new do |spec|
|
|
57
56
|
spec.add_dependency "dry-files", "0.1.0"
|
58
57
|
spec.add_dependency "dry-initializer", "3.1.1"
|
59
58
|
spec.add_dependency "dry-struct", "1.4.0"
|
60
|
-
spec.add_dependency "dry-validation", "1.
|
59
|
+
spec.add_dependency "dry-validation", "1.8.0"
|
61
60
|
spec.add_dependency "email_address", "~> 0.2"
|
62
61
|
spec.add_dependency "grape", "1.6.2"
|
63
62
|
spec.add_dependency "grape-entity", "0.10.1"
|
@@ -65,32 +64,33 @@ Gem::Specification.new do |spec|
|
|
65
64
|
spec.add_dependency "grape-swagger-entity", "0.5.1"
|
66
65
|
spec.add_dependency "greynoise", "~> 0.1"
|
67
66
|
spec.add_dependency "hachi", "~> 1.0"
|
68
|
-
spec.add_dependency "http", "~> 5.0"
|
69
67
|
spec.add_dependency "jr-cli", "~> 0.5"
|
70
68
|
spec.add_dependency "launchy", "~> 2.5"
|
71
69
|
spec.add_dependency "memist", "~> 2.0"
|
72
70
|
spec.add_dependency "misp", "~> 0.1"
|
73
71
|
spec.add_dependency "net-ping", "~> 2.0"
|
74
|
-
spec.add_dependency "normalize_country", "0.3"
|
72
|
+
spec.add_dependency "normalize_country", "~> 0.3"
|
75
73
|
spec.add_dependency "onyphe", "~> 2.0"
|
76
74
|
spec.add_dependency "otx_ruby", "~> 0.9"
|
77
75
|
spec.add_dependency "parallel", "~> 1.21"
|
78
76
|
spec.add_dependency "passive_circl", "~> 0.1"
|
79
77
|
spec.add_dependency "passivetotalx", "~> 0.1"
|
80
|
-
spec.add_dependency "plissken", "~>
|
78
|
+
spec.add_dependency "plissken", "~> 2.0"
|
81
79
|
spec.add_dependency "public_suffix", "~> 4.0"
|
82
80
|
spec.add_dependency "pulsedive", "~> 0.1"
|
83
|
-
spec.add_dependency "puma", "5.
|
81
|
+
spec.add_dependency "puma", "5.6.2"
|
84
82
|
spec.add_dependency "rack", "2.2.3"
|
85
83
|
spec.add_dependency "rack-contrib", "2.3.0"
|
86
84
|
spec.add_dependency "rack-cors", "~> 1.1"
|
87
85
|
spec.add_dependency "safe_shell", "~> 1.1"
|
88
86
|
spec.add_dependency "securitytrails", "~> 1.0"
|
87
|
+
spec.add_dependency "semantic_logger", "~> 4.10"
|
88
|
+
spec.add_dependency "sentry-ruby", "~> 5.1.1"
|
89
89
|
spec.add_dependency "shodanx", "~> 0.2"
|
90
90
|
spec.add_dependency "slack-notifier", "~> 2.4"
|
91
91
|
spec.add_dependency "spysex", "~> 0.2"
|
92
92
|
spec.add_dependency "sqlite3", "~> 1.4"
|
93
|
-
spec.add_dependency "thor", "1.1
|
93
|
+
spec.add_dependency "thor", "1.2.1"
|
94
94
|
spec.add_dependency "thread_safe", "~> 0.3"
|
95
95
|
spec.add_dependency "urlscan", "~> 0.8"
|
96
96
|
spec.add_dependency "uuidtools", "~> 2.2"
|
@@ -39,7 +39,35 @@ module Mihari
|
|
39
39
|
end
|
40
40
|
|
41
41
|
class Slack < Base
|
42
|
-
|
42
|
+
SLACK_WEBHOOK_URL_KEY: ::String
|
43
|
+
|
44
|
+
SLACK_CHANNEL_KEY: ::String
|
45
|
+
|
46
|
+
DEFAULT_USERNAME: ::String
|
47
|
+
|
48
|
+
#
|
49
|
+
# Slack channel to post
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
#
|
53
|
+
def slack_channel: () -> String
|
54
|
+
|
55
|
+
#
|
56
|
+
# Slack webhook URL
|
57
|
+
#
|
58
|
+
# @return [String]
|
59
|
+
#
|
60
|
+
def slack_webhook_url: () -> String
|
61
|
+
|
62
|
+
#
|
63
|
+
# Check Slack webhook URL is set
|
64
|
+
#
|
65
|
+
# @return [Boolean]
|
66
|
+
#
|
67
|
+
def slack_webhook_url?: () -> bool
|
68
|
+
|
69
|
+
|
70
|
+
def notifier: () -> ::Slack::Notifier
|
43
71
|
|
44
72
|
def valid?: () -> bool
|
45
73
|
|
@@ -12,8 +12,8 @@ module Mihari
|
|
12
12
|
|
13
13
|
def initialize: (
|
14
14
|
String uri,
|
15
|
-
?http_request_headers: Hash[(String | Symbol), untyped]
|
16
|
-
?http_request_method:
|
15
|
+
?http_request_headers: Hash[(String | Symbol), untyped] http_request_headers,
|
16
|
+
?http_request_method: String http_request_method,
|
17
17
|
?http_request_payload_type: String? http_request_payload_type,
|
18
18
|
?http_request_payload: Hash[(String | Symbol), untyped] http_request_payload
|
19
19
|
) -> void
|
@@ -0,0 +1,65 @@
|
|
1
|
+
|
2
|
+
module Mihari
|
3
|
+
class HTTP
|
4
|
+
attr_reader uri: URI
|
5
|
+
|
6
|
+
attr_reader headers: Hash[(String | Symbol), untyped]
|
7
|
+
|
8
|
+
attr_reader payload_type: String?
|
9
|
+
|
10
|
+
attr_reader payload: Hash[(String | Symbol), untyped]
|
11
|
+
|
12
|
+
def initialize: (
|
13
|
+
String uri,
|
14
|
+
?headers: Hash[(String | Symbol), untyped] headers,
|
15
|
+
?payload_type: String? payload_type,
|
16
|
+
?payload: Hash[(String | Symbol), untyped] payload
|
17
|
+
) -> void
|
18
|
+
|
19
|
+
#
|
20
|
+
# Make a GET request
|
21
|
+
#
|
22
|
+
# @return [Net::HTTPResponse]
|
23
|
+
#
|
24
|
+
def get: () -> Net::HTTPResponse
|
25
|
+
|
26
|
+
#
|
27
|
+
# Make a POST request
|
28
|
+
#
|
29
|
+
# @return [Net::HTTPResponse]
|
30
|
+
#
|
31
|
+
def post: () -> Net::HTTPResponse
|
32
|
+
|
33
|
+
def self.get: (
|
34
|
+
String uri,
|
35
|
+
?headers: Hash[(String | Symbol), untyped] headers,
|
36
|
+
?payload_type: String? payload_type,
|
37
|
+
?payload: Hash[(String | Symbol), untyped] payload
|
38
|
+
) -> Net::HTTPResponse
|
39
|
+
|
40
|
+
def self.post: (
|
41
|
+
String uri,
|
42
|
+
?headers: Hash[(String | Symbol), untyped] headers,
|
43
|
+
?payload_type: String? payload_type,
|
44
|
+
?payload: Hash[(String | Symbol), untyped] payload
|
45
|
+
) -> Net::HTTPResponse
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
#
|
50
|
+
# Get options for HTTP request
|
51
|
+
#
|
52
|
+
# @return [Hahs]
|
53
|
+
#
|
54
|
+
def https_options: () -> ({ use_ssl: ::TrueClass } | ::Hash[untyped, untyped])
|
55
|
+
|
56
|
+
#
|
57
|
+
# Make a HTTP request
|
58
|
+
#
|
59
|
+
# @param [Net::HTTPRequest] req
|
60
|
+
#
|
61
|
+
# @return [Net::HTTPResponse]
|
62
|
+
#
|
63
|
+
def request: (untyped req) -> Net::HTTPResponse
|
64
|
+
end
|
65
|
+
end
|
@@ -50,6 +50,12 @@ module Mihari
|
|
50
50
|
# @return [Mihari::Rule]
|
51
51
|
#
|
52
52
|
def to_model: () -> Mihari::Rule
|
53
|
+
|
54
|
+
def to_analyzer: () -> Mihari::Analyzers::Rule
|
55
|
+
|
56
|
+
class << self
|
57
|
+
def from_model: (Mihari::Rule model) -> Mihari::Structs::Rule::Rule
|
58
|
+
end
|
53
59
|
end
|
54
60
|
end
|
55
61
|
end
|
data/sig/lib/mihari.rbs
CHANGED
@@ -25,6 +25,7 @@ class Configuration
|
|
25
25
|
attr_accessor webhook_url (): String?
|
26
26
|
attr_accessor webhook_use_json_body (): (bool | nil)
|
27
27
|
attr_accessor database (): String?
|
28
|
+
attr_accessor sentry_dsn(): String?
|
28
29
|
|
29
30
|
attr_reader values: Hash[(String | Symbol), String?]
|
30
31
|
end
|
@@ -42,14 +43,9 @@ module Mihari
|
|
42
43
|
|
43
44
|
def self.enrichers: () -> ::Array[singleton(Mihari::Enrichers::Base)]
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# @param [String] path Path to YAML file
|
49
|
-
#
|
50
|
-
# @return [nil]
|
51
|
-
#
|
52
|
-
def self.load_config_from_yaml: (String path) -> void
|
46
|
+
def self.logger: () -> SemanticLogger
|
47
|
+
|
48
|
+
def self.initialize_sentry: () -> void
|
53
49
|
end
|
54
50
|
|
55
51
|
class Object
|