mihari 0.5.1 → 0.5.2

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: 6409ca38527e133337f4dbe174615e3c84aff5d4d82effcc40d57e63c0a6f80c
4
- data.tar.gz: 6814631990a33c3c3363863d7e9c00d8d3d1ca4f48f0862226cc5416e7be1a14
3
+ metadata.gz: d0d889b6f04bff599f1dbb8eac861469500061e5ef4c3f48e4e4624d0c4ce57a
4
+ data.tar.gz: 0201ba42b96271982b78d28ac7f8c01f0e34a398d5f897b5e5b1e7f0fb1573cb
5
5
  SHA512:
6
- metadata.gz: 5693f87250cd3f23047932adc24a781074038ebaf34c3a2a4aabc921446053df0f426a259b1cc51d49f0dae5e9f6fdf64a8391dcb45f7c323267051b8b2823fd
7
- data.tar.gz: d5337291e107b38a69ef4d70900b3c90a2c8f5eba13cdc96efb30ded29ff90fa6f0eec08595045fb3407d094f37d9572a458292686088b74b29a3f8e96888c69
6
+ metadata.gz: b32e5330ba7f77c9c2a6411de65ef91bd49a7798bef817c0ed2ae76ee8818c81dd4e3b24970361017ba60dbb9c629b508bb13abf0ffa81978c0bca8d1c9fc1df
7
+ data.tar.gz: 9ec9fc6d441b83f0e337f4af7647ddd7a15600c7cfb371e4a05dba066e3a6bf8933a43261b27b76f24ea474a69b1da48e98b4cf22edd2ffdf5cc7697b7e6b69b
@@ -14,15 +14,15 @@ module Mihari
14
14
  CENSYS_ID_KEY = "CENSYS_ID"
15
15
  CENSYS_SECRET_KEY = "CENSYS_SECRET"
16
16
 
17
- def initialize(query, tags: [])
17
+ def initialize(query, title: nil, description: nil, tags: [])
18
18
  super()
19
19
 
20
20
  raise ArgumentError, "#{CENSYS_ID_KEY} and #{CENSYS_SECRET_KEY} are required" unless valid?
21
21
 
22
22
  @api = ::Censys::API.new
23
23
  @query = query
24
- @title = "Censys lookup"
25
- @description = "query = #{query}"
24
+ @title = title || "Censys lookup"
25
+ @description = description || "query = #{query}"
26
26
  @tags = tags
27
27
  end
28
28
 
@@ -11,13 +11,13 @@ module Mihari
11
11
  attr_reader :query
12
12
  attr_reader :tags
13
13
 
14
- def initialize(query, tags: [])
14
+ def initialize(query, title: nil, description: nil, tags: [])
15
15
  super()
16
16
 
17
17
  @api = ::Onyphe::API.new
18
18
  @query = query
19
- @title = "Onyphe lookup"
20
- @description = "query = #{query}"
19
+ @title = title || "Onyphe lookup"
20
+ @description = description || "query = #{query}"
21
21
  @tags = tags
22
22
  end
23
23
 
@@ -11,13 +11,13 @@ module Mihari
11
11
  attr_reader :query
12
12
  attr_reader :tags
13
13
 
14
- def initialize(query, tags: [])
14
+ def initialize(query, title: nil, description: nil, tags: [])
15
15
  super()
16
16
 
17
17
  @api = ::Shodan::API.new
18
18
  @query = query
19
- @title = "Shodan lookup"
20
- @description = "query = #{query}"
19
+ @title = title || "Shodan lookup"
20
+ @description = description || "query = #{query}"
21
21
  @tags = tags
22
22
  end
23
23
 
@@ -11,13 +11,13 @@ module Mihari
11
11
  attr_reader :query
12
12
  attr_reader :tags
13
13
 
14
- def initialize(query, tags: [])
14
+ def initialize(query, title: nil, description: nil, tags: [])
15
15
  super()
16
16
 
17
17
  @api = ::UrlScan::API.new
18
18
  @query = query
19
- @title = "urlscan lookup"
20
- @description = "query = #{query}"
19
+ @title = title || "urlscan lookup"
20
+ @description = description || "query = #{query}"
21
21
  @tags = tags
22
22
  end
23
23
 
@@ -13,15 +13,15 @@ module Mihari
13
13
  attr_reader :description
14
14
  attr_reader :tags
15
15
 
16
- def initialize(indicator, tags: [])
16
+ def initialize(indicator, title: nil, description: nil, tags: [])
17
17
  super()
18
18
 
19
19
  @api = ::VirusTotal::API.new
20
20
  @indicator = indicator
21
21
  @type = TypeChecker.type(indicator)
22
22
 
23
- @title = "VirusTotal lookup"
24
- @description = "indicator = #{indicator}"
23
+ @title = title || "VirusTotal lookup"
24
+ @description = description || "indicator = #{indicator}"
25
25
  @tags = tags
26
26
  end
27
27
 
@@ -6,52 +6,52 @@ require "json"
6
6
  module Mihari
7
7
  class CLI < Thor
8
8
  desc "censys [QUERY]", "Censys IPv4 lookup by a given query"
9
+ method_option :title, type: :string, desc: "title"
10
+ method_option :description, type: :string, desc: "description"
9
11
  method_option :tags, type: :array, desc: "tags"
10
12
  def censys(query)
11
13
  with_error_handling do
12
- tags = options.dig("tags") || []
13
- censys = Analyzers::Censys.new(query, tags: tags)
14
- censys.run
14
+ run_analyzer Analyzers::Censys, query: query, options: options
15
15
  end
16
16
  end
17
17
 
18
18
  desc "shodan [QUERY]", "Shodan host lookup by a given query"
19
+ method_option :title, type: :string, desc: "title"
20
+ method_option :description, type: :string, desc: "description"
19
21
  method_option :tags, type: :array, desc: "tags"
20
22
  def shodan(query)
21
23
  with_error_handling do
22
- tags = options.dig("tags") || []
23
- shodan = Analyzers::Shodan.new(query, tags: tags)
24
- shodan.run
24
+ run_analyzer Analyzers::Shodan, query: query, options: options
25
25
  end
26
26
  end
27
27
 
28
28
  desc "onyphe [QUERY]", "Onyphe datascan lookup by a given query"
29
+ method_option :title, type: :string, desc: "title"
30
+ method_option :description, type: :string, desc: "description"
29
31
  method_option :tags, type: :array, desc: "tags"
30
32
  def onyphe(query)
31
33
  with_error_handling do
32
- tags = options.dig("tags") || []
33
- onyphe = Analyzers::Onyphe.new(query, tags: tags)
34
- onyphe.run
34
+ run_analyzer Analyzers::Onyphe, query: query, options: options
35
35
  end
36
36
  end
37
37
 
38
38
  desc "urlscan [QUERY]", "urlscan lookup by a given query"
39
+ method_option :title, type: :string, desc: "title"
40
+ method_option :description, type: :string, desc: "description"
39
41
  method_option :tags, type: :array, desc: "tags"
40
42
  def urlscan(query)
41
43
  with_error_handling do
42
- tags = options.dig("tags") || []
43
- urlscan = Analyzers::Urlscan.new(query, tags: tags)
44
- urlscan.run
44
+ run_analyzer Analyzers::Urlscan, query: query, options: options
45
45
  end
46
46
  end
47
47
 
48
48
  desc "virustotal [IP|DOMAIN]", "VirusTotal resolutions lookup by a given ip or domain"
49
+ method_option :title, type: :string, desc: "title"
50
+ method_option :description, type: :string, desc: "description"
49
51
  method_option :tags, type: :array, desc: "tags"
50
52
  def virustotal(indiactor)
51
53
  with_error_handling do
52
- tags = options.dig("tags") || []
53
- virustotal = Analyzers::VirusTotal.new(indiactor, tags: tags)
54
- virustotal.run
54
+ run_analyzer Analyzers::VirusTotal, query: indiactor, options: options
55
55
  end
56
56
  end
57
57
 
@@ -102,6 +102,15 @@ module Mihari
102
102
  def valid_json?(json)
103
103
  %w(title description artifacts).all? { |key| json.key? key }
104
104
  end
105
+
106
+ def run_analyzer(analyzer_class, query:, options:)
107
+ title = options.dig("title")
108
+ description = options.dig("description")
109
+ tags = options.dig("tags") || []
110
+
111
+ analyzer = analyzer_class.new(query, title: title, description: description, tags: tags)
112
+ analyzer.run
113
+ end
105
114
  end
106
115
  end
107
116
  end
@@ -16,32 +16,26 @@ module Mihari
16
16
  @data_type = data_type
17
17
  end
18
18
 
19
- def fields
20
- [vt_link, urlscan_link].compact
21
- end
22
-
23
19
  def actions
24
- [vt_link, urlscan_link].compact
20
+ [vt_link, urlscan_link, censys_link].compact
25
21
  end
26
22
 
27
23
  def vt_link
28
24
  return nil unless _vt_link
29
25
 
30
- {
31
- type: "button",
32
- text: "Lookup on VirusTotal",
33
- url: _vt_link,
34
- }
26
+ { type: "button", text: "Lookup on VirusTotal", url: _vt_link, }
35
27
  end
36
28
 
37
29
  def urlscan_link
38
30
  return nil unless _urlscan_link
39
31
 
40
- {
41
- type: "button",
42
- text: "Lookup on urlscan.io",
43
- url: _urlscan_link,
44
- }
32
+ { type: "button", text: "Lookup on urlscan.io", url: _urlscan_link, }
33
+ end
34
+
35
+ def censys_link
36
+ return nil unless _censys_link
37
+
38
+ { type: "button", text: "Lookup on Censys", url: _censys_link, }
45
39
  end
46
40
 
47
41
  # @return [Array]
@@ -88,6 +82,11 @@ module Mihari
88
82
  end
89
83
  memoize :_vt_link
90
84
 
85
+ def _censys_link
86
+ data_type == "ip" ? "https://censys.io/ipv4/#{data}" : nil
87
+ end
88
+ memoize :_censys_link
89
+
91
90
  # @return [String]
92
91
  def sha256
93
92
  Digest::SHA256.hexdigest data
@@ -7,7 +7,7 @@ module Mihari
7
7
  class ExceptionNotifier
8
8
  def initialize
9
9
  @backtrace_lines = 10
10
- @color = 'danger'
10
+ @color = "danger"
11
11
 
12
12
  @slack = Notifiers::Slack.new
13
13
  end
@@ -44,20 +44,20 @@ module Mihari
44
44
  end
45
45
 
46
46
  def to_text(exception_class)
47
- measure_word = /^[aeiou]/i.match?(exception_class.to_s) ? 'An' : 'A'
47
+ measure_word = /^[aeiou]/i.match?(exception_class.to_s) ? "An" : "A"
48
48
  exception_name = "*#{measure_word}* `#{exception_class}`"
49
49
  "#{exception_name} *occured in background*\n"
50
50
  end
51
51
 
52
52
  def to_fields(clean_message, backtrace)
53
53
  fields = [
54
- { title: 'exception', value: clean_message },
55
- { title: 'Hostname', value: hostname }
54
+ { title: "Exception", value: clean_message },
55
+ { title: "Hostname", value: hostname }
56
56
  ]
57
57
 
58
58
  if backtrace
59
59
  formatted_backtrace = format_backtrace(backtrace)
60
- fields << { title: 'Backtrace', value: formatted_backtrace }
60
+ fields << { title: "Backtrace", value: formatted_backtrace }
61
61
  end
62
62
  fields
63
63
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mihari
4
- VERSION = "0.5.1"
4
+ VERSION = "0.5.2"
5
5
  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.1
4
+ version: 0.5.2
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-16 00:00:00.000000000 Z
11
+ date: 2019-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler