mihari 5.0.0 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/docker/Dockerfile +1 -1
- data/lib/mihari/analyzers/base.rb +6 -9
- data/lib/mihari/cli/database.rb +11 -0
- data/lib/mihari/cli/main.rb +10 -4
- data/lib/mihari/cli/rule.rb +11 -0
- data/lib/mihari/commands/database.rb +28 -0
- data/lib/mihari/commands/{initializer.rb → rule.rb} +27 -6
- data/lib/mihari/commands/searcher.rb +36 -26
- data/lib/mihari/database.rb +8 -22
- data/lib/mihari/mixins/database.rb +2 -0
- data/lib/mihari/structs/rule.rb +2 -6
- data/lib/mihari/version.rb +1 -1
- data/mihari.gemspec +1 -0
- metadata +20 -4
- data/lib/mihari/commands/validator.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9481229c15756515053bbc91453db90d914e40e5f536d0b5aaad0f2b8fff5868
|
4
|
+
data.tar.gz: 1ea1f9caa3dbb1f945f4a3ba9f9af17c80c786594692de1564ca4f76692fa628
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f13bb894b69d4c92b03afc30fcce1be95ba1af1b0cb963c553a328fb85f771c852ee5526af751a098dd4f1b69c60592f021a0e3ee7e40004856d1d4eabc53aba
|
7
|
+
data.tar.gz: 751ad7fc17f2db38961e835f8c9b2a325cbf82692df65ef29c638bcf3eec9cbc17905a39bcbcf5a53bcf477adbf6080a23aa40702b3fb5a55727038eefe9b09d
|
data/.rspec
CHANGED
data/docker/Dockerfile
CHANGED
@@ -9,7 +9,6 @@ module Mihari
|
|
9
9
|
|
10
10
|
include Mixins::AutonomousSystem
|
11
11
|
include Mixins::Configurable
|
12
|
-
include Mixins::Database
|
13
12
|
include Mixins::Retriable
|
14
13
|
|
15
14
|
# @return [Mihari::Structs::Rule, nil]
|
@@ -42,16 +41,14 @@ module Mihari
|
|
42
41
|
raise ConfigurationError, "#{class_name} is not configured correctly"
|
43
42
|
end
|
44
43
|
|
45
|
-
|
46
|
-
set_enriched_artifacts
|
44
|
+
set_enriched_artifacts
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
# returns Mihari::Alert created by the database emitter
|
53
|
-
responses.find { |res| res.is_a?(Mihari::Alert) }
|
46
|
+
responses = Parallel.map(valid_emitters) do |emitter|
|
47
|
+
run_emitter emitter
|
54
48
|
end
|
49
|
+
|
50
|
+
# returns Mihari::Alert created by the database emitter
|
51
|
+
responses.find { |res| res.is_a?(Mihari::Alert) }
|
55
52
|
end
|
56
53
|
|
57
54
|
#
|
data/lib/mihari/cli/main.rb
CHANGED
@@ -3,23 +3,29 @@
|
|
3
3
|
require "thor"
|
4
4
|
|
5
5
|
# Commands
|
6
|
-
require "mihari/commands/initializer"
|
7
6
|
require "mihari/commands/searcher"
|
8
|
-
require "mihari/commands/validator"
|
9
7
|
require "mihari/commands/version"
|
10
8
|
require "mihari/commands/web"
|
9
|
+
require "mihari/commands/database"
|
11
10
|
|
12
11
|
# CLIs
|
13
12
|
require "mihari/cli/base"
|
14
13
|
|
14
|
+
require "mihari/cli/database"
|
15
|
+
require "mihari/cli/rule"
|
16
|
+
|
15
17
|
module Mihari
|
16
18
|
module CLI
|
17
19
|
class Main < Base
|
18
20
|
include Mihari::Commands::Searcher
|
19
21
|
include Mihari::Commands::Version
|
20
22
|
include Mihari::Commands::Web
|
21
|
-
|
22
|
-
|
23
|
+
|
24
|
+
desc "db", "Sub commands for DB"
|
25
|
+
subcommand "db", Database
|
26
|
+
|
27
|
+
desc "rule", "Sub commands for rule"
|
28
|
+
subcommand "rule", Rule
|
23
29
|
end
|
24
30
|
end
|
25
31
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mihari
|
4
|
+
module Commands
|
5
|
+
module Database
|
6
|
+
include Mixins::Database
|
7
|
+
|
8
|
+
def self.included(thor)
|
9
|
+
thor.class_eval do
|
10
|
+
desc "migrate", "Migrate DB schemas"
|
11
|
+
method_option :verbose, type: :boolean, default: true
|
12
|
+
#
|
13
|
+
# @param [String] direction
|
14
|
+
#
|
15
|
+
#
|
16
|
+
def migrate(direction = "up")
|
17
|
+
verbose = options["verbose"]
|
18
|
+
ActiveRecord::Migration.verbose = verbose
|
19
|
+
|
20
|
+
with_db_connection do
|
21
|
+
Mihari::Database.migrate(direction.to_sym)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -4,20 +4,41 @@ require "pathname"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Commands
|
7
|
-
module
|
7
|
+
module Rule
|
8
8
|
def self.included(thor)
|
9
9
|
thor.class_eval do
|
10
|
-
desc "
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
desc "validate [PATH]", "Validate a rule file"
|
11
|
+
#
|
12
|
+
# Validate format of a rule
|
13
|
+
#
|
14
|
+
# @param [String] path
|
15
|
+
#
|
16
|
+
def validate(path)
|
17
|
+
rule = Structs::Rule.from_path_or_id(path)
|
14
18
|
|
19
|
+
begin
|
20
|
+
rule.validate!
|
21
|
+
Mihari.logger.info "Valid format. The input is parsed as the following:"
|
22
|
+
Mihari.logger.info rule.data.to_yaml
|
23
|
+
rescue RuleValidationError
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "init [PATH]", "Initialize a new rule file"
|
29
|
+
#
|
30
|
+
# Initialize a new rule file
|
31
|
+
#
|
32
|
+
# @param [String] path
|
33
|
+
#
|
34
|
+
#
|
35
|
+
def init(path = "./rule.yml")
|
15
36
|
warning = "#{path} exists. Do you want to overwrite it? (y/n)"
|
16
37
|
return if Pathname(path).exist? && !(yes? warning)
|
17
38
|
|
18
39
|
initialize_rule path
|
19
40
|
|
20
|
-
Mihari.logger.info "A new rule is initialized
|
41
|
+
Mihari.logger.info "A new rule is initialized: #{path}."
|
21
42
|
end
|
22
43
|
|
23
44
|
no_commands do
|
@@ -9,39 +9,49 @@ module Mihari
|
|
9
9
|
def self.included(thor)
|
10
10
|
thor.class_eval do
|
11
11
|
desc "search [PATH]", "Search by a rule"
|
12
|
-
method_option :
|
12
|
+
method_option :force_overwrite, type: :boolean, aliases: "-f", desc: "Force an overwrite the rule"
|
13
|
+
#
|
14
|
+
# Search by a rule
|
15
|
+
#
|
16
|
+
# @param [String] path_or_id
|
17
|
+
#
|
13
18
|
def search(path_or_id)
|
14
|
-
|
19
|
+
with_db_connection do
|
20
|
+
rule = Structs::Rule.from_path_or_id path_or_id
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
+
# validate
|
23
|
+
begin
|
24
|
+
rule.validate!
|
25
|
+
rescue RuleValidationError
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
force_overwrite = options["force_overwrite"] || false
|
30
|
+
|
31
|
+
begin
|
32
|
+
rule_model = Mihari::Rule.find(rule.id)
|
33
|
+
has_change = rule_model.data != rule.data.deep_stringify_keys
|
34
|
+
has_change_and_not_force_overwrite = has_change & !force_overwrite
|
22
35
|
|
23
|
-
|
24
|
-
yes = options["yes"] || false
|
25
|
-
unless yes
|
26
|
-
with_db_connection do
|
27
|
-
next if Mihari::Rule.find(rule.id).data == rule.data.deep_stringify_keys
|
28
|
-
unless yes?("This operation will overwrite the rule in the database (Rule ID: #{rule.id}). Are you sure you want to update the rule? (y/n)")
|
36
|
+
if has_change_and_not_force_overwrite && !yes?("This operation will overwrite the rule in the database (Rule ID: #{rule.id}). Are you sure you want to update the rule? (y/n)")
|
29
37
|
return
|
30
38
|
end
|
39
|
+
|
40
|
+
# update the rule
|
41
|
+
rule.model.save
|
31
42
|
rescue ActiveRecord::RecordNotFound
|
32
|
-
|
43
|
+
# create a new rule
|
44
|
+
rule.model.save
|
33
45
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
else
|
44
|
-
Mihari.logger.info "There is no new alert created in the database"
|
46
|
+
|
47
|
+
with_error_notification do
|
48
|
+
alert = rule.analyzer.run
|
49
|
+
if alert
|
50
|
+
data = Mihari::Entities::Alert.represent(alert)
|
51
|
+
puts JSON.pretty_generate(data.as_json)
|
52
|
+
else
|
53
|
+
Mihari.logger.info "There is no new alert created in the database"
|
54
|
+
end
|
45
55
|
end
|
46
56
|
end
|
47
57
|
end
|
data/lib/mihari/database.rb
CHANGED
@@ -9,10 +9,6 @@ def env
|
|
9
9
|
ENV["APP_ENV"] || ENV["RACK_ENV"]
|
10
10
|
end
|
11
11
|
|
12
|
-
def test_env?
|
13
|
-
env == "test"
|
14
|
-
end
|
15
|
-
|
16
12
|
def development_env?
|
17
13
|
env == "development"
|
18
14
|
end
|
@@ -121,22 +117,24 @@ def adapter
|
|
121
117
|
"sqlite3"
|
122
118
|
end
|
123
119
|
|
120
|
+
#
|
121
|
+
# @return [Array<ActiveRecord::Migration>] schemas
|
122
|
+
#
|
123
|
+
def schemas
|
124
|
+
[V5Schema]
|
125
|
+
end
|
126
|
+
|
124
127
|
module Mihari
|
125
128
|
class Database
|
126
129
|
class << self
|
127
|
-
include Memist::Memoizable
|
128
|
-
|
129
130
|
#
|
130
131
|
# DB migraration
|
131
132
|
#
|
132
133
|
# @param [Symbol] direction
|
133
134
|
#
|
134
135
|
def migrate(direction)
|
135
|
-
|
136
|
-
|
137
|
-
[V5Schema].each { |schema| schema.migrate direction }
|
136
|
+
schemas.each { |schema| schema.migrate direction }
|
138
137
|
end
|
139
|
-
memoize :migrate unless test_env?
|
140
138
|
|
141
139
|
#
|
142
140
|
# Establish DB connection
|
@@ -153,10 +151,7 @@ module Mihari
|
|
153
151
|
database: Mihari.config.database_url.path[1..]
|
154
152
|
)
|
155
153
|
end
|
156
|
-
|
157
154
|
ActiveRecord::Base.logger = Logger.new($stdout) if development_env?
|
158
|
-
|
159
|
-
migrate :up
|
160
155
|
rescue StandardError => e
|
161
156
|
Mihari.logger.error e
|
162
157
|
end
|
@@ -169,15 +164,6 @@ module Mihari
|
|
169
164
|
|
170
165
|
ActiveRecord::Base.clear_active_connections!
|
171
166
|
end
|
172
|
-
|
173
|
-
#
|
174
|
-
# Destory DB
|
175
|
-
#
|
176
|
-
def destroy!
|
177
|
-
return unless ActiveRecord::Base.connected?
|
178
|
-
|
179
|
-
migrate :down
|
180
|
-
end
|
181
167
|
end
|
182
168
|
end
|
183
169
|
end
|
data/lib/mihari/structs/rule.rb
CHANGED
@@ -164,8 +164,6 @@ module Mihari
|
|
164
164
|
end
|
165
165
|
|
166
166
|
class << self
|
167
|
-
include Mixins::Database
|
168
|
-
|
169
167
|
#
|
170
168
|
# Load rule from YAML string
|
171
169
|
#
|
@@ -209,11 +207,9 @@ module Mihari
|
|
209
207
|
# @return [Mihari::Structs::Rule, nil]
|
210
208
|
#
|
211
209
|
def from_id(id)
|
212
|
-
|
213
|
-
return nil unless Mihari::Rule.exists?(id)
|
210
|
+
return nil unless Mihari::Rule.exists?(id)
|
214
211
|
|
215
|
-
|
216
|
-
end
|
212
|
+
Structs::Rule.from_model Mihari::Rule.find(id)
|
217
213
|
end
|
218
214
|
|
219
215
|
#
|
data/lib/mihari/version.rb
CHANGED
data/mihari.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 2.4"
|
31
31
|
spec.add_development_dependency "coveralls_reborn", "~> 0.27"
|
32
32
|
spec.add_development_dependency "fakefs", "~> 2.4"
|
33
|
+
spec.add_development_dependency "fuubar", "~> 2.5"
|
33
34
|
spec.add_development_dependency "mysql2", "~> 0.5"
|
34
35
|
spec.add_development_dependency "overcommit", "~> 0.60"
|
35
36
|
spec.add_development_dependency "pg", "~> 1.4"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mihari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manabu Niseki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: fuubar
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.5'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: mysql2
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -1066,10 +1080,12 @@ files:
|
|
1066
1080
|
- lib/mihari/analyzers/virustotal_intelligence.rb
|
1067
1081
|
- lib/mihari/analyzers/zoomeye.rb
|
1068
1082
|
- lib/mihari/cli/base.rb
|
1083
|
+
- lib/mihari/cli/database.rb
|
1069
1084
|
- lib/mihari/cli/main.rb
|
1070
|
-
- lib/mihari/
|
1085
|
+
- lib/mihari/cli/rule.rb
|
1086
|
+
- lib/mihari/commands/database.rb
|
1087
|
+
- lib/mihari/commands/rule.rb
|
1071
1088
|
- lib/mihari/commands/searcher.rb
|
1072
|
-
- lib/mihari/commands/validator.rb
|
1073
1089
|
- lib/mihari/commands/version.rb
|
1074
1090
|
- lib/mihari/commands/web.rb
|
1075
1091
|
- lib/mihari/constants.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Mihari
|
4
|
-
module Commands
|
5
|
-
module Validator
|
6
|
-
def self.included(thor)
|
7
|
-
thor.class_eval do
|
8
|
-
desc "validate [PATH]", "Validate a rule file"
|
9
|
-
#
|
10
|
-
# Validate format of a rule
|
11
|
-
#
|
12
|
-
# @param [String] path
|
13
|
-
#
|
14
|
-
# @return [nil]
|
15
|
-
#
|
16
|
-
def validate(path)
|
17
|
-
rule = Structs::Rule.from_path_or_id(path)
|
18
|
-
|
19
|
-
begin
|
20
|
-
rule.validate!
|
21
|
-
Mihari.logger.info "Valid format. The input is parsed as the following:"
|
22
|
-
Mihari.logger.info rule.data.to_yaml
|
23
|
-
rescue RuleValidationError
|
24
|
-
nil
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|