mihari 3.8.1 → 3.10.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 +6 -7
- data/config.ru +1 -1
- data/lib/mihari/analyzers/greynoise.rb +65 -0
- data/lib/mihari/analyzers/rule.rb +1 -0
- data/lib/mihari/analyzers/shodan.rb +3 -1
- data/lib/mihari/cli/analyzer.rb +2 -0
- data/lib/mihari/commands/greynoise.rb +21 -0
- data/lib/mihari/commands/search.rb +3 -2
- data/lib/mihari/commands/web.rb +9 -5
- data/lib/mihari/database.rb +1 -1
- data/lib/mihari/errors.rb +2 -0
- data/lib/mihari/mixins/configuration.rb +12 -2
- data/lib/mihari/models/alert.rb +29 -54
- data/lib/mihari/models/artifact.rb +3 -0
- data/lib/mihari/schemas/configuration.rb +3 -2
- data/lib/mihari/structs/alert.rb +45 -0
- data/lib/mihari/structs/greynoise.rb +55 -0
- data/lib/mihari/structs/ipinfo.rb +3 -4
- data/lib/mihari/structs/shodan.rb +2 -2
- data/lib/mihari/types.rb +2 -0
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/api.rb +43 -0
- data/lib/mihari/web/app.rb +48 -30
- data/lib/mihari/web/endpoints/alerts.rb +74 -0
- data/lib/mihari/web/endpoints/artifacts.rb +92 -0
- data/lib/mihari/web/endpoints/command.rb +32 -0
- data/lib/mihari/web/endpoints/configs.rb +22 -0
- data/lib/mihari/web/endpoints/ip_addresses.rb +27 -0
- data/lib/mihari/web/endpoints/sources.rb +18 -0
- data/lib/mihari/web/endpoints/tags.rb +38 -0
- data/lib/mihari/web/entities/alert.rb +23 -0
- data/lib/mihari/web/entities/artifact.rb +24 -0
- data/lib/mihari/web/entities/autonomous_system.rb +9 -0
- data/lib/mihari/web/entities/command.rb +14 -0
- data/lib/mihari/web/entities/config.rb +16 -0
- data/lib/mihari/web/entities/dns.rb +10 -0
- data/lib/mihari/web/entities/geolocation.rb +10 -0
- data/lib/mihari/web/entities/ip_address.rb +13 -0
- data/lib/mihari/web/entities/message.rb +9 -0
- data/lib/mihari/web/entities/reverse_dns.rb +9 -0
- data/lib/mihari/web/entities/source.rb +9 -0
- data/lib/mihari/web/entities/tag.rb +13 -0
- data/lib/mihari/web/entities/whois.rb +16 -0
- data/lib/mihari/web/public/grape.rb +73 -0
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari/web/public/redoc-static.html +53 -27
- data/lib/mihari/web/public/static/js/app.0a0cc502.js +21 -0
- data/lib/mihari/web/public/static/js/app.0a0cc502.js.map +1 -0
- data/lib/mihari/web/public/static/js/app.14008741.js +21 -0
- data/lib/mihari/web/public/static/js/app.14008741.js.map +1 -0
- data/lib/mihari/web/public/static/js/app.378da3dc.js +50 -0
- data/lib/mihari/web/public/static/js/app.378da3dc.js.map +1 -0
- data/lib/mihari/web/public/static/js/app.6b636b62.js +50 -0
- data/lib/mihari/web/public/static/js/app.6b636b62.js.map +1 -0
- data/lib/mihari.rb +8 -14
- data/mihari.gemspec +10 -6
- data/sig/lib/mihari/analyzers/rule.rbs +1 -1
- data/sig/lib/mihari/models/alert.rbs +3 -31
- data/sig/lib/mihari/structs/alert.rbs +27 -0
- data/sig/lib/mihari/structs/greynoise.rbs +30 -0
- data/sig/lib/mihari/structs/shodan.rbs +1 -1
- data/sig/lib/mihari/web/app.rbs +2 -2
- metadata +150 -76
- data/lib/mihari/serializers/alert.rb +0 -14
- data/lib/mihari/serializers/artifact.rb +0 -18
- data/lib/mihari/serializers/autonomous_system.rb +0 -9
- data/lib/mihari/serializers/dns.rb +0 -11
- data/lib/mihari/serializers/geolocation.rb +0 -11
- data/lib/mihari/serializers/reverse_dns.rb +0 -11
- data/lib/mihari/serializers/tag.rb +0 -11
- data/lib/mihari/serializers/whois.rb +0 -11
- data/lib/mihari/web/controllers/alerts_controller.rb +0 -74
- data/lib/mihari/web/controllers/analyzers_controller.rb +0 -38
- data/lib/mihari/web/controllers/artifacts_controller.rb +0 -94
- data/lib/mihari/web/controllers/base_controller.rb +0 -22
- data/lib/mihari/web/controllers/command_controller.rb +0 -26
- data/lib/mihari/web/controllers/config_controller.rb +0 -13
- data/lib/mihari/web/controllers/ip_address_controller.rb +0 -21
- data/lib/mihari/web/controllers/sources_controller.rb +0 -12
- data/lib/mihari/web/controllers/tags_controller.rb +0 -30
- data/lib/mihari/web/helpers/json.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4d53239fe8be60cdc674dc22c14f801147a71144649cec83f4fd3caaf2c99fa
|
4
|
+
data.tar.gz: 71b9b3746164b1f3eec9b98a807a6940e85a9184991efd7dd9abe5bd9b3f3578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bee10443bd55e0ac483e8495c508bcce95dc56073aeb99f6c1566f38fb73707140baa838c07212c39795017d109aef8e9478f560bc3d04a21cbb949a48c9b61
|
7
|
+
data.tar.gz: c35f757168a737c37dcbf9a54d0408eabdfbf807a7a57db77c59c10f9a5b803d6731c615f3360db93b05647ee5e6cdcd35518baf4a7a7efe8d73e198d7f2664e
|
data/.github/workflows/test.yml
CHANGED
@@ -43,17 +43,16 @@ jobs:
|
|
43
43
|
|
44
44
|
steps:
|
45
45
|
- uses: actions/checkout@v2
|
46
|
-
- name: Set up Ruby 2.7
|
47
|
-
uses: ruby/setup-ruby@v1
|
48
|
-
with:
|
49
|
-
ruby-version: ${{ matrix.ruby }}
|
50
|
-
bundler-cache: true
|
51
46
|
|
52
47
|
- name: Install dependencies
|
53
48
|
run: |
|
54
49
|
sudo apt-get -yqq install libpq-dev libmysqlclient-dev
|
55
|
-
|
56
|
-
|
50
|
+
|
51
|
+
- name: Set up Ruby
|
52
|
+
uses: ruby/setup-ruby@v1
|
53
|
+
with:
|
54
|
+
ruby-version: ${{ matrix.ruby }}
|
55
|
+
bundler-cache: true
|
57
56
|
|
58
57
|
- name: Test with PostgreSQL
|
59
58
|
env:
|
data/config.ru
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "greynoise"
|
4
|
+
|
5
|
+
module Mihari
|
6
|
+
module Analyzers
|
7
|
+
class GreyNoise < Base
|
8
|
+
param :query
|
9
|
+
option :title, default: proc { "GreyNoise search" }
|
10
|
+
option :description, default: proc { "query = #{query}" }
|
11
|
+
option :tags, default: proc { [] }
|
12
|
+
|
13
|
+
def artifacts
|
14
|
+
res = Structs::GreyNoise::Response.from_dynamic!(search)
|
15
|
+
res.data.map do |datum|
|
16
|
+
build_artifact datum
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
PAGE_SIZE = 10_000
|
23
|
+
|
24
|
+
def configuration_keys
|
25
|
+
%w[greynoise_api_key]
|
26
|
+
end
|
27
|
+
|
28
|
+
def api
|
29
|
+
@api ||= ::GreyNoise::API.new(key: Mihari.config.greynoise_api_key)
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Search
|
34
|
+
#
|
35
|
+
# @return [Hash]
|
36
|
+
#
|
37
|
+
def search
|
38
|
+
api.experimental.gnql(query, size: PAGE_SIZE)
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Build an artifact from a GreyNoise search API response
|
43
|
+
#
|
44
|
+
# @param [Structs::GreyNoise::Datum] datum
|
45
|
+
#
|
46
|
+
# @return [Artifact]
|
47
|
+
#
|
48
|
+
def build_artifact(datum)
|
49
|
+
as = AutonomousSystem.new(asn: normalize_asn(datum.metadata.asn))
|
50
|
+
|
51
|
+
geolocation = Geolocation.new(
|
52
|
+
country: datum.metadata.country,
|
53
|
+
country_code: datum.metadata.country_code
|
54
|
+
)
|
55
|
+
|
56
|
+
Artifact.new(
|
57
|
+
data: datum.ip,
|
58
|
+
source: source,
|
59
|
+
autonomous_system: as,
|
60
|
+
geolocation: geolocation
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -78,7 +78,9 @@ module Mihari
|
|
78
78
|
# @return [Artifact]
|
79
79
|
#
|
80
80
|
def build_artifact(match)
|
81
|
-
as =
|
81
|
+
as = nil
|
82
|
+
as = AutonomousSystem.new(asn: normalize_asn(match.asn)) unless match.asn.nil?
|
83
|
+
|
82
84
|
geolocation = Geolocation.new(
|
83
85
|
country: match.location.country_name,
|
84
86
|
country_code: match.location.country_code
|
data/lib/mihari/cli/analyzer.rb
CHANGED
@@ -6,6 +6,7 @@ require "mihari/commands/circl"
|
|
6
6
|
require "mihari/commands/crtsh"
|
7
7
|
require "mihari/commands/dnpedia"
|
8
8
|
require "mihari/commands/dnstwister"
|
9
|
+
require "mihari/commands/greynoise"
|
9
10
|
require "mihari/commands/onyphe"
|
10
11
|
require "mihari/commands/otx"
|
11
12
|
require "mihari/commands/passivetotal"
|
@@ -33,6 +34,7 @@ module Mihari
|
|
33
34
|
include Mihari::Commands::Crtsh
|
34
35
|
include Mihari::Commands::DNPedia
|
35
36
|
include Mihari::Commands::DNSTwister
|
37
|
+
include Mihari::Commands::GreyNoise
|
36
38
|
include Mihari::Commands::JSON
|
37
39
|
include Mihari::Commands::Onyphe
|
38
40
|
include Mihari::Commands::OTX
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mihari
|
4
|
+
module Commands
|
5
|
+
module GreyNoise
|
6
|
+
def self.included(thor)
|
7
|
+
thor.class_eval do
|
8
|
+
desc "greynoise [QUERY]", "GreyNoise search"
|
9
|
+
method_option :title, type: :string, desc: "title"
|
10
|
+
method_option :description, type: :string, desc: "description"
|
11
|
+
method_option :tags, type: :array, desc: "tags"
|
12
|
+
def greynoise(query)
|
13
|
+
with_error_handling do
|
14
|
+
run_analyzer Analyzers::GreyNoise, query: query, options: options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -10,6 +10,9 @@ module Mihari
|
|
10
10
|
desc "search [RULE]", "Search by a rule"
|
11
11
|
method_option :config, type: :string, desc: "Path to the config file"
|
12
12
|
def search_by_rule(rule)
|
13
|
+
# load configuration
|
14
|
+
load_configuration
|
15
|
+
|
13
16
|
# convert str(YAML) to hash or str(path/YAML file) to hash
|
14
17
|
rule = load_rule(rule)
|
15
18
|
|
@@ -77,8 +80,6 @@ module Mihari
|
|
77
80
|
# @return [nil]
|
78
81
|
#
|
79
82
|
def run_rule_analyzer(analyzer, ignore_old_artifacts: false, ignore_threshold: 0)
|
80
|
-
load_configuration
|
81
|
-
|
82
83
|
analyzer.ignore_old_artifacts = ignore_old_artifacts
|
83
84
|
analyzer.ignore_threshold = ignore_threshold
|
84
85
|
|
data/lib/mihari/commands/web.rb
CHANGED
@@ -6,19 +6,23 @@ module Mihari
|
|
6
6
|
def self.included(thor)
|
7
7
|
thor.class_eval do
|
8
8
|
desc "web", "Launch the web app"
|
9
|
-
method_option :port, type: :numeric, default: 9292
|
10
|
-
method_option :host, type: :string, default: "localhost"
|
9
|
+
method_option :port, type: :numeric, default: 9292, desc: "Hostname to listen on"
|
10
|
+
method_option :host, type: :string, default: "localhost", desc: "Port to listen on"
|
11
|
+
method_option :threads, type: :string, default: "0:16", desc: "min:max threads to use"
|
12
|
+
method_option :verbose, type: :boolean, default: true, desc: "Report each request"
|
11
13
|
method_option :config, type: :string, desc: "Path to the config file"
|
12
14
|
def web
|
13
|
-
port = options["port"]
|
14
|
-
host = options["host"]
|
15
|
+
port = options["port"]
|
16
|
+
host = options["host"]
|
17
|
+
threads = options["threads"]
|
18
|
+
verbose = options["verbose"]
|
15
19
|
|
16
20
|
load_configuration
|
17
21
|
|
18
22
|
# set rack env as production
|
19
23
|
ENV["RACK_ENV"] ||= "production"
|
20
24
|
|
21
|
-
Mihari::App.run!(port: port, host: host)
|
25
|
+
Mihari::App.run!(port: port, host: host, threads: threads, verbose: verbose)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
data/lib/mihari/database.rb
CHANGED
data/lib/mihari/errors.rb
CHANGED
@@ -80,10 +80,20 @@ module Mihari
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
#
|
84
|
+
# Load configuration file
|
85
|
+
#
|
86
|
+
# @param [String] path
|
87
|
+
#
|
88
|
+
# @return [Hash]
|
89
|
+
#
|
83
90
|
def _load_config(path)
|
84
|
-
|
91
|
+
unless Pathname(path).exist?
|
92
|
+
puts "#{path} does not exist".colorize(:red)
|
93
|
+
raise FileNotFoundError
|
94
|
+
end
|
85
95
|
|
86
|
-
YAML.safe_load(path, symbolize_names: true)
|
96
|
+
YAML.safe_load(File.read(path), symbolize_names: true)
|
87
97
|
end
|
88
98
|
end
|
89
99
|
end
|
data/lib/mihari/models/alert.rb
CHANGED
@@ -13,92 +13,67 @@ module Mihari
|
|
13
13
|
#
|
14
14
|
# Search alerts
|
15
15
|
#
|
16
|
-
# @param [
|
17
|
-
# @param [String, nil] description
|
18
|
-
# @param [String, nil] source
|
19
|
-
# @param [String, nil] tag_name
|
20
|
-
# @param [String, nil] title
|
21
|
-
# @param [DateTime, nil] from_at
|
22
|
-
# @param [DateTime, nil] to_at
|
23
|
-
# @param [Integer, nil] limit
|
24
|
-
# @param [Integer, nil] page
|
16
|
+
# @param [Structs::Alert::SearchFilterWithPagination] filter
|
25
17
|
#
|
26
18
|
# @return [Array<Hash>]
|
27
19
|
#
|
28
|
-
def search(
|
29
|
-
limit = limit.to_i
|
20
|
+
def search(filter)
|
21
|
+
limit = filter.limit.to_i
|
30
22
|
raise ArgumentError, "limit should be bigger than zero" unless limit.positive?
|
31
23
|
|
32
|
-
page = page.to_i
|
24
|
+
page = filter.page.to_i
|
33
25
|
raise ArgumentError, "page should be bigger than zero" unless page.positive?
|
34
26
|
|
35
27
|
offset = (page - 1) * limit
|
36
28
|
|
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
|
-
)
|
29
|
+
relation = build_relation(filter.without_pagination)
|
46
30
|
|
47
31
|
# TODO: improve queires
|
48
32
|
alert_ids = relation.limit(limit).offset(offset).order(id: :desc).pluck(:id).uniq
|
49
|
-
|
50
|
-
|
51
|
-
alerts.map do |alert|
|
52
|
-
json = Serializers::AlertSerializer.new(alert).as_json
|
53
|
-
json[:artifacts] = json[:artifacts] || []
|
54
|
-
json[:tags] = json[:tags] || []
|
55
|
-
json
|
56
|
-
end
|
33
|
+
includes(:artifacts, :tags).where(id: [alert_ids]).order(id: :desc)
|
57
34
|
end
|
58
35
|
|
59
36
|
#
|
60
37
|
# Count alerts
|
61
38
|
#
|
62
39
|
# @param [String, nil] artifact_data
|
63
|
-
# @param [String, nil] description
|
64
|
-
# @param [String, nil] source
|
65
|
-
# @param [String, nil] tag_name
|
66
|
-
# @param [String, nil] title
|
67
|
-
# @param [DateTime, nil] from_at
|
68
|
-
# @param [DateTime, nil] to_at
|
69
40
|
#
|
70
41
|
# @return [Integer]
|
71
42
|
#
|
72
|
-
def count(
|
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
|
-
)
|
43
|
+
def count(filter)
|
44
|
+
relation = build_relation(filter)
|
82
45
|
relation.distinct("alerts.id").count
|
83
46
|
end
|
84
47
|
|
85
48
|
private
|
86
49
|
|
87
|
-
def build_relation(
|
88
|
-
|
50
|
+
def build_relation(filter)
|
51
|
+
artifact_ids = []
|
52
|
+
artifact = Artifact.includes(:autonomous_system, :dns_records, :reverse_dns_names)
|
53
|
+
artifact = artifact.where(data: filter.artifact_data) if filter.artifact_data
|
54
|
+
artifact = artifact.where(autonomous_system: { asn: filter.asn }) if filter.asn
|
55
|
+
artifact = artifact.where(dns_records: { value: filter.dns_record }) if filter.dns_record
|
56
|
+
artifact = artifact.where(reverse_dns_names: { name: filter.reverse_dns_name }) if filter.reverse_dns_name
|
57
|
+
# get artifact ids if there is any valid filter for artifact
|
58
|
+
if filter.has_valid_artifact_filters
|
59
|
+
artifact_ids = artifact.pluck(:id)
|
60
|
+
# set invalid ID if nothing is matched with the filters
|
61
|
+
artifact_ids = [-1] if artifact_ids.empty?
|
62
|
+
end
|
89
63
|
|
64
|
+
relation = self
|
90
65
|
relation = relation.includes(:artifacts, :tags)
|
91
66
|
|
92
|
-
relation = relation.where(artifacts: {
|
93
|
-
relation = relation.where(tags: { name: tag_name }) if tag_name
|
67
|
+
relation = relation.where(artifacts: { id: artifact_ids }) unless artifact_ids.empty?
|
68
|
+
relation = relation.where(tags: { name: filter.tag_name }) if filter.tag_name
|
94
69
|
|
95
|
-
relation = relation.where(source: source) if source
|
96
|
-
relation = relation.where(title: title) if title
|
70
|
+
relation = relation.where(source: filter.source) if filter.source
|
71
|
+
relation = relation.where(title: filter.title) if filter.title
|
97
72
|
|
98
|
-
relation = relation.filter(description: { like: "%#{description}%" }) if description
|
73
|
+
relation = relation.filter(description: { like: "%#{filter.description}%" }) if filter.description
|
99
74
|
|
100
|
-
relation = relation.filter(created_at: { gte: from_at }) if from_at
|
101
|
-
relation = relation.filter(created_at: { lte: to_at }) if to_at
|
75
|
+
relation = relation.filter(created_at: { gte: filter.from_at }) if filter.from_at
|
76
|
+
relation = relation.filter(created_at: { lte: filter.to_at }) if filter.to_at
|
102
77
|
|
103
78
|
relation
|
104
79
|
end
|
@@ -13,6 +13,8 @@ module Mihari
|
|
13
13
|
optional(:censys_secret).value(:string)
|
14
14
|
optional(:circl_passive_password).value(:string)
|
15
15
|
optional(:circl_passive_username).value(:string)
|
16
|
+
optional(:database).value(:string)
|
17
|
+
optional(:greynoise_api_key).value(:string)
|
16
18
|
optional(:ipinfo_api_key).value(:string)
|
17
19
|
optional(:misp_api_endpoint).value(:string)
|
18
20
|
optional(:misp_api_key).value(:string)
|
@@ -30,10 +32,9 @@ module Mihari
|
|
30
32
|
optional(:thehive_api_key).value(:string)
|
31
33
|
optional(:urlscan_api_key).value(:string)
|
32
34
|
optional(:virustotal_api_key).value(:string)
|
33
|
-
optional(:zoomeye_api_key).value(:string)
|
34
35
|
optional(:webhook_url).value(:string)
|
35
36
|
optional(:webhook_use_json_body).value(:bool)
|
36
|
-
optional(:
|
37
|
+
optional(:zoomeye_api_key).value(:string)
|
37
38
|
end
|
38
39
|
|
39
40
|
class ConfigurationContract < Dry::Validation::Contract
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "json"
|
2
|
+
require "dry/struct"
|
3
|
+
|
4
|
+
module Mihari
|
5
|
+
module Structs
|
6
|
+
module Alert
|
7
|
+
class SearchFilter < Dry::Struct
|
8
|
+
attribute? :artifact_data, Types::String.optional
|
9
|
+
attribute? :description, Types::String.optional
|
10
|
+
attribute? :source, Types::String.optional
|
11
|
+
attribute? :tag_name, Types::String.optional
|
12
|
+
attribute? :title, Types::String.optional
|
13
|
+
attribute? :from_at, Types::DateTime.optional
|
14
|
+
attribute? :to_at, Types::DateTime.optional
|
15
|
+
attribute? :asn, Types::Int.optional
|
16
|
+
attribute? :dns_record, Types::String.optional
|
17
|
+
attribute? :reverse_dns_name, Types::String.optional
|
18
|
+
|
19
|
+
def has_valid_artifact_filters
|
20
|
+
!(artifact_data || asn || dns_record || reverse_dns_name).nil?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class SearchFilterWithPagination < SearchFilter
|
25
|
+
attribute? :page, Types::Int.default(1)
|
26
|
+
attribute? :limit, Types::Int.default(10)
|
27
|
+
|
28
|
+
def without_pagination
|
29
|
+
SearchFilter.new(
|
30
|
+
artifact_data: artifact_data,
|
31
|
+
description: description,
|
32
|
+
from_at: from_at,
|
33
|
+
source: source,
|
34
|
+
tag_name: tag_name,
|
35
|
+
title: title,
|
36
|
+
to_at: to_at,
|
37
|
+
asn: asn,
|
38
|
+
dns_record: dns_record,
|
39
|
+
reverse_dns_name: reverse_dns_name
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "json"
|
2
|
+
require "dry/struct"
|
3
|
+
|
4
|
+
module Mihari
|
5
|
+
module Structs
|
6
|
+
module GreyNoise
|
7
|
+
class Metadata < Dry::Struct
|
8
|
+
attribute :country, Types::String
|
9
|
+
attribute :country_code, Types::String
|
10
|
+
attribute :asn, Types::String
|
11
|
+
|
12
|
+
def self.from_dynamic!(d)
|
13
|
+
d = Types::Hash[d]
|
14
|
+
new(
|
15
|
+
country: d.fetch("country"),
|
16
|
+
country_code: d.fetch("country_code"),
|
17
|
+
asn: d.fetch("asn")
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Datum < Dry::Struct
|
23
|
+
attribute :ip, Types::String
|
24
|
+
attribute :metadata, Metadata
|
25
|
+
|
26
|
+
def self.from_dynamic!(d)
|
27
|
+
d = Types::Hash[d]
|
28
|
+
new(
|
29
|
+
ip: d.fetch("ip"),
|
30
|
+
metadata: Metadata.from_dynamic!(d.fetch("metadata"))
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Response < Dry::Struct
|
36
|
+
attribute :complete, Types::Bool
|
37
|
+
attribute :count, Types::Int
|
38
|
+
attribute :data, Types.Array(Datum)
|
39
|
+
attribute :message, Types::String
|
40
|
+
attribute :query, Types::String
|
41
|
+
|
42
|
+
def self.from_dynamic!(d)
|
43
|
+
d = Types::Hash[d]
|
44
|
+
new(
|
45
|
+
complete: d.fetch("complete"),
|
46
|
+
count: d.fetch("count"),
|
47
|
+
data: d.fetch("data").map { |x| Datum.from_dynamic!(x) },
|
48
|
+
message: d.fetch("message"),
|
49
|
+
query: d.fetch("query")
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -18,7 +18,7 @@ module Mihari
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class Match < Dry::Struct
|
21
|
-
attribute :asn, Types::String
|
21
|
+
attribute :asn, Types::String.optional
|
22
22
|
attribute :hostnames, Types.Array(Types::String)
|
23
23
|
attribute :location, Location
|
24
24
|
attribute :domains, Types.Array(Types::String)
|
@@ -27,7 +27,7 @@ module Mihari
|
|
27
27
|
def self.from_dynamic!(d)
|
28
28
|
d = Types::Hash[d]
|
29
29
|
new(
|
30
|
-
asn: d
|
30
|
+
asn: d["asn"],
|
31
31
|
hostnames: d.fetch("hostnames"),
|
32
32
|
location: Location.from_dynamic!(d.fetch("location")),
|
33
33
|
domains: d.fetch("domains"),
|
data/lib/mihari/types.rb
CHANGED
@@ -9,6 +9,7 @@ module Mihari
|
|
9
9
|
Hash = Strict::Hash
|
10
10
|
String = Strict::String
|
11
11
|
Double = Strict::Float | Strict::Integer
|
12
|
+
DateTime = Strict::DateTime
|
12
13
|
|
13
14
|
DataTypes = Types::String.enum(*ALLOWED_DATA_TYPES)
|
14
15
|
|
@@ -18,6 +19,7 @@ module Mihari
|
|
18
19
|
"circl",
|
19
20
|
"dnpedia",
|
20
21
|
"dnstwister",
|
22
|
+
"greynoise",
|
21
23
|
"onyphe",
|
22
24
|
"otx",
|
23
25
|
"passivetotal",
|
data/lib/mihari/version.rb
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Entities
|
2
|
+
require "mihari/web/entities/message"
|
3
|
+
|
4
|
+
require "mihari/web/entities/autonomous_system"
|
5
|
+
require "mihari/web/entities/command"
|
6
|
+
require "mihari/web/entities/config"
|
7
|
+
require "mihari/web/entities/dns"
|
8
|
+
require "mihari/web/entities/geolocation"
|
9
|
+
require "mihari/web/entities/ip_address"
|
10
|
+
require "mihari/web/entities/reverse_dns"
|
11
|
+
require "mihari/web/entities/source"
|
12
|
+
require "mihari/web/entities/tag"
|
13
|
+
require "mihari/web/entities/whois"
|
14
|
+
|
15
|
+
require "mihari/web/entities/artifact"
|
16
|
+
|
17
|
+
require "mihari/web/entities/alert"
|
18
|
+
|
19
|
+
# Endpoints
|
20
|
+
require "mihari/web/endpoints/alerts"
|
21
|
+
require "mihari/web/endpoints/artifacts"
|
22
|
+
require "mihari/web/endpoints/command"
|
23
|
+
require "mihari/web/endpoints/configs"
|
24
|
+
require "mihari/web/endpoints/ip_addresses"
|
25
|
+
require "mihari/web/endpoints/sources"
|
26
|
+
require "mihari/web/endpoints/tags"
|
27
|
+
|
28
|
+
module Mihari
|
29
|
+
class API < Grape::API
|
30
|
+
prefix "api"
|
31
|
+
format :json
|
32
|
+
|
33
|
+
mount Endpoints::Alerts
|
34
|
+
mount Endpoints::Artifacts
|
35
|
+
mount Endpoints::Command
|
36
|
+
mount Endpoints::Configs
|
37
|
+
mount Endpoints::IPAddresses
|
38
|
+
mount Endpoints::Sources
|
39
|
+
mount Endpoints::Tags
|
40
|
+
|
41
|
+
add_swagger_documentation(api_version: "v1", info: { title: "Mihari API" })
|
42
|
+
end
|
43
|
+
end
|