mihari 3.6.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/lib/mihari/analyzers/base.rb +5 -5
- data/lib/mihari/analyzers/binaryedge.rb +13 -0
- data/lib/mihari/analyzers/censys.rb +5 -0
- 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 +20 -4
- 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 +13 -0
- 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/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/structs/onyphe.rb +2 -2
- data/lib/mihari/type_checker.rb +9 -9
- data/lib/mihari/version.rb +1 -1
- data/mihari.gemspec +1 -0
- 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 +102 -2
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mihari
|
2
|
+
module Mixins
|
3
|
+
module Configurable
|
4
|
+
#
|
5
|
+
# Check whether it is configured or not
|
6
|
+
#
|
7
|
+
# @return [Boolean]
|
8
|
+
#
|
9
|
+
def configured?: () -> bool
|
10
|
+
|
11
|
+
#
|
12
|
+
# Configuration values
|
13
|
+
#
|
14
|
+
# @return [Array<Hash>, nil] Configuration values as a list of hash. Returns nil if there is any keys.
|
15
|
+
#
|
16
|
+
def configuration_values: () -> untyped
|
17
|
+
|
18
|
+
#
|
19
|
+
# Configuration keys
|
20
|
+
#
|
21
|
+
# @return [Array<String>] A list of cofiguration keys
|
22
|
+
#
|
23
|
+
def configuration_keys: () -> Array[String]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Mihari
|
2
|
+
module Mixins
|
3
|
+
module Configuration
|
4
|
+
#
|
5
|
+
# Load config file into hash
|
6
|
+
#
|
7
|
+
# @param [String] path Path to YAML file
|
8
|
+
#
|
9
|
+
# @return [Hash]
|
10
|
+
#
|
11
|
+
def load_config: (String path) -> Hash
|
12
|
+
|
13
|
+
#
|
14
|
+
# Validate config schema
|
15
|
+
#
|
16
|
+
# @param [Hash] config
|
17
|
+
#
|
18
|
+
def validate_config: (Hash config) -> void
|
19
|
+
|
20
|
+
#
|
21
|
+
# Returns a template for config
|
22
|
+
#
|
23
|
+
# @return [String] A template for config
|
24
|
+
#
|
25
|
+
def config_template: () -> String
|
26
|
+
|
27
|
+
#
|
28
|
+
# Create (blank) config file
|
29
|
+
#
|
30
|
+
# @param [String] filename
|
31
|
+
# @param [Dry::Files] files
|
32
|
+
# @param [String] template
|
33
|
+
#
|
34
|
+
# @return [nil]
|
35
|
+
#
|
36
|
+
def initialize_config_yaml: (String filename, ?untyped files, ?template: String template) -> nil
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def show_validation_errors: (untyped errors) -> void
|
41
|
+
|
42
|
+
def _load_config: (String path) -> untyped
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Mihari
|
2
|
+
module Mixins
|
3
|
+
module DisallowedDataValue
|
4
|
+
# include Mem
|
5
|
+
|
6
|
+
#
|
7
|
+
# Normalize a value as a disallowed data value
|
8
|
+
#
|
9
|
+
# @param [String] value Data value
|
10
|
+
#
|
11
|
+
# @return [String, Regexp] Normalized value
|
12
|
+
#
|
13
|
+
def normalize_disallowed_data_value: (String value) -> (String | Regexp)
|
14
|
+
|
15
|
+
#
|
16
|
+
# Check whetehr a value is valid format as a disallowed data value
|
17
|
+
#
|
18
|
+
# @param [String] value Data value
|
19
|
+
#
|
20
|
+
# @return [Boolean] true if it is valid, otherwise false
|
21
|
+
#
|
22
|
+
def valid_disallowed_data_value?: (String value) -> bool
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Mihari
|
2
|
+
module Mixins
|
3
|
+
module Retriable
|
4
|
+
#
|
5
|
+
# Retry on error
|
6
|
+
#
|
7
|
+
# @param [Integer] times
|
8
|
+
# @param [Integer] interval
|
9
|
+
#
|
10
|
+
# @return [nil]
|
11
|
+
#
|
12
|
+
def retry_on_error: (?times: ::Integer times, ?interval: ::Integer interval) { () -> untyped } -> nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Mihari
|
2
|
+
module Mixins
|
3
|
+
module Rule
|
4
|
+
#
|
5
|
+
# Load rule into hash
|
6
|
+
#
|
7
|
+
# @param [String] path Path to YAML file or YAML string
|
8
|
+
#
|
9
|
+
# @return [Hash]
|
10
|
+
#
|
11
|
+
def load_rule: (String path) -> Hash
|
12
|
+
|
13
|
+
#
|
14
|
+
# Validate rule schema and return a normalized rule
|
15
|
+
#
|
16
|
+
# @param [Hash] rule
|
17
|
+
#
|
18
|
+
# @return [Hash]
|
19
|
+
#
|
20
|
+
def validate_rule: (Hash rule) -> Hash
|
21
|
+
|
22
|
+
#
|
23
|
+
# Returns a template for rule
|
24
|
+
#
|
25
|
+
# @return [String] A template for rule
|
26
|
+
#
|
27
|
+
def rule_template: () -> String
|
28
|
+
|
29
|
+
#
|
30
|
+
# Create (blank) rule file
|
31
|
+
#
|
32
|
+
# @param [String] filename
|
33
|
+
# @param [Dry::Files] files
|
34
|
+
# @param [String] template
|
35
|
+
#
|
36
|
+
# @return [nil]
|
37
|
+
#
|
38
|
+
def initialize_rule_yaml: (String filename, ?untyped files, ?template: String template) -> nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Mihari
|
2
|
+
class Alert < ActiveRecord::Base
|
3
|
+
attr_accessor title (): String
|
4
|
+
attr_accessor description (): String?
|
5
|
+
attr_accessor source (): String
|
6
|
+
|
7
|
+
attr_accessor artifacts(): Array[Mihari::Artifact]
|
8
|
+
attr_accessor Tags(): Array[Mihari::Tag]
|
9
|
+
|
10
|
+
#
|
11
|
+
# Search alerts
|
12
|
+
#
|
13
|
+
# @param [String, nil] artifact_data
|
14
|
+
# @param [String, nil] description
|
15
|
+
# @param [String, nil] source
|
16
|
+
# @param [String, nil] tag_name
|
17
|
+
# @param [String, nil] title
|
18
|
+
# @param [DateTime, nil] from_at
|
19
|
+
# @param [DateTime, nil] to_at
|
20
|
+
# @param [Integer, nil] limit
|
21
|
+
# @param [Integer, nil] page
|
22
|
+
#
|
23
|
+
# @return [Array<Hash>]
|
24
|
+
#
|
25
|
+
def self.search: (?artifact_data: String? artifact_data, ?description: String? description, ?source: String? source, ?tag_name: String? tag_name, ?title: String? title, ?from_at: DateTime? from_at, ?to_at: DateTime? to_at, ?limit: ::Integer limit, ?page: ::Integer page) -> Array[Hash[(String | Symbol), untyped]]
|
26
|
+
|
27
|
+
#
|
28
|
+
# Count alerts
|
29
|
+
#
|
30
|
+
# @param [String, nil] artifact_data
|
31
|
+
# @param [String, nil] description
|
32
|
+
# @param [String, nil] source
|
33
|
+
# @param [String, nil] tag_name
|
34
|
+
# @param [String, nil] title
|
35
|
+
# @param [DateTime, nil] from_at
|
36
|
+
# @param [DateTime, nil] to_at
|
37
|
+
#
|
38
|
+
# @return [Integer]
|
39
|
+
#
|
40
|
+
def self.count: (?artifact_data: String? artifact_data, ?description: String? description, ?source: String? source, ?tag_name: String? tag_name, ?title: String? title, ?from_at: DateTime? from_at, ?to_at: DateTime? to_at) -> Integer
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def self.build_relation: (?artifact_data: String? artifact_data, ?title: String? title, ?description: String? description, ?source: String? source, ?tag_name: String? tag_name, ?from_at: DateTime? from_at, ?to_at: DateTime? to_at) -> Mihari::Alert
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class ArtifactValidator < ActiveModel::Validator
|
2
|
+
def validate: (Mihari::Artifact record) -> (nil | Mihari::Artifact)
|
3
|
+
end
|
4
|
+
|
5
|
+
module Mihari
|
6
|
+
class Artifact < ActiveRecord::Base
|
7
|
+
attr_accessor data (): String
|
8
|
+
attr_accessor data_type (): String
|
9
|
+
|
10
|
+
attr_accessor geolocation (): Mihari::Geolocation
|
11
|
+
attr_accessor whois_record(): Mihari::WhoisRecord
|
12
|
+
attr_accessor dns_records(): Array[Mihari::DnsRecord]
|
13
|
+
attr_accessor reverse_dns_names(): Array[Mihari::ReverseDnsName]
|
14
|
+
|
15
|
+
include ActiveModel::Validations
|
16
|
+
|
17
|
+
def initialize: (Hash[(String | Symbol), untyped] attributes) -> void
|
18
|
+
|
19
|
+
#
|
20
|
+
# Check uniqueness of artifact
|
21
|
+
#
|
22
|
+
# @param [Boolean] ignore_old_artifacts
|
23
|
+
# @param [Integer] ignore_threshold
|
24
|
+
#
|
25
|
+
# @return [Boolean] true if it is unique. Otherwise false.
|
26
|
+
#
|
27
|
+
def unique?: (?ignore_old_artifacts: bool ignore_old_artifacts, ?ignore_threshold: ::Integer ignore_threshold) -> (bool)
|
28
|
+
|
29
|
+
#
|
30
|
+
# Enrich(add) whois record
|
31
|
+
#
|
32
|
+
def enrich_whois: () -> void
|
33
|
+
|
34
|
+
#
|
35
|
+
# Enrich(add) DNS records
|
36
|
+
#
|
37
|
+
def enrich_dns: () -> void
|
38
|
+
|
39
|
+
#
|
40
|
+
# Enrich(add) reverse DNS names
|
41
|
+
#
|
42
|
+
def enrich_reverse_dns: () -> void
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def normalize_as_domain: (String url_or_domain) -> String
|
47
|
+
|
48
|
+
def can_enrich_whois?: () -> bool
|
49
|
+
|
50
|
+
def can_enrich_dns?: () -> bool
|
51
|
+
|
52
|
+
def can_enrich_revese_dns?: () -> bool
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mihari
|
2
|
+
class DnsRecord < ActiveRecord::Base
|
3
|
+
attr_accessor resource (): String
|
4
|
+
attr_accessor value (): String
|
5
|
+
|
6
|
+
#
|
7
|
+
# Build DNS records
|
8
|
+
#
|
9
|
+
# @param [String] domain
|
10
|
+
#
|
11
|
+
# @return [Array<Mihari::DnsRecord>]
|
12
|
+
#
|
13
|
+
def self.build_by_domain: (String domain) -> Array[Mihari::DnsRecord]
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.get_values: (String domain, singleton(Resolv::DNS::Query) resource_type) -> Array[Mihari::DnsRecord]
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mihari
|
2
|
+
class ReverseDnsName < ActiveRecord::Base
|
3
|
+
attr_accessor name (): String
|
4
|
+
|
5
|
+
#
|
6
|
+
# Build reverse DNS names
|
7
|
+
#
|
8
|
+
# @param [String] ip
|
9
|
+
#
|
10
|
+
# @return [Array<Mihari::ReverseDnsName>]
|
11
|
+
#
|
12
|
+
def self.build_by_ip: (String ip) -> Array[Mihari::ReverseDnsName]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Mihari
|
2
|
+
class WhoisRecord < ActiveRecord::Base
|
3
|
+
attr_accessor domain (): String
|
4
|
+
attr_accessor created_on (): DateTime?
|
5
|
+
attr_accessor updated_on (): DateTime?
|
6
|
+
attr_accessor expires_on (): DateTime?
|
7
|
+
attr_accessor registrar (): Hash[(String | Symbol), untyped]
|
8
|
+
attr_accessor contacts (): Array[Hash[(String | Symbol), untyped]]
|
9
|
+
|
10
|
+
#
|
11
|
+
# Build whois record
|
12
|
+
#
|
13
|
+
# @param [Stinrg] domain
|
14
|
+
#
|
15
|
+
# @return [WhoisRecord, nil]
|
16
|
+
#
|
17
|
+
def self.build_by_domain: (String domain) -> Mihari::WhoisRecord?
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
#
|
22
|
+
# Get created_on
|
23
|
+
#
|
24
|
+
# @param [::Whois::Parser:] parser
|
25
|
+
#
|
26
|
+
# @return [Date, nil]
|
27
|
+
#
|
28
|
+
def self.get_created_on: (untyped parser) -> Date?
|
29
|
+
|
30
|
+
#
|
31
|
+
# Get updated_on
|
32
|
+
#
|
33
|
+
# @param [::Whois::Parser:] parser
|
34
|
+
#
|
35
|
+
# @return [Date, nil]
|
36
|
+
#
|
37
|
+
def self.get_updated_on: (untyped parser) -> Date?
|
38
|
+
|
39
|
+
#
|
40
|
+
# Get expires_on
|
41
|
+
#
|
42
|
+
# @param [::Whois::Parser:] parser
|
43
|
+
#
|
44
|
+
# @return [Date, nil]
|
45
|
+
#
|
46
|
+
def self.get_expires_on: (untyped parser) -> Date?
|
47
|
+
|
48
|
+
#
|
49
|
+
# Get registrar
|
50
|
+
#
|
51
|
+
# @param [::Whois::Parser:] parser
|
52
|
+
#
|
53
|
+
# @return [Hash, nil]
|
54
|
+
#
|
55
|
+
def self.get_registrar: (untyped parser) -> Hash[(String | Symbol), untyped]?
|
56
|
+
|
57
|
+
#
|
58
|
+
# Get contacts
|
59
|
+
#
|
60
|
+
# @param [::Whois::Parser:] parser
|
61
|
+
#
|
62
|
+
# @return [Array[Hash[(String | Symbol), untyped]], nil]
|
63
|
+
#
|
64
|
+
def self.get_contacts: (untyped parser) -> Array[Hash[(String | Symbol), untyped]]?
|
65
|
+
end
|
66
|
+
end
|