mihari 3.4.0 → 3.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +3 -0
- data/README.md +2 -0
- data/Steepfile +32 -0
- data/config.ru +1 -0
- data/lib/mihari/analyzers/base.rb +39 -11
- data/lib/mihari/analyzers/binaryedge.rb +13 -0
- data/lib/mihari/analyzers/censys.rb +42 -9
- data/lib/mihari/analyzers/circl.rb +15 -0
- data/lib/mihari/analyzers/crtsh.rb +5 -0
- data/lib/mihari/analyzers/dnpedia.rb +5 -0
- data/lib/mihari/analyzers/dnstwister.rb +17 -0
- data/lib/mihari/analyzers/onyphe.rb +50 -9
- data/lib/mihari/analyzers/otx.rb +20 -0
- data/lib/mihari/analyzers/passivetotal.rb +25 -0
- data/lib/mihari/analyzers/pulsedive.rb +10 -0
- data/lib/mihari/analyzers/rule.rb +18 -0
- data/lib/mihari/analyzers/securitytrails.rb +25 -0
- data/lib/mihari/analyzers/shodan.rb +39 -5
- data/lib/mihari/analyzers/spyse.rb +20 -0
- data/lib/mihari/analyzers/urlscan.rb +10 -0
- data/lib/mihari/analyzers/virustotal.rb +20 -0
- data/lib/mihari/analyzers/zoomeye.rb +38 -0
- data/lib/mihari/cli/analyzer.rb +1 -0
- data/lib/mihari/cli/base.rb +0 -2
- data/lib/mihari/commands/init.rb +4 -4
- data/lib/mihari/commands/search.rb +1 -0
- data/lib/mihari/commands/web.rb +1 -0
- data/lib/mihari/{constraints.rb → constants.rb} +0 -0
- data/lib/mihari/database.rb +42 -3
- data/lib/mihari/emitters/base.rb +1 -1
- data/lib/mihari/emitters/misp.rb +38 -5
- data/lib/mihari/emitters/slack.rb +20 -2
- data/lib/mihari/emitters/the_hive.rb +16 -3
- data/lib/mihari/emitters/webhook.rb +18 -3
- data/lib/mihari/mixins/disallowed_data_value.rb +1 -1
- data/lib/mihari/models/alert.rb +28 -10
- data/lib/mihari/models/artifact.rb +55 -0
- data/lib/mihari/models/autonomous_system.rb +9 -0
- data/lib/mihari/models/dns.rb +53 -0
- data/lib/mihari/models/geolocation.rb +9 -0
- data/lib/mihari/models/reverse_dns.rb +24 -0
- data/lib/mihari/models/whois.rb +119 -0
- data/lib/mihari/schemas/configuration.rb +1 -0
- data/lib/mihari/schemas/rule.rb +2 -15
- data/lib/mihari/serializers/alert.rb +6 -4
- data/lib/mihari/serializers/artifact.rb +11 -2
- data/lib/mihari/serializers/autonomous_system.rb +9 -0
- data/lib/mihari/serializers/dns.rb +11 -0
- data/lib/mihari/serializers/geolocation.rb +11 -0
- data/lib/mihari/serializers/reverse_dns.rb +11 -0
- data/lib/mihari/serializers/tag.rb +4 -2
- data/lib/mihari/serializers/whois.rb +11 -0
- data/lib/mihari/structs/censys.rb +92 -0
- data/lib/mihari/structs/onyphe.rb +47 -0
- data/lib/mihari/structs/shodan.rb +53 -0
- data/lib/mihari/type_checker.rb +9 -9
- data/lib/mihari/types.rb +21 -0
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/app.rb +2 -0
- data/lib/mihari/web/controllers/alerts_controller.rb +3 -4
- data/lib/mihari/web/controllers/artifacts_controller.rb +46 -2
- data/lib/mihari/web/controllers/ip_address_controller.rb +36 -0
- data/lib/mihari/web/controllers/sources_controller.rb +2 -2
- data/lib/mihari/web/controllers/tags_controller.rb +3 -1
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari/web/public/redoc-static.html +12 -10
- data/lib/mihari/web/public/static/fonts/fa-brands-400.1a575a41.woff +0 -0
- data/lib/mihari/web/public/static/fonts/fa-brands-400.513aa607.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-brands-400.592643a8.eot +0 -0
- data/lib/mihari/web/public/static/fonts/fa-brands-400.ed311c7a.woff2 +0 -0
- data/lib/mihari/web/public/static/fonts/fa-regular-400.766913e6.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-regular-400.b0e2db3b.eot +0 -0
- data/lib/mihari/web/public/static/fonts/fa-regular-400.b91d376b.woff2 +0 -0
- data/lib/mihari/web/public/static/fonts/fa-regular-400.d1d7e3b4.woff +0 -0
- data/lib/mihari/web/public/static/fonts/fa-solid-900.0c6bfc66.eot +0 -0
- data/lib/mihari/web/public/static/fonts/fa-solid-900.b9625119.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-solid-900.d745348d.woff +0 -0
- data/lib/mihari/web/public/static/fonts/fa-solid-900.d824df7e.woff2 +0 -0
- data/lib/mihari/web/public/static/img/fa-brands-400.1d5619cd.svg +3717 -0
- data/lib/mihari/web/public/static/img/fa-regular-400.c5d109be.svg +801 -0
- data/lib/mihari/web/public/static/img/fa-solid-900.37bc7099.svg +5034 -0
- data/lib/mihari/web/public/static/js/app.8e3e5150.js +36 -0
- data/lib/mihari/web/public/static/js/app.8e3e5150.js.map +1 -0
- data/lib/mihari/web/public/static/js/app.b5914c39.js +36 -0
- data/lib/mihari/web/public/static/js/app.b5914c39.js.map +1 -0
- data/lib/mihari.rb +25 -4
- data/mihari.gemspec +10 -2
- data/sig/lib/mihari/analyzers/base.rbs +99 -0
- data/sig/lib/mihari/analyzers/basic.rbs +17 -0
- data/sig/lib/mihari/analyzers/binaryedge.rbs +25 -0
- data/sig/lib/mihari/analyzers/censys.rbs +38 -0
- data/sig/lib/mihari/analyzers/circl.rbs +29 -0
- data/sig/lib/mihari/analyzers/crtsh.rbs +19 -0
- data/sig/lib/mihari/analyzers/dnpedia.rbs +18 -0
- data/sig/lib/mihari/analyzers/dnstwister.rbs +27 -0
- data/sig/lib/mihari/analyzers/onyphe.rbs +33 -0
- data/sig/lib/mihari/analyzers/otx.rbs +33 -0
- data/sig/lib/mihari/analyzers/passivetotal.rbs +33 -0
- data/sig/lib/mihari/analyzers/pulsedive.rbs +27 -0
- data/sig/lib/mihari/analyzers/rule.rbs +68 -0
- data/sig/lib/mihari/analyzers/securitytrails.rbs +33 -0
- data/sig/lib/mihari/analyzers/shodan.rbs +33 -0
- data/sig/lib/mihari/analyzers/spyse.rbs +29 -0
- data/sig/lib/mihari/analyzers/urlscan.rbs +28 -0
- data/sig/lib/mihari/analyzers/virustotal.rbs +31 -0
- data/sig/lib/mihari/analyzers/zoomeye.rbs +33 -0
- data/sig/lib/mihari/cli/analyzer.rbs +39 -0
- data/sig/lib/mihari/cli/base.rbs +11 -0
- data/sig/lib/mihari/cli/init.rbs +7 -0
- data/sig/lib/mihari/cli/main.rbs +9 -0
- data/sig/lib/mihari/cli/mixins/utils.rbs +50 -0
- data/sig/lib/mihari/cli/validator.rbs +7 -0
- data/sig/lib/mihari/commands/binaryedge.rbs +7 -0
- data/sig/lib/mihari/commands/censys.rbs +7 -0
- data/sig/lib/mihari/commands/circl.rbs +7 -0
- data/sig/lib/mihari/commands/crtsh.rbs +7 -0
- data/sig/lib/mihari/commands/dnpedia.rbs +7 -0
- data/sig/lib/mihari/commands/dnstwister.rbs +7 -0
- data/sig/lib/mihari/commands/init.rbs +11 -0
- data/sig/lib/mihari/commands/json.rbs +7 -0
- data/sig/lib/mihari/commands/onyphe.rbs +7 -0
- data/sig/lib/mihari/commands/otx.rbs +7 -0
- data/sig/lib/mihari/commands/passivetotal.rbs +7 -0
- data/sig/lib/mihari/commands/pulsedive.rbs +7 -0
- data/sig/lib/mihari/commands/search.rbs +35 -0
- data/sig/lib/mihari/commands/securitytrails.rbs +7 -0
- data/sig/lib/mihari/commands/shodan.rbs +7 -0
- data/sig/lib/mihari/commands/spyse.rbs +7 -0
- data/sig/lib/mihari/commands/urlscan.rbs +7 -0
- data/sig/lib/mihari/commands/validator.rbs +11 -0
- data/sig/lib/mihari/commands/virustotal.rbs +7 -0
- data/sig/lib/mihari/commands/web.rbs +7 -0
- data/sig/lib/mihari/commands/zoomeye.rbs +7 -0
- data/sig/lib/mihari/constants.rbs +3 -0
- data/sig/lib/mihari/database.rbs +25 -0
- data/sig/lib/mihari/emitters/base.rbs +18 -0
- data/sig/lib/mihari/emitters/database.rbs +9 -0
- data/sig/lib/mihari/emitters/misp.rbs +28 -0
- data/sig/lib/mihari/emitters/slack.rbs +58 -0
- data/sig/lib/mihari/emitters/stdout.rbs +9 -0
- data/sig/lib/mihari/emitters/the_hive.rbs +24 -0
- data/sig/lib/mihari/emitters/webhook.rbs +20 -0
- data/sig/lib/mihari/errors.rbs +10 -0
- data/sig/lib/mihari/mixins/configurable.rbs +26 -0
- data/sig/lib/mihari/mixins/configuration.rbs +45 -0
- data/sig/lib/mihari/mixins/disallowed_data_value.rbs +25 -0
- data/sig/lib/mihari/mixins/hash.rbs +14 -0
- data/sig/lib/mihari/mixins/refang.rbs +14 -0
- data/sig/lib/mihari/mixins/retriable.rbs +15 -0
- data/sig/lib/mihari/mixins/rule.rbs +41 -0
- data/sig/lib/mihari/models/alert.rbs +46 -0
- data/sig/lib/mihari/models/artifact.rbs +54 -0
- data/sig/lib/mihari/models/autonomous_system.rbs +5 -0
- data/sig/lib/mihari/models/dns.rbs +19 -0
- data/sig/lib/mihari/models/geolocation.rbs +6 -0
- data/sig/lib/mihari/models/reverse_dns.rbs +14 -0
- data/sig/lib/mihari/models/tag.rbs +5 -0
- data/sig/lib/mihari/models/tagging.rbs +4 -0
- data/sig/lib/mihari/models/whois.rbs +66 -0
- data/sig/lib/mihari/notifiers/base.rbs +18 -0
- data/sig/lib/mihari/notifiers/exception_notifier.rbs +75 -0
- data/sig/lib/mihari/notifiers/slack.rbs +50 -0
- data/sig/lib/mihari/status.rbs +25 -0
- data/sig/lib/mihari/structs/censys.rbs +50 -0
- data/sig/lib/mihari/structs/onyphe.rbs +25 -0
- data/sig/lib/mihari/structs/shodan.rbs +28 -0
- data/sig/lib/mihari/type_checker.rbs +48 -0
- data/sig/lib/mihari/types.rbs +17 -0
- data/sig/lib/mihari/version.rbs +3 -0
- data/sig/lib/mihari/web/app.rbs +5 -0
- data/sig/lib/mihari.rbs +57 -0
- metadata +240 -8
data/lib/mihari/cli/analyzer.rb
CHANGED
@@ -24,6 +24,7 @@ module Mihari
|
|
24
24
|
class Analyzer < Base
|
25
25
|
class_option :ignore_old_artifacts, type: :boolean, default: false, desc: "Whether to ignore old artifacts from checking or not."
|
26
26
|
class_option :ignore_threshold, type: :numeric, default: 0, desc: "Number of days to define whether an artifact is old or not."
|
27
|
+
class_option :config, type: :string, desc: "Path to the config file"
|
27
28
|
|
28
29
|
include Mihari::Commands::BinaryEdge
|
29
30
|
include Mihari::Commands::Censys
|
data/lib/mihari/cli/base.rb
CHANGED
data/lib/mihari/commands/init.rb
CHANGED
@@ -5,10 +5,10 @@ require "colorize"
|
|
5
5
|
module Mihari
|
6
6
|
module Commands
|
7
7
|
module Initialization
|
8
|
-
|
9
|
-
|
10
|
-
include Mixins::Rule
|
8
|
+
include Mixins::Configuration
|
9
|
+
include Mixins::Rule
|
11
10
|
|
11
|
+
def self.included(thor)
|
12
12
|
thor.class_eval do
|
13
13
|
desc "config", "Create a config file"
|
14
14
|
method_option :filename, type: :string, default: "mihari.yml"
|
@@ -37,7 +37,7 @@ module Mihari
|
|
37
37
|
|
38
38
|
initialize_rule_yaml filename
|
39
39
|
|
40
|
-
puts "The rule file is
|
40
|
+
puts "The rule file is initialized as #{filename}.".colorize(:blue)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -8,6 +8,7 @@ module Mihari
|
|
8
8
|
def self.included(thor)
|
9
9
|
thor.class_eval do
|
10
10
|
desc "search [RULE]", "Search by a rule"
|
11
|
+
method_option :config, type: :string, desc: "Path to the config file"
|
11
12
|
def search_by_rule(rule)
|
12
13
|
# convert str(YAML) to hash or str(path/YAML file) to hash
|
13
14
|
rule = load_rule(rule)
|
data/lib/mihari/commands/web.rb
CHANGED
@@ -8,6 +8,7 @@ module Mihari
|
|
8
8
|
desc "web", "Launch the web app"
|
9
9
|
method_option :port, type: :numeric, default: 9292
|
10
10
|
method_option :host, type: :string, default: "localhost"
|
11
|
+
method_option :config, type: :string, desc: "Path to the config file"
|
11
12
|
def web
|
12
13
|
port = options["port"].to_i || 9292
|
13
14
|
host = options["host"] || "localhost"
|
File without changes
|
data/lib/mihari/database.rb
CHANGED
@@ -32,12 +32,48 @@ class InitialSchema < ActiveRecord::Migration[6.1]
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
class
|
35
|
+
class AddeSourceToArtifactSchema < ActiveRecord::Migration[6.1]
|
36
36
|
def change
|
37
37
|
add_column :artifacts, :source, :string, if_not_exists: true
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
class EnrichmentsSchema < ActiveRecord::Migration[6.1]
|
42
|
+
def change
|
43
|
+
create_table :autonomous_systems, if_not_exists: true do |t|
|
44
|
+
t.integer :asn, null: false
|
45
|
+
t.belongs_to :artifact, foreign_key: true
|
46
|
+
end
|
47
|
+
|
48
|
+
create_table :geolocations, if_not_exists: true do |t|
|
49
|
+
t.string :country, null: false
|
50
|
+
t.string :country_code, null: false
|
51
|
+
t.belongs_to :artifact, foreign_key: true
|
52
|
+
end
|
53
|
+
|
54
|
+
create_table :whois_records, if_not_exists: true do |t|
|
55
|
+
t.string :domain, null: false
|
56
|
+
t.date :created_on
|
57
|
+
t.date :updated_on
|
58
|
+
t.date :expires_on
|
59
|
+
t.json :registrar
|
60
|
+
t.json :contacts
|
61
|
+
t.belongs_to :artifact, foreign_key: true
|
62
|
+
end
|
63
|
+
|
64
|
+
create_table :dns_records, if_not_exists: true do |t|
|
65
|
+
t.string :resource, null: false
|
66
|
+
t.string :value, null: false
|
67
|
+
t.belongs_to :artifact, foreign_key: true
|
68
|
+
end
|
69
|
+
|
70
|
+
create_table :reverse_dns_names, if_not_exists: true do |t|
|
71
|
+
t.string :name, null: false
|
72
|
+
t.belongs_to :artifact, foreign_key: true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
41
77
|
def adapter
|
42
78
|
return "postgresql" if Mihari.config.database.start_with?("postgresql://", "postgres://")
|
43
79
|
return "mysql2" if Mihari.config.database.start_with?("mysql2://")
|
@@ -59,10 +95,12 @@ module Mihari
|
|
59
95
|
)
|
60
96
|
end
|
61
97
|
|
98
|
+
# ActiveRecord::Base.logger = Logger.new STDOUT
|
62
99
|
ActiveRecord::Migration.verbose = false
|
63
100
|
|
64
101
|
InitialSchema.migrate(:up)
|
65
|
-
|
102
|
+
AddeSourceToArtifactSchema.migrate(:up)
|
103
|
+
EnrichmentsSchema.migrate(:up)
|
66
104
|
rescue StandardError
|
67
105
|
# Do nothing
|
68
106
|
end
|
@@ -76,7 +114,8 @@ module Mihari
|
|
76
114
|
return unless ActiveRecord::Base.connected?
|
77
115
|
|
78
116
|
InitialSchema.migrate(:down)
|
79
|
-
|
117
|
+
AddeSourceToArtifactSchema.migrate(:down)
|
118
|
+
EnrichmentsSchema.migrate(:down)
|
80
119
|
end
|
81
120
|
end
|
82
121
|
end
|
data/lib/mihari/emitters/base.rb
CHANGED
data/lib/mihari/emitters/misp.rb
CHANGED
@@ -15,7 +15,7 @@ module Mihari
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
# @return [
|
18
|
+
# @return [Boolean]
|
19
19
|
def valid?
|
20
20
|
api_endpoint? && api_key? && ping?
|
21
21
|
end
|
@@ -42,10 +42,24 @@ module Mihari
|
|
42
42
|
%w[misp_api_endpoint misp_api_key]
|
43
43
|
end
|
44
44
|
|
45
|
+
#
|
46
|
+
# Build a MISP attribute
|
47
|
+
#
|
48
|
+
# @param [Mihari::Artifact] artifact
|
49
|
+
#
|
50
|
+
# @return [::MISP::Attribute] <description>
|
51
|
+
#
|
45
52
|
def build_attribute(artifact)
|
46
53
|
::MISP::Attribute.new(value: artifact.data, type: to_misp_type(type: artifact.data_type, value: artifact.data))
|
47
54
|
end
|
48
55
|
|
56
|
+
#
|
57
|
+
# Get a type of a hash
|
58
|
+
#
|
59
|
+
# @param [String] value
|
60
|
+
#
|
61
|
+
# @return [String]
|
62
|
+
#
|
49
63
|
def hash_type(value)
|
50
64
|
case value.length
|
51
65
|
when 32
|
@@ -59,6 +73,14 @@ module Mihari
|
|
59
73
|
end
|
60
74
|
end
|
61
75
|
|
76
|
+
#
|
77
|
+
# Convert a type to a MISP type
|
78
|
+
#
|
79
|
+
# @param [String] type
|
80
|
+
# @param [String] value
|
81
|
+
#
|
82
|
+
# @return [String]
|
83
|
+
#
|
62
84
|
def to_misp_type(type:, value:)
|
63
85
|
type = type.to_sym
|
64
86
|
table = {
|
@@ -72,20 +94,31 @@ module Mihari
|
|
72
94
|
hash_type value
|
73
95
|
end
|
74
96
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
97
|
+
#
|
98
|
+
# Check whether an API endpoint is set or not
|
99
|
+
#
|
100
|
+
# @return [Boolean]
|
101
|
+
#
|
79
102
|
def api_endpoint?
|
80
103
|
api_endpoint = ::MISP.configuration.api_endpoint
|
81
104
|
!api_endpoint.nil? && !api_endpoint.empty?
|
82
105
|
end
|
83
106
|
|
107
|
+
#
|
108
|
+
# Check whether an API key is set or not
|
109
|
+
#
|
110
|
+
# @return [Boolean]
|
111
|
+
#
|
84
112
|
def api_key?
|
85
113
|
api_key = ::MISP.configuration.api_key
|
86
114
|
!api_key.nil? && !api_key.empty?
|
87
115
|
end
|
88
116
|
|
117
|
+
#
|
118
|
+
# Check whether an API endpoint is reachable or not
|
119
|
+
#
|
120
|
+
# @return [Boolean]
|
121
|
+
#
|
89
122
|
def ping?
|
90
123
|
base_url = ::MISP.configuration.api_endpoint
|
91
124
|
base_url = base_url.end_with?("/") ? base_url[0..-2] : base_url
|
@@ -55,7 +55,7 @@ module Mihari
|
|
55
55
|
|
56
56
|
private
|
57
57
|
|
58
|
-
# @return [String]
|
58
|
+
# @return [String, nil]
|
59
59
|
def _urlscan_link
|
60
60
|
case data_type
|
61
61
|
when "ip"
|
@@ -69,7 +69,7 @@ module Mihari
|
|
69
69
|
end
|
70
70
|
memoize :_urlscan_link
|
71
71
|
|
72
|
-
# @return [String]
|
72
|
+
# @return [String, nil]
|
73
73
|
def _vt_link
|
74
74
|
case data_type
|
75
75
|
when "hash"
|
@@ -86,11 +86,13 @@ module Mihari
|
|
86
86
|
end
|
87
87
|
memoize :_vt_link
|
88
88
|
|
89
|
+
# @return [String, nil]
|
89
90
|
def _censys_link
|
90
91
|
data_type == "ip" ? "https://search.censys.io/hosts/#{data}" : nil
|
91
92
|
end
|
92
93
|
memoize :_censys_link
|
93
94
|
|
95
|
+
# @return [String, nil]
|
94
96
|
def _shodan_link
|
95
97
|
data_type == "ip" ? "https://www.shodan.io/host/#{data}" : nil
|
96
98
|
end
|
@@ -116,12 +118,28 @@ module Mihari
|
|
116
118
|
notifier.valid?
|
117
119
|
end
|
118
120
|
|
121
|
+
#
|
122
|
+
# Build attachements
|
123
|
+
#
|
124
|
+
# @param [Array<Mihari::Artifact>] artifacts
|
125
|
+
#
|
126
|
+
# @return [Array<Mihari::Emitters::Attachment>]
|
127
|
+
#
|
119
128
|
def to_attachments(artifacts)
|
120
129
|
artifacts.map do |artifact|
|
121
130
|
Attachment.new(data: artifact.data, data_type: artifact.data_type).to_a
|
122
131
|
end.flatten
|
123
132
|
end
|
124
133
|
|
134
|
+
#
|
135
|
+
# Build a text
|
136
|
+
#
|
137
|
+
# @param [String] title
|
138
|
+
# @param [String] description
|
139
|
+
# @param [Array<String>] tags
|
140
|
+
#
|
141
|
+
# @return [String]
|
142
|
+
#
|
125
143
|
def to_text(title:, description:, tags: [])
|
126
144
|
tags = ["N/A"] if tags.empty?
|
127
145
|
|
@@ -6,7 +6,7 @@ require "net/ping"
|
|
6
6
|
module Mihari
|
7
7
|
module Emitters
|
8
8
|
class TheHive < Base
|
9
|
-
# @return [
|
9
|
+
# @return [Boolean]
|
10
10
|
def valid?
|
11
11
|
api_endpont? && api_key? && ping?
|
12
12
|
end
|
@@ -34,16 +34,29 @@ module Mihari
|
|
34
34
|
@api ||= Hachi::API.new(api_endpoint: Mihari.config.thehive_api_endpoint, api_key: Mihari.config.thehive_api_key)
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
37
|
+
#
|
38
|
+
# Check whether an API endpoint is set or not
|
39
|
+
#
|
40
|
+
# @return [Boolean]
|
41
|
+
#
|
38
42
|
def api_endpont?
|
39
43
|
!Mihari.config.thehive_api_endpoint.nil?
|
40
44
|
end
|
41
45
|
|
42
|
-
#
|
46
|
+
#
|
47
|
+
# Check whether an API key is set or not
|
48
|
+
#
|
49
|
+
# @return [Boolean]
|
50
|
+
# ]
|
43
51
|
def api_key?
|
44
52
|
!Mihari.config.thehive_api_key.nil?
|
45
53
|
end
|
46
54
|
|
55
|
+
#
|
56
|
+
# Check whether an API endpoint is reachable or not
|
57
|
+
#
|
58
|
+
# @return [Boolean]
|
59
|
+
#
|
47
60
|
def ping?
|
48
61
|
base_url = Mihari.config.thehive_api_endpoint
|
49
62
|
base_url = base_url.end_with?("/") ? base_url[0..-2] : base_url
|
@@ -7,7 +7,7 @@ require "uri"
|
|
7
7
|
module Mihari
|
8
8
|
module Emitters
|
9
9
|
class Webhook < Base
|
10
|
-
# @return [
|
10
|
+
# @return [Boolean]
|
11
11
|
def valid?
|
12
12
|
webhook_url?
|
13
13
|
end
|
@@ -24,7 +24,7 @@ module Mihari
|
|
24
24
|
tags: tags
|
25
25
|
}
|
26
26
|
|
27
|
-
if use_json_body
|
27
|
+
if use_json_body?
|
28
28
|
Net::HTTP.post(uri, data.to_json, "Content-Type" => "application/json")
|
29
29
|
else
|
30
30
|
Net::HTTP.post_form(uri, data)
|
@@ -37,15 +37,30 @@ module Mihari
|
|
37
37
|
%w[webhook_url]
|
38
38
|
end
|
39
39
|
|
40
|
+
#
|
41
|
+
# Webhook URL
|
42
|
+
#
|
43
|
+
# @return [String, nil]
|
44
|
+
#
|
40
45
|
def webhook_url
|
41
46
|
@webhook_url ||= Mihari.config.webhook_url
|
42
47
|
end
|
43
48
|
|
49
|
+
#
|
50
|
+
# Check whether a webhook URL is set or not
|
51
|
+
#
|
52
|
+
# @return [<Type>] <description>
|
53
|
+
#
|
44
54
|
def webhook_url?
|
45
55
|
!webhook_url.nil?
|
46
56
|
end
|
47
57
|
|
48
|
-
|
58
|
+
#
|
59
|
+
# Check whether to use JSON body or NOT
|
60
|
+
#
|
61
|
+
# @return [<Type>] <description>
|
62
|
+
#
|
63
|
+
def use_json_body?
|
49
64
|
@use_json_body ||= Mihari.config.webhook_use_json_body
|
50
65
|
end
|
51
66
|
end
|
data/lib/mihari/models/alert.rb
CHANGED
@@ -18,8 +18,8 @@ module Mihari
|
|
18
18
|
# @param [String, nil] source
|
19
19
|
# @param [String, nil] tag_name
|
20
20
|
# @param [String, nil] title
|
21
|
-
# @param [
|
22
|
-
# @param [
|
21
|
+
# @param [DateTime, nil] from_at
|
22
|
+
# @param [DateTime, nil] to_at
|
23
23
|
# @param [Integer, nil] limit
|
24
24
|
# @param [Integer, nil] page
|
25
25
|
#
|
@@ -34,12 +34,22 @@ module Mihari
|
|
34
34
|
|
35
35
|
offset = (page - 1) * limit
|
36
36
|
|
37
|
-
relation = build_relation(
|
37
|
+
relation = build_relation(
|
38
|
+
artifact_data: artifact_data,
|
39
|
+
title: title,
|
40
|
+
description: description,
|
41
|
+
source: source,
|
42
|
+
tag_name: tag_name,
|
43
|
+
from_at: from_at,
|
44
|
+
to_at: to_at
|
45
|
+
)
|
38
46
|
|
39
|
-
|
47
|
+
# TODO: improve queires
|
48
|
+
alert_ids = relation.limit(limit).offset(offset).order(id: :desc).pluck(:id).uniq
|
49
|
+
alerts = includes(:artifacts, :tags).where(id: [alert_ids]).order(id: :desc)
|
40
50
|
|
41
51
|
alerts.map do |alert|
|
42
|
-
json = AlertSerializer.new(alert).as_json
|
52
|
+
json = Serializers::AlertSerializer.new(alert).as_json
|
43
53
|
json[:artifacts] = json[:artifacts] || []
|
44
54
|
json[:tags] = json[:tags] || []
|
45
55
|
json
|
@@ -54,13 +64,21 @@ module Mihari
|
|
54
64
|
# @param [String, nil] source
|
55
65
|
# @param [String, nil] tag_name
|
56
66
|
# @param [String, nil] title
|
57
|
-
# @param [
|
58
|
-
# @param [
|
67
|
+
# @param [DateTime, nil] from_at
|
68
|
+
# @param [DateTime, nil] to_at
|
59
69
|
#
|
60
70
|
# @return [Integer]
|
61
71
|
#
|
62
72
|
def count(artifact_data: nil, description: nil, source: nil, tag_name: nil, title: nil, from_at: nil, to_at: nil)
|
63
|
-
relation = build_relation(
|
73
|
+
relation = build_relation(
|
74
|
+
artifact_data: artifact_data,
|
75
|
+
title: title,
|
76
|
+
description: description,
|
77
|
+
source: source,
|
78
|
+
tag_name: tag_name,
|
79
|
+
from_at: from_at,
|
80
|
+
to_at: to_at
|
81
|
+
)
|
64
82
|
relation.distinct("alerts.id").count
|
65
83
|
end
|
66
84
|
|
@@ -68,8 +86,8 @@ module Mihari
|
|
68
86
|
|
69
87
|
def build_relation(artifact_data: nil, title: nil, description: nil, source: nil, tag_name: nil, from_at: nil, to_at: nil)
|
70
88
|
relation = self
|
71
|
-
|
72
|
-
relation =
|
89
|
+
|
90
|
+
relation = relation.includes(:artifacts, :tags)
|
73
91
|
|
74
92
|
relation = relation.where(artifacts: { data: artifact_data }) if artifact_data
|
75
93
|
relation = relation.where(tags: { name: tag_name }) if tag_name
|