lita-virus_total 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 29200a16bfc71672fb8d6bb18b548428ab5d16b9
4
+ data.tar.gz: 4003a68bcb994e5b93a613b8c7e1049abe66ad64
5
+ SHA512:
6
+ metadata.gz: 8015982961ece102effa7f664a96f95127aa6770d84f284f2f130e39bb5a0bfc9bd8b23ae71766879f016296763c6c5836e60998bdff7eaac1746312e3aa01e5
7
+ data.tar.gz: 4991e3f52eb48b5397066be9673aa3c6897494d9a6c2ada4701e2ec01d96a7bdd41ab43a1f8320a2e9f3d34903402be27d9a760b3c9083b379d0f96fcd35dd6e
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,7 @@
1
+ # I never write any, so don't bug me about it
2
+ Documentation:
3
+ Enabled: false
4
+
5
+ # 80 is rather short
6
+ LineLength:
7
+ Max: 120
@@ -0,0 +1 @@
1
+ lita-virus_total
@@ -0,0 +1 @@
1
+ ruby-2.2.3
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ script: bundle exec rake
5
+ before_install:
6
+ - gem update --system
7
+ services:
8
+ - redis-server
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2015, Constant Contact
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,33 @@
1
+ # lita-virus_total
2
+
3
+ [![Build Status](https://travis-ci.org/constantcontact/lita-virus_total.png?branch=master)](https://travis-ci.org/constantcontact/lita-virus_total)
4
+ [![Coverage Status](https://coveralls.io/repos/constantcontact/lita-virus_total/badge.svg?branch=master&service=github)](https://coveralls.io/github/constantcontact/lita-virus_total?branch=master)
5
+
6
+ Adds the capability to call the virus total api to scan for file hashes and urls.
7
+
8
+ ## Installation
9
+
10
+ Add lita-virus_total to your Lita instance's Gemfile:
11
+
12
+ ``` ruby
13
+ gem "lita-virus_total"
14
+ ```
15
+
16
+ ## Configuration
17
+
18
+ Add your api to to lita:
19
+
20
+ ```ruby
21
+ Lita.configure do |config|
22
+ ...
23
+ config.handlers.virus_total.api_key = ENV['VIRUS_TOTAL_KEY']
24
+ ...
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ The plugin adds two routes that both call the virus total api. Both routes can take a url/dns or a file hash.
30
+
31
+ `vt PATTERN` or `virus total PATTERN`
32
+
33
+ Both of these will report the positives/total, the date last scanned and a link to the full report. If there are any positive results then they will also list the scans that had hits.
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+ require 'mutant'
5
+
6
+ RuboCop::RakeTask.new(:rubocop)
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ desc 'Run mutation tests using mutant'
10
+ task :mutant do
11
+ ENV['SKIP_COVERAGE'] = 'true'
12
+ result = Mutant::CLI.run(%w( -Ilib -rlita/virus_total --use rspec Lita::Handlers::VirusTotal))
13
+ fail unless result == Mutant::CLI::EXIT_SUCCESS
14
+ end
15
+
16
+ task default: [:spec, :rubocop, :mutant]
@@ -0,0 +1,71 @@
1
+ module Lita
2
+ module Handlers
3
+ class VirusTotal < Handler
4
+ require 'uirusu'
5
+
6
+ config :api_key, required: true
7
+
8
+ route(/^vt (?<pattern>.*)/i,
9
+ :virus_total,
10
+ command: false,
11
+ help: { 'vt PATTERN' => 'Checks virus total for results of PATTERN' }
12
+ )
13
+
14
+ route(/^virus total (?<pattern>.*)/i,
15
+ :virus_total,
16
+ command: false,
17
+ help: { 'virus total PATTERN' => 'Checks virus total for results of PATTERN' }
18
+ )
19
+
20
+ def virus_total(response)
21
+ match = response.match_data[:pattern]
22
+ message = case match
23
+ when /\S+\.\S+/
24
+ url_report match
25
+ else
26
+ file_report match
27
+ end
28
+
29
+ response.reply message
30
+ end
31
+
32
+ private
33
+
34
+ def header(key, result)
35
+ positive_results = "#{result.fetch('positives', '?')}/#{result.fetch('total', '?')} positive results"
36
+ "#{key} had #{positive_results} on #{result.fetch('scan_date', 'Date Unknown')}"
37
+ end
38
+
39
+ def report(key, result)
40
+ data = []
41
+ data << header(key, result)
42
+ positives = positive_list result
43
+ data << "Positive scans: #{positives}" if positives.any?
44
+ data << "Full report: #{result.fetch('permalink', 'Link Unavailable')}"
45
+
46
+ data.join "\n"
47
+ end
48
+
49
+ def positive_list(result)
50
+ result.fetch('scans', 'Unknown' => 'detected').map { |k, v| k if v['detected'] }.compact
51
+ end
52
+
53
+ def api_key
54
+ Lita.config.handlers.virus_total.api_key
55
+ end
56
+
57
+ def file_report(hash)
58
+ result = Uirusu::VTFile.query_report(api_key, hash)
59
+
60
+ report hash, result
61
+ end
62
+
63
+ def url_report(url)
64
+ result = Uirusu::VTUrl.query_report(api_key, url)
65
+ report url, result
66
+ end
67
+
68
+ Lita.register_handler(self)
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,12 @@
1
+ require 'lita'
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join('..', '..', 'locales', '*.yml'), __FILE__
5
+ )]
6
+
7
+ require 'lita/handlers/virus_total'
8
+
9
+ Lita::Handlers::VirusTotal.template_root File.expand_path(
10
+ File.join('..', '..', 'templates'),
11
+ __FILE__
12
+ )
@@ -0,0 +1,5 @@
1
+ module Lita
2
+ module VirusTotal
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'lita/virus_total/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lita-virus_total'
7
+ spec.version = Lita::VirusTotal::VERSION
8
+ spec.authors = ["'Joseph Henrich'"]
9
+ spec.email = ['jhenrich@constantcontact.com']
10
+ spec.description = 'Use the virus total api to check file hashes and urls'
11
+ spec.summary = 'Use the virus total api to check file hashes and urls'
12
+ spec.homepage = 'http://github.com/constantcontact/lita-virus_total'
13
+ spec.license = 'BSD'
14
+ spec.metadata = { 'lita_plugin_type' => 'handler' }
15
+
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'lita', '>= 4.6'
22
+ spec.add_runtime_dependency 'uirusu', '>= 1.0'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'pry-byebug'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rack-test'
28
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
29
+ spec.add_development_dependency 'simplecov'
30
+ spec.add_development_dependency 'coveralls'
31
+ spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'mutant'
33
+ spec.add_development_dependency 'mutant-rspec'
34
+ end
@@ -0,0 +1,11 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ virus-total:
5
+ help:
6
+ vt_key: 'vt PATTERN'
7
+ virus_total_key: 'virus total PATTERN'
8
+ vt_value: 'Checks virus total for results of PATTERN'
9
+ report:
10
+ header: "%{resource} had %{positives}/%{total} positive results on %{scan_date}"
11
+ link: "Full report: %{link}"
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::VirusTotal, lita_handler: true do
4
+ let(:response) do
5
+ {
6
+ 'positives' => 1,
7
+ 'scans' => { 'useless' => 'nope', 'boring' => 'nope', 'awesome' => 'detected' },
8
+ 'total' => 3,
9
+ 'permalink' => 'http://url.to.thing',
10
+ 'scan_date' => 'today!'
11
+ }
12
+ end
13
+
14
+ let(:clean_response) do
15
+ {
16
+ 'positives' => 0,
17
+ 'scans' => { 'useless' => 'nope', 'cool' => 'nope', 'awesome' => 'nope' },
18
+ 'total' => 3,
19
+ 'permalink' => 'http://url.to.thing',
20
+ 'scan_date' => 'today!'
21
+ }
22
+ end
23
+
24
+ before :each do
25
+ allow(Lita.config.handlers.virus_total).to receive(:api_key).and_return 'api key'
26
+ end
27
+
28
+ it { is_expected.to route('vt asdf').to :virus_total }
29
+ it { is_expected.to route('virus total asdf').to :virus_total }
30
+
31
+ context '#virus_total' do
32
+ context 'responds with' do
33
+ it 'does not blow up if missing stuff' do
34
+ expect(Uirusu::VTUrl).to receive(:query_report).with('api key', 'asdf.com').and_return({})
35
+ send_message 'vt asdf.com'
36
+ message = <<MESSAGE
37
+ asdf.com had ?/? positive results on Date Unknown
38
+ Positive scans: [\"Unknown\"]
39
+ Full report: Link Unavailable
40
+ MESSAGE
41
+ expect(replies.last).to eq(message.strip)
42
+ end
43
+ it 'a formatted string for urls' do
44
+ expect(Uirusu::VTUrl).to receive(:query_report).with('api key', 'asdf.com').and_return(response)
45
+ send_message 'vt asdf.com'
46
+ message = <<MESSAGE
47
+ asdf.com had 1/3 positive results on today!
48
+ Positive scans: [\"awesome\"]
49
+ Full report: http://url.to.thing
50
+ MESSAGE
51
+ expect(replies.last).to eq(message.strip)
52
+ end
53
+
54
+ it 'a formatted string for urls with no positives' do
55
+ expect(Uirusu::VTUrl).to receive(:query_report).with('api key', 'asdf.com').and_return(clean_response)
56
+ send_message 'vt asdf.com'
57
+ message = <<MESSAGE
58
+ asdf.com had 0/3 positive results on today!
59
+ Full report: http://url.to.thing
60
+ MESSAGE
61
+ expect(replies.last).to eq(message.strip)
62
+ end
63
+
64
+ it 'prints a formatted string for files' do
65
+ expect(Uirusu::VTFile).to receive(:query_report).with('api key', 'asdf').and_return(response)
66
+ send_message 'vt asdf'
67
+ message = <<MESSAGE
68
+ asdf had 1/3 positive results on today!
69
+ Positive scans: [\"awesome\"]
70
+ Full report: http://url.to.thing
71
+ MESSAGE
72
+ expect(replies.last).to eq(message.strip)
73
+ end
74
+
75
+ it 'a formatted string for files with no positives' do
76
+ expect(Uirusu::VTFile).to receive(:query_report).with('api key', 'asdf').and_return(clean_response)
77
+ send_message 'vt asdf'
78
+ message = <<MESSAGE
79
+ asdf had 0/3 positive results on today!
80
+ Full report: http://url.to.thing
81
+ MESSAGE
82
+ expect(replies.last).to eq(message.strip)
83
+ end
84
+ end
85
+
86
+ it 'parses files' do
87
+ expect(Uirusu::VTFile).to receive(:query_report).with('api key', 'asdf').and_return(response)
88
+ send_message 'vt asdf'
89
+ end
90
+
91
+ it 'parses dns' do
92
+ expect(Uirusu::VTUrl).to receive(:query_report).with('api key', 'asdf.com').and_return(response)
93
+ send_message 'vt asdf.com'
94
+ end
95
+
96
+ it 'parses urls' do
97
+ expect(Uirusu::VTUrl).to receive(:query_report).with('api key', 'http://asdf.com').and_return(response)
98
+ send_message 'vt http://asdf.com'
99
+ end
100
+
101
+ it 'handles bad urls' do
102
+ expect(Uirusu::VTFile).to receive(:query_report).with('api key', 'http://asdf asdf').and_return(response)
103
+ send_message 'vt http://asdf asdf'
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,14 @@
1
+ require 'simplecov'
2
+ require 'coveralls'
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter,
5
+ Coveralls::SimpleCov::Formatter
6
+ ]
7
+ SimpleCov.start { add_filter '/spec/' } unless ENV['SKIP_COVERAGE']
8
+
9
+ require 'lita/virus_total'
10
+ require 'lita/rspec'
11
+
12
+ # A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
13
+ # was generated with Lita 4, the compatibility mode should be left disabled.
14
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-virus_total
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "'Joseph Henrich'"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: uirusu
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 3.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 3.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: mutant
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: mutant-rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Use the virus total api to check file hashes and urls
182
+ email:
183
+ - jhenrich@constantcontact.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rubocop.yml"
190
+ - ".ruby-gemset"
191
+ - ".ruby-version"
192
+ - ".travis.yml"
193
+ - Gemfile
194
+ - LICENSE
195
+ - README.md
196
+ - Rakefile
197
+ - lib/lita/handlers/virus_total.rb
198
+ - lib/lita/virus_total.rb
199
+ - lib/lita/virus_total/version.rb
200
+ - lita-virus_total.gemspec
201
+ - locales/en.yml
202
+ - spec/lita/handlers/virus_total_spec.rb
203
+ - spec/spec_helper.rb
204
+ - templates/.gitkeep
205
+ homepage: http://github.com/constantcontact/lita-virus_total
206
+ licenses:
207
+ - BSD
208
+ metadata:
209
+ lita_plugin_type: handler
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 2.4.5.1
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: Use the virus total api to check file hashes and urls
230
+ test_files:
231
+ - spec/lita/handlers/virus_total_spec.rb
232
+ - spec/spec_helper.rb