mihari 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0d889b6f04bff599f1dbb8eac861469500061e5ef4c3f48e4e4624d0c4ce57a
4
- data.tar.gz: 0201ba42b96271982b78d28ac7f8c01f0e34a398d5f897b5e5b1e7f0fb1573cb
3
+ metadata.gz: 487e9fb5b564d2f9edfdd225c5188dd8505e282a106ffd6434c159f1a05bf6b5
4
+ data.tar.gz: 2149a69537d25d65cd7a036190351d0d89e8bf5a6fe99f79076f8328445f21b1
5
5
  SHA512:
6
- metadata.gz: b32e5330ba7f77c9c2a6411de65ef91bd49a7798bef817c0ed2ae76ee8818c81dd4e3b24970361017ba60dbb9c629b508bb13abf0ffa81978c0bca8d1c9fc1df
7
- data.tar.gz: 9ec9fc6d441b83f0e337f4af7647ddd7a15600c7cfb371e4a05dba066e3a6bf8933a43261b27b76f24ea474a69b1da48e98b4cf22edd2ffdf5cc7697b7e6b69b
6
+ metadata.gz: 437dc50a254afd8a0f444224665a47fab6bd0314ad403df2f83f2bca719ac5172064348306146e97647e41b7bb87502845e4459480660500763f8fe63126c4ed
7
+ data.tar.gz: 704c26e0a0a62e7481bb185a6e0af2823dcf528bb49224ab6620215b66f7bec082d8fa52aa1d0d093470fb5b1e0a2afe6f81c25e181071eb73fede734b144106
data/README.md CHANGED
@@ -39,13 +39,16 @@ mihari supports Censys, Shodan, Onyphe, urlscan and VirusTotal by default.
39
39
  ```bash
40
40
  $ mihari
41
41
  Commands:
42
+ mihari alerts # Show the alerts on TheHive
42
43
  mihari censys [QUERY] # Censys IPv4 lookup by a given query
43
44
  mihari help [COMMAND] # Describe available commands or one specific command
44
45
  mihari import_from_json # Give a JSON input via STDIN
45
46
  mihari onyphe [QUERY] # Onyphe datascan lookup by a given query
46
47
  mihari shodan [QUERY] # Shodan host lookup by a given query
48
+ mihari status # Show the current configuration status
47
49
  mihari urlscan [QUERY] # urlscan lookup by a given query
48
50
  mihari virustotal [IP|DOMAIN] # VirusTotal resolutions lookup by a given ip or domain
51
+
49
52
  ```
50
53
 
51
54
  ### Import from JSON
@@ -44,4 +44,6 @@ require "mihari/emitters/the_hive"
44
44
 
45
45
  require "mihari/alert_viewer"
46
46
 
47
+ require "mihari/status"
48
+
47
49
  require "mihari/cli"
@@ -10,8 +10,9 @@ module Mihari
10
10
  attr_reader :description
11
11
  attr_reader :query
12
12
  attr_reader :tags
13
+ attr_reader :target_type
13
14
 
14
- def initialize(query, title: nil, description: nil, tags: [])
15
+ def initialize(query, title: nil, description: nil, tags: [], target_type: "url")
15
16
  super()
16
17
 
17
18
  @api = ::UrlScan::API.new
@@ -19,6 +20,9 @@ module Mihari
19
20
  @title = title || "urlscan lookup"
20
21
  @description = description || "query = #{query}"
21
22
  @tags = tags
23
+ @target_type = target_type
24
+
25
+ raise ArgumentError, "type should be url, domain or ip." unless valid_target_type?
22
26
  end
23
27
 
24
28
  def artifacts
@@ -27,7 +31,7 @@ module Mihari
27
31
 
28
32
  results = result.dig("results") || []
29
33
  results.map do |match|
30
- match.dig "task", "url"
34
+ match.dig "page", target_type
31
35
  end.compact.uniq
32
36
  end
33
37
 
@@ -38,6 +42,10 @@ module Mihari
38
42
  rescue ::UrlScan::ResponseError => _e
39
43
  nil
40
44
  end
45
+
46
+ def valid_target_type?
47
+ %w(url domain ip).include? target_type
48
+ end
41
49
  end
42
50
  end
43
51
  end
@@ -39,6 +39,7 @@ module Mihari
39
39
  method_option :title, type: :string, desc: "title"
40
40
  method_option :description, type: :string, desc: "description"
41
41
  method_option :tags, type: :array, desc: "tags"
42
+ method_option :target_type, type: :string, default: "url", desc: "target type to fetch from lookup results (target type should be 'url', 'domain' or 'ip')"
42
43
  def urlscan(query)
43
44
  with_error_handling do
44
45
  run_analyzer Analyzers::Urlscan, query: query, options: options
@@ -84,6 +85,13 @@ module Mihari
84
85
  end
85
86
  end
86
87
 
88
+ desc "status", "Show the current configuration status"
89
+ def status
90
+ with_error_handling do
91
+ puts JSON.pretty_generate(Status.check)
92
+ end
93
+ end
94
+
87
95
  no_commands do
88
96
  def with_error_handling
89
97
  yield
@@ -104,13 +112,15 @@ module Mihari
104
112
  end
105
113
 
106
114
  def run_analyzer(analyzer_class, query:, options:)
107
- title = options.dig("title")
108
- description = options.dig("description")
109
- tags = options.dig("tags") || []
115
+ options = symbolize_hash_keys(options)
110
116
 
111
- analyzer = analyzer_class.new(query, title: title, description: description, tags: tags)
117
+ analyzer = analyzer_class.new(query, **options)
112
118
  analyzer.run
113
119
  end
120
+
121
+ def symbolize_hash_keys(hash)
122
+ hash.map{ |k, v| [k.to_sym, v] }.to_h
123
+ end
114
124
  end
115
125
  end
116
126
  end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mihari
4
+ class Status
5
+ def check
6
+ {
7
+ shodan: { status: shodan?, message: shodan },
8
+ slack: { status: slack?, message: slack },
9
+ censys: { status: censys?, message: censys },
10
+ virustotal: { status: virustotal?, message: virustotal },
11
+ onyphe: { status: onyphe?, message: onyphe },
12
+ the_hive: { status: the_hive?, message: the_hive },
13
+ }.map do |key, value|
14
+ [key, convert(value)]
15
+ end.to_h
16
+ end
17
+
18
+ def self.check
19
+ new.check
20
+ end
21
+
22
+ private
23
+
24
+ def convert(status:, message:)
25
+ {
26
+ status: status ? "OK" : "Bad",
27
+ message: message
28
+ }
29
+ end
30
+
31
+ def virustotal?
32
+ ENV.key?("VIRUSTOTAL_API_KEY")
33
+ end
34
+
35
+ def virustotal
36
+ virustotal? ? "VIRUSTOTAL_API_KEY is found" : "VIRUSTOTAL_API_KEY is missing"
37
+ end
38
+
39
+ def onyphe?
40
+ ENV.key? "ONYPHE_API_KEY"
41
+ end
42
+
43
+ def onyphe
44
+ onyphe? ? "ONYPHE_API_KEY is found" : "ONYPHE_API_KEY is missing"
45
+ end
46
+
47
+ def censys?
48
+ ENV.key?("CENSYS_ID") && ENV.key?("CENSYS_SECRET")
49
+ end
50
+
51
+ def censys
52
+ censys? ? "CENSYS_ID and CENSYS_SECRET are found" : "CENSYS_ID and CENSYS_SECRET are missing"
53
+ end
54
+
55
+ def shodan?
56
+ ENV.key? "SHODAN_API_KEY"
57
+ end
58
+
59
+ def shodan
60
+ shodan? ? "SHODAN_API_KEY is found" : "SHODAN_API_KEY is missing"
61
+ end
62
+
63
+ def slack?
64
+ ENV.key? "SLACK_WEBHOOK_URL"
65
+ end
66
+
67
+ def slack
68
+ slack? ? "SLACK_WEBHOOK_URL is found" : "SLACK_WEBHOOK_URL is missing"
69
+ end
70
+
71
+ def the_hive?
72
+ ENV.key?("THEHIVE_API_ENDPOINT") && ENV.key?("THEHIVE_API_KEY")
73
+ end
74
+
75
+ def the_hive
76
+ the_hive? ? "THEHIVE_API_ENDPOINT and THEHIVE_API_KEY are found" : "THEHIVE_API_ENDPOINT and THEHIVE_API_KEY are are missing"
77
+ end
78
+ end
79
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "0.5.2"
4
+ VERSION = "0.6.0"
5
5
  end
@@ -29,9 +29,9 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "rake", "~> 12.3"
30
30
  spec.add_development_dependency "rspec", "~> 3.8"
31
31
  spec.add_development_dependency "vcr", "~> 5.0"
32
- spec.add_development_dependency "webmock", "~> 3.6"
32
+ spec.add_development_dependency "webmock", "~> 3.7"
33
33
 
34
- spec.add_dependency "addressable", "~> 2.6"
34
+ spec.add_dependency "addressable", "~> 2.7"
35
35
  spec.add_dependency "censu", "~> 0.2"
36
36
  spec.add_dependency "email_address", "~> 0.1"
37
37
  spec.add_dependency "hachi", "~> 0.2"
@@ -42,6 +42,6 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency "shodanx", "~> 0.1"
43
43
  spec.add_dependency "slack-notifier", "~> 2.3"
44
44
  spec.add_dependency "thor", "~> 0.20"
45
- spec.add_dependency "urlscan", "~> 0.2"
45
+ spec.add_dependency "urlscan", "~> 0.3"
46
46
  spec.add_dependency "virustotalx", "~> 0.1"
47
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mihari
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manabu Niseki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-17 00:00:00.000000000 Z
11
+ date: 2019-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '3.6'
89
+ version: '3.7'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '3.6'
96
+ version: '3.7'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: addressable
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '2.6'
103
+ version: '2.7'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '2.6'
110
+ version: '2.7'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: censu
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -254,14 +254,14 @@ dependencies:
254
254
  requirements:
255
255
  - - "~>"
256
256
  - !ruby/object:Gem::Version
257
- version: '0.2'
257
+ version: '0.3'
258
258
  type: :runtime
259
259
  prerelease: false
260
260
  version_requirements: !ruby/object:Gem::Requirement
261
261
  requirements:
262
262
  - - "~>"
263
263
  - !ruby/object:Gem::Version
264
- version: '0.2'
264
+ version: '0.3'
265
265
  - !ruby/object:Gem::Dependency
266
266
  name: virustotalx
267
267
  requirement: !ruby/object:Gem::Requirement
@@ -315,6 +315,7 @@ files:
315
315
  - lib/mihari/notifiers/base.rb
316
316
  - lib/mihari/notifiers/exception_notifier.rb
317
317
  - lib/mihari/notifiers/slack.rb
318
+ - lib/mihari/status.rb
318
319
  - lib/mihari/the_hive.rb
319
320
  - lib/mihari/the_hive/alert.rb
320
321
  - lib/mihari/the_hive/artifact.rb