mihari 4.1.0 → 4.2.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 +1 -1
- data/README.md +1 -1
- data/Rakefile +5 -0
- data/config.ru +0 -1
- data/lib/mihari/analyzers/base.rb +18 -10
- data/lib/mihari/analyzers/rule.rb +1 -1
- data/lib/mihari/cli/base.rb +0 -4
- data/lib/mihari/commands/init.rb +1 -1
- data/lib/mihari/commands/search.rb +11 -58
- data/lib/mihari/commands/validator.rb +1 -2
- data/lib/mihari/database.rb +1 -1
- data/lib/mihari/emitters/base.rb +5 -2
- data/lib/mihari/emitters/slack.rb +40 -4
- data/lib/mihari/enrichers/base.rb +5 -2
- data/lib/mihari/enrichers/ipinfo.rb +4 -3
- data/lib/mihari/{web/entities → entities}/alert.rb +0 -0
- data/lib/mihari/{web/entities → entities}/artifact.rb +0 -0
- data/lib/mihari/{web/entities → entities}/autonomous_system.rb +0 -0
- data/lib/mihari/{web/entities → entities}/command.rb +0 -0
- data/lib/mihari/{web/entities → entities}/config.rb +0 -0
- data/lib/mihari/{web/entities → entities}/dns.rb +0 -0
- data/lib/mihari/{web/entities → entities}/geolocation.rb +0 -0
- data/lib/mihari/{web/entities → entities}/ip_address.rb +0 -0
- data/lib/mihari/{web/entities → entities}/message.rb +0 -0
- data/lib/mihari/{web/entities → entities}/reverse_dns.rb +0 -0
- data/lib/mihari/{web/entities → entities}/rule.rb +0 -0
- data/lib/mihari/{web/entities → entities}/source.rb +0 -0
- data/lib/mihari/{web/entities → entities}/tag.rb +0 -0
- data/lib/mihari/{web/entities → entities}/whois.rb +0 -0
- data/lib/mihari/errors.rb +2 -0
- data/lib/mihari/feed/reader.rb +11 -55
- data/lib/mihari/http.rb +94 -0
- data/lib/mihari/mixins/error_notification.rb +20 -0
- data/lib/mihari/mixins/retriable.rb +12 -2
- data/lib/mihari/mixins/rule.rb +1 -2
- data/lib/mihari/structs/ipinfo.rb +2 -3
- data/lib/mihari/structs/rule.rb +30 -0
- data/lib/mihari/structs/shodan.rb +9 -1
- data/lib/mihari/version.rb +1 -1
- data/lib/mihari/web/api.rb +0 -20
- data/lib/mihari/web/app.rb +3 -3
- data/lib/mihari/web/endpoints/rules.rb +3 -1
- data/lib/mihari/web/middleware/error_notification_adapter.rb +19 -0
- data/lib/mihari/web/public/index.html +1 -1
- data/lib/mihari/web/public/redoc-static.html +1881 -165
- data/lib/mihari/web/public/static/css/app.43138058.css +1 -0
- data/lib/mihari/web/public/static/css/chunk-vendors.3ed9b08e.css +7 -0
- data/lib/mihari/web/public/static/fonts/fa-brands-400.1fd0b4d7.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-brands-400.5d5236fb.woff2 +0 -0
- data/lib/mihari/web/public/static/fonts/fa-regular-400.64b3730e.woff2 +0 -0
- data/lib/mihari/web/public/static/fonts/fa-regular-400.95a8a8af.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-solid-900.6115ad71.woff2 +0 -0
- data/lib/mihari/web/public/static/fonts/fa-solid-900.f0203cfc.ttf +0 -0
- data/lib/mihari/web/public/static/fonts/fa-v4compatibility.e1023515.ttf +0 -0
- data/lib/mihari/web/public/static/js/app-legacy.46b666f0.js +2 -0
- data/lib/mihari/web/public/static/js/app-legacy.46b666f0.js.map +1 -0
- data/lib/mihari/web/public/static/js/app.4818aedd.js +2 -0
- data/lib/mihari/web/public/static/js/app.4818aedd.js.map +1 -0
- data/lib/mihari/web/public/static/js/app.b88ce341.js +35 -0
- data/lib/mihari/web/public/static/js/app.b88ce341.js.map +1 -0
- data/lib/mihari/web/public/static/js/chunk-vendors-legacy.c99e452e.js +17 -0
- data/lib/mihari/web/public/static/js/chunk-vendors-legacy.c99e452e.js.map +1 -0
- data/lib/mihari/web/public/static/js/chunk-vendors.15e84e22.js +23 -0
- data/lib/mihari/web/public/static/js/chunk-vendors.15e84e22.js.map +1 -0
- data/lib/mihari.rb +63 -15
- data/mihari.gemspec +12 -12
- data/sig/lib/mihari/emitters/slack.rbs +29 -1
- data/sig/lib/mihari/feed/reader.rbs +2 -2
- data/sig/lib/mihari/http.rbs +65 -0
- data/sig/lib/mihari/mixins/error_notification.rbs +12 -0
- data/sig/lib/mihari/structs/rule.rbs +6 -0
- data/sig/lib/mihari.rbs +4 -8
- metadata +88 -73
- data/lib/mihari/cli/mixins/utils.rb +0 -72
- data/lib/mihari/emitters/stdout.rb +0 -22
- data/lib/mihari/notifiers/base.rb +0 -24
- data/lib/mihari/notifiers/exception_notifier.rb +0 -126
- data/lib/mihari/notifiers/slack.rb +0 -63
- data/sig/lib/mihari/cli/mixins/utils.rbs +0 -50
- data/sig/lib/mihari/notifiers/base.rbs +0 -18
- data/sig/lib/mihari/notifiers/exception_notifier.rbs +0 -75
- data/sig/lib/mihari/notifiers/slack.rbs +0 -50
@@ -14,13 +14,12 @@ module Mihari
|
|
14
14
|
include Mixins::AutonomousSystem
|
15
15
|
|
16
16
|
def from_dynamic!(d)
|
17
|
+
d = d.deep_stringify_keys
|
17
18
|
d = Types::Hash[d]
|
18
19
|
|
19
20
|
asn = nil
|
20
21
|
asn_ = d.dig("asn", "asn")
|
21
|
-
unless asn_.nil?
|
22
|
-
asn = normalize_asn(asn_)
|
23
|
-
end
|
22
|
+
asn = normalize_asn(asn_) unless asn_.nil?
|
24
23
|
|
25
24
|
new(
|
26
25
|
ip: d.fetch("ip"),
|
data/lib/mihari/structs/rule.rb
CHANGED
@@ -121,6 +121,36 @@ module Mihari
|
|
121
121
|
data: data
|
122
122
|
)
|
123
123
|
end
|
124
|
+
|
125
|
+
#
|
126
|
+
# @return [Mihari::Analyzers::Rule]
|
127
|
+
#
|
128
|
+
def to_analyzer
|
129
|
+
analyzer = Mihari::Analyzers::Rule.new(
|
130
|
+
title: self[:title],
|
131
|
+
description: self[:description],
|
132
|
+
tags: self[:tags],
|
133
|
+
queries: self[:queries],
|
134
|
+
allowed_data_types: self[:allowed_data_types],
|
135
|
+
disallowed_data_values: self[:disallowed_data_values],
|
136
|
+
id: id
|
137
|
+
)
|
138
|
+
analyzer.ignore_old_artifacts = self[:ignore_old_artifacts]
|
139
|
+
analyzer.ignore_threshold = self[:ignore_threshold]
|
140
|
+
|
141
|
+
analyzer
|
142
|
+
end
|
143
|
+
|
144
|
+
class << self
|
145
|
+
#
|
146
|
+
# @param [Mihari::Rule] model
|
147
|
+
#
|
148
|
+
# @return [Mihari::Structs::Rule::Rule]
|
149
|
+
#
|
150
|
+
def from_model(model)
|
151
|
+
Structs::Rule::Rule.new(model.data)
|
152
|
+
end
|
153
|
+
end
|
124
154
|
end
|
125
155
|
end
|
126
156
|
end
|
@@ -26,9 +26,17 @@ module Mihari
|
|
26
26
|
|
27
27
|
def self.from_dynamic!(d)
|
28
28
|
d = Types::Hash[d]
|
29
|
+
|
30
|
+
# hostnames should be an array of string but sometimes Shodan returns a string
|
31
|
+
# e.g. "hostnames": "set(['149.28.146.131.vultr.com', 'rebs.ga'])",
|
32
|
+
# https://github.com/ninoseki/mihari/issues/424
|
33
|
+
# so use an empty array if hostnames is a string
|
34
|
+
hostnames = d.fetch("hostnames")
|
35
|
+
hostnames = [] if hostnames.is_a?(String)
|
36
|
+
|
29
37
|
new(
|
30
38
|
asn: d["asn"],
|
31
|
-
hostnames:
|
39
|
+
hostnames: hostnames,
|
32
40
|
location: Location.from_dynamic!(d.fetch("location")),
|
33
41
|
domains: d.fetch("domains"),
|
34
42
|
ip_str: d.fetch("ip_str"),
|
data/lib/mihari/version.rb
CHANGED
data/lib/mihari/web/api.rb
CHANGED
@@ -1,25 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Entities
|
4
|
-
require "mihari/web/entities/message"
|
5
|
-
|
6
|
-
require "mihari/web/entities/autonomous_system"
|
7
|
-
require "mihari/web/entities/command"
|
8
|
-
require "mihari/web/entities/config"
|
9
|
-
require "mihari/web/entities/dns"
|
10
|
-
require "mihari/web/entities/geolocation"
|
11
|
-
require "mihari/web/entities/ip_address"
|
12
|
-
require "mihari/web/entities/reverse_dns"
|
13
|
-
require "mihari/web/entities/source"
|
14
|
-
require "mihari/web/entities/tag"
|
15
|
-
require "mihari/web/entities/whois"
|
16
|
-
|
17
|
-
require "mihari/web/entities/artifact"
|
18
|
-
|
19
|
-
require "mihari/web/entities/alert"
|
20
|
-
|
21
|
-
require "mihari/web/entities/rule"
|
22
|
-
|
23
3
|
# Endpoints
|
24
4
|
require "mihari/web/endpoints/alerts"
|
25
5
|
require "mihari/web/endpoints/artifacts"
|
data/lib/mihari/web/app.rb
CHANGED
@@ -6,12 +6,11 @@ require "rack/contrib"
|
|
6
6
|
require "rack/handler/puma"
|
7
7
|
require "rack/cors"
|
8
8
|
|
9
|
-
require "grape"
|
10
|
-
require "grape-entity"
|
11
9
|
require "grape-swagger"
|
12
10
|
require "grape-swagger-entity"
|
13
11
|
|
14
12
|
require "mihari/web/middleware/connection_adapter"
|
13
|
+
require "mihari/web/middleware/error_notification_adapter"
|
15
14
|
|
16
15
|
require "mihari/web/api"
|
17
16
|
|
@@ -37,12 +36,13 @@ module Mihari
|
|
37
36
|
end
|
38
37
|
|
39
38
|
use Middleware::ConnectionAdapter
|
39
|
+
use Middleware::ErrorNotificationAdapter
|
40
40
|
|
41
41
|
run App.new
|
42
42
|
end.to_app
|
43
43
|
end
|
44
44
|
|
45
|
-
def run!(port: 9292, host: "localhost", threads: "0:
|
45
|
+
def run!(port: 9292, host: "localhost", threads: "0:5", verbose: false)
|
46
46
|
url = "http://#{host}:#{port}"
|
47
47
|
|
48
48
|
Rack::Handler::Puma.run(instance, Port: port, Host: host, Threads: threads, Verbose: verbose) do |_launcher|
|
@@ -79,7 +79,9 @@ module Mihari
|
|
79
79
|
error!({ message: "ID:#{id} is not found" }, 404)
|
80
80
|
end
|
81
81
|
|
82
|
-
Mihari::
|
82
|
+
struct = Mihari::Structs::Rule::Rule.from_model(rule)
|
83
|
+
analyzer = struct.to_analyzer
|
84
|
+
analyzer.run
|
83
85
|
|
84
86
|
status 201
|
85
87
|
present({ message: "ID:#{id} is ran successfully" }, with: Entities::Message)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mihari
|
2
|
+
module Middleware
|
3
|
+
class ErrorNotificationAdapter
|
4
|
+
include Mixins::ErrorNotification
|
5
|
+
|
6
|
+
def initialize(app)
|
7
|
+
@app = app
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
with_error_notification do
|
12
|
+
status, headers, body = @app.call(env)
|
13
|
+
|
14
|
+
[status, headers, body]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1 +1 @@
|
|
1
|
-
<!
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="icon" href="/static/favicon.ico"/><title>Mihari</title><script defer="defer" type="module" src="/static/js/chunk-vendors.15e84e22.js"></script><script defer="defer" type="module" src="/static/js/app.4818aedd.js"></script><link href="/static/css/chunk-vendors.3ed9b08e.css" rel="stylesheet"><link href="/static/css/app.43138058.css" rel="stylesheet"><script defer="defer" src="/static/js/chunk-vendors-legacy.c99e452e.js" nomodule></script><script defer="defer" src="/static/js/app-legacy.46b666f0.js" nomodule></script></head><body><noscript><strong>We're sorry but Mihari doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|