mihari 3.7.2 → 3.9.1
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/README.md +1 -1
- data/config.ru +1 -1
- data/lib/mihari/analyzers/rule.rb +24 -19
- data/lib/mihari/analyzers/virustotal_intelligence.rb +63 -0
- data/lib/mihari/cli/analyzer.rb +2 -0
- data/lib/mihari/commands/passivetotal.rb +1 -0
- data/lib/mihari/commands/virustotal.rb +1 -0
- data/lib/mihari/commands/virustotal_intelligence.rb +22 -0
- 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/structs/alert.rb +45 -0
- data/lib/mihari/structs/ipinfo.rb +3 -4
- data/lib/mihari/structs/virustotal_intelligence.rb +75 -0
- data/lib/mihari/types.rb +18 -3
- 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.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/web/public/static/js/app.a862ebca.js +50 -0
- data/lib/mihari/web/public/static/js/app.a862ebca.js.map +1 -0
- data/lib/mihari.rb +5 -13
- data/mihari.gemspec +9 -7
- data/sig/lib/mihari/analyzers/rule.rbs +3 -3
- data/sig/lib/mihari/analyzers/virustotal_intelligence.rbs +32 -0
- data/sig/lib/mihari/models/alert.rbs +3 -31
- data/sig/lib/mihari/structs/alert.rbs +27 -0
- data/sig/lib/mihari/structs/virustotal_intelligence.rbs +33 -0
- data/sig/lib/mihari/web/app.rbs +2 -2
- metadata +123 -78
- 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: d2e67ff3e1ae2bf328a9a77ef7c9a88dce779749c422490a97106d3529a9a3b1
|
4
|
+
data.tar.gz: a71ee49c8fcb0b06e180739a588930783dabbc40078d234f791314dd3f8af9b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41c30a97d80e6d96f425230401b7f0ee947979dff6b2a8c458bb72c38ed34c2577bed1b007f25e2607cacc1c70f6d7de183722bac0b604f0c54f582758db1e53
|
7
|
+
data.tar.gz: 6cb1d47e4efec3fb54bd93ddacf5e8f55e423d3b28c1e3c6ae2ea852898b88d3995d8eb767e89535ba50bfffb6b533ce946068eb348cfbd33afe41ace587a5df
|
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/README.md
CHANGED
@@ -46,7 +46,7 @@ Mihari supports the following services by default.
|
|
46
46
|
- [Shodan](https://shodan.io)
|
47
47
|
- [Spyse](https://spyse.com)
|
48
48
|
- [urlscan.io](https://urlscan.io)
|
49
|
-
- [VirusTotal](http://virustotal.com)
|
49
|
+
- [VirusTotal](http://virustotal.com) & [VirusTotal Intelligence](https://www.virustotal.com/gui/intelligence-overview)
|
50
50
|
- [ZoomEye](https://zoomeye.org)
|
51
51
|
|
52
52
|
## Docs
|
data/config.ru
CHANGED
@@ -4,6 +4,30 @@ require "uuidtools"
|
|
4
4
|
|
5
5
|
module Mihari
|
6
6
|
module Analyzers
|
7
|
+
ANALYZER_TO_CLASS = {
|
8
|
+
"binaryedge" => BinaryEdge,
|
9
|
+
"censys" => Censys,
|
10
|
+
"circl" => CIRCL,
|
11
|
+
"crtsh" => Crtsh,
|
12
|
+
"dnpedia" => DNPedia,
|
13
|
+
"dnstwister" => DNSTwister,
|
14
|
+
"onyphe" => Onyphe,
|
15
|
+
"otx" => OTX,
|
16
|
+
"passivetotal" => PassiveTotal,
|
17
|
+
"pt" => PassiveTotal,
|
18
|
+
"pulsedive" => Pulsedive,
|
19
|
+
"securitytrails" => SecurityTrails,
|
20
|
+
"shodan" => Shodan,
|
21
|
+
"spyse" => Spyse,
|
22
|
+
"st" => SecurityTrails,
|
23
|
+
"urlscan" => Urlscan,
|
24
|
+
"virustotal_intelligence" => VirusTotalIntelligence,
|
25
|
+
"virustotal" => VirusTotal,
|
26
|
+
"vt_intel" => VirusTotalIntelligence,
|
27
|
+
"vt" => VirusTotal,
|
28
|
+
"zoomeye" => ZoomEye
|
29
|
+
}.freeze
|
30
|
+
|
7
31
|
class Rule < Base
|
8
32
|
include Mihari::Mixins::DisallowedDataValue
|
9
33
|
|
@@ -26,25 +50,6 @@ module Mihari
|
|
26
50
|
validate_analyzer_configurations
|
27
51
|
end
|
28
52
|
|
29
|
-
ANALYZER_TO_CLASS = {
|
30
|
-
"binaryedge" => BinaryEdge,
|
31
|
-
"censys" => Censys,
|
32
|
-
"circl" => CIRCL,
|
33
|
-
"crtsh" => Crtsh,
|
34
|
-
"dnpedia" => DNPedia,
|
35
|
-
"dnstwister" => DNSTwister,
|
36
|
-
"onyphe" => Onyphe,
|
37
|
-
"otx" => OTX,
|
38
|
-
"passivetotal" => PassiveTotal,
|
39
|
-
"pulsedive" => Pulsedive,
|
40
|
-
"securitytrails" => SecurityTrails,
|
41
|
-
"shodan" => Shodan,
|
42
|
-
"spyse" => Spyse,
|
43
|
-
"urlscan" => Urlscan,
|
44
|
-
"virustotal" => VirusTotal,
|
45
|
-
"zoomeye" => ZoomEye
|
46
|
-
}.freeze
|
47
|
-
|
48
53
|
#
|
49
54
|
# Returns a list of artifacts matched with queries
|
50
55
|
#
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "virustotal"
|
4
|
+
|
5
|
+
module Mihari
|
6
|
+
module Analyzers
|
7
|
+
class VirusTotalIntelligence < Base
|
8
|
+
param :query
|
9
|
+
option :title, default: proc { "VirusTotal Intelligence search" }
|
10
|
+
option :description, default: proc { "query = #{query}" }
|
11
|
+
option :tags, default: proc { [] }
|
12
|
+
|
13
|
+
def initialize(*args, **kwargs)
|
14
|
+
super
|
15
|
+
|
16
|
+
@query = query
|
17
|
+
end
|
18
|
+
|
19
|
+
def artifacts
|
20
|
+
responses = search_witgh_cursor
|
21
|
+
responses.map do |response|
|
22
|
+
response.data.map(&:value)
|
23
|
+
end.flatten.compact.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def configuration_keys
|
29
|
+
%w[virustotal_api_key]
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# VT API
|
34
|
+
#
|
35
|
+
# @return [::VirusTotal::API]
|
36
|
+
#
|
37
|
+
def api
|
38
|
+
@api = ::VirusTotal::API.new(key: Mihari.config.virustotal_api_key)
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Search with cursor
|
43
|
+
#
|
44
|
+
# @return [Array<Structs::VirusTotalIntelligence::Response>]
|
45
|
+
#
|
46
|
+
def search_witgh_cursor
|
47
|
+
cursor = nil
|
48
|
+
responses = []
|
49
|
+
|
50
|
+
loop do
|
51
|
+
response = Structs::VirusTotalIntelligence::Response.from_dynamic!(api.intelligence.search(query, cursor: cursor))
|
52
|
+
responses << response
|
53
|
+
|
54
|
+
break if response.meta.cursor.nil?
|
55
|
+
|
56
|
+
cursor = response.meta.cursor
|
57
|
+
end
|
58
|
+
|
59
|
+
responses
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/mihari/cli/analyzer.rb
CHANGED
@@ -14,6 +14,7 @@ require "mihari/commands/securitytrails"
|
|
14
14
|
require "mihari/commands/shodan"
|
15
15
|
require "mihari/commands/spyse"
|
16
16
|
require "mihari/commands/urlscan"
|
17
|
+
require "mihari/commands/virustotal_intelligence"
|
17
18
|
require "mihari/commands/virustotal"
|
18
19
|
require "mihari/commands/zoomeye"
|
19
20
|
|
@@ -42,6 +43,7 @@ module Mihari
|
|
42
43
|
include Mihari::Commands::Spyse
|
43
44
|
include Mihari::Commands::Urlscan
|
44
45
|
include Mihari::Commands::VirusTotal
|
46
|
+
include Mihari::Commands::VirusTotalIntelligence
|
45
47
|
include Mihari::Commands::ZoomEye
|
46
48
|
end
|
47
49
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mihari
|
4
|
+
module Commands
|
5
|
+
module VirusTotalIntelligence
|
6
|
+
def self.included(thor)
|
7
|
+
thor.class_eval do
|
8
|
+
desc "virustotal_intelligence [QUERY]", "VirusTotal Intelligence 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 virustotal_intelligence(query)
|
13
|
+
with_error_handling do
|
14
|
+
run_analyzer Analyzers::VirusTotalIntelligence, query: query, options: options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
map "vt_intel" => :virustotal_intelligence
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
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
|
@@ -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,75 @@
|
|
1
|
+
require "json"
|
2
|
+
require "dry/struct"
|
3
|
+
|
4
|
+
module Mihari
|
5
|
+
module Structs
|
6
|
+
module VirusTotalIntelligence
|
7
|
+
class ContextAttributes < Dry::Struct
|
8
|
+
attribute :url, Types.Array(Types::String).optional
|
9
|
+
|
10
|
+
def self.from_dynamic!(d)
|
11
|
+
d = Types::Hash[d]
|
12
|
+
new(
|
13
|
+
url: d["url"]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class Datum < Dry::Struct
|
19
|
+
attribute :type, Types::String
|
20
|
+
attribute :id, Types::String
|
21
|
+
attribute :context_attributes, ContextAttributes.optional
|
22
|
+
|
23
|
+
def value
|
24
|
+
case type
|
25
|
+
when "file"
|
26
|
+
id
|
27
|
+
when "url"
|
28
|
+
(context_attributes.url || []).first
|
29
|
+
when "domain"
|
30
|
+
id
|
31
|
+
when "ip_address"
|
32
|
+
id
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.from_dynamic!(d)
|
37
|
+
d = Types::Hash[d]
|
38
|
+
|
39
|
+
context_attributes = nil
|
40
|
+
context_attributes = ContextAttributes.from_dynamic!(d.fetch("context_attributes")) if d.key?("context_attributes")
|
41
|
+
|
42
|
+
new(
|
43
|
+
type: d.fetch("type"),
|
44
|
+
id: d.fetch("id"),
|
45
|
+
context_attributes: context_attributes
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Meta < Dry::Struct
|
51
|
+
attribute :cursor, Types::String.optional
|
52
|
+
|
53
|
+
def self.from_dynamic!(d)
|
54
|
+
d = Types::Hash[d]
|
55
|
+
new(
|
56
|
+
cursor: d["cursor"]
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Response < Dry::Struct
|
62
|
+
attribute :meta, Meta
|
63
|
+
attribute :data, Types.Array(Datum)
|
64
|
+
|
65
|
+
def self.from_dynamic!(d)
|
66
|
+
d = Types::Hash[d]
|
67
|
+
new(
|
68
|
+
meta: Meta.from_dynamic!(d.fetch("meta")),
|
69
|
+
data: d.fetch("data").map { |x| Datum.from_dynamic!(x) }
|
70
|
+
)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/mihari/types.rb
CHANGED
@@ -9,13 +9,28 @@ 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
|
|
15
16
|
AnalyzerTypes = Types::String.enum(
|
16
|
-
"binaryedge",
|
17
|
-
"
|
18
|
-
"
|
17
|
+
"binaryedge",
|
18
|
+
"censys",
|
19
|
+
"circl",
|
20
|
+
"dnpedia",
|
21
|
+
"dnstwister",
|
22
|
+
"onyphe",
|
23
|
+
"otx",
|
24
|
+
"passivetotal",
|
25
|
+
"pt",
|
26
|
+
"pulsedive",
|
27
|
+
"securitytrails",
|
28
|
+
"shodan",
|
29
|
+
"st",
|
30
|
+
"virustotal_intelligence",
|
31
|
+
"virustotal",
|
32
|
+
"vt_intel",
|
33
|
+
"vt"
|
19
34
|
)
|
20
35
|
end
|
21
36
|
end
|
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
|