file_sentry 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/file_sentry +10 -0
- data/bin/setup +7 -0
- data/config/.DS_Store +0 -0
- data/config/environment.rb +12 -0
- data/file_sentry.gemspec +42 -0
- data/lib/file_sentry/api_wrapper.rb +95 -0
- data/lib/file_sentry/command_line.rb +121 -0
- data/lib/file_sentry/configuration.rb +11 -0
- data/lib/file_sentry/file_hash.rb +34 -0
- data/lib/file_sentry/op_file.rb +28 -0
- data/lib/file_sentry/version.rb +3 -0
- data/lib/file_sentry.rb +19 -0
- metadata +185 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e7dc49f35192c46441476d1d74663e555a18e2bf6129107619dd1643d296e032
|
4
|
+
data.tar.gz: 13fb073cb45a5cd7a4d71a8e12579166c563f3d3ef179f39f39da635e8875b81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '09e4351dc05a8d471aa818ab4b3b2d93a0f0fc174159b67cd2804385bba9037ac00d45ccff3f62f745e630b83cb11c9abfb2005131bead945a4dc9e03a98e958'
|
7
|
+
data.tar.gz: a9fd362c67fe26c46bb3b4dcf3de7e6ddc27fa6cb394906afde9c3e4d0158b552c73b2014a9109446afd5979638b7dee8a76c57925130184e4139ec20efb53d7
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at <github email address>. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
file_sentry (0.2.0)
|
5
|
+
colorize
|
6
|
+
dotenv
|
7
|
+
httparty
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.5.2)
|
13
|
+
public_suffix (>= 2.0.2, < 4.0)
|
14
|
+
coderay (1.1.2)
|
15
|
+
colorize (0.8.1)
|
16
|
+
crack (0.4.3)
|
17
|
+
safe_yaml (~> 1.0.0)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
dotenv (2.2.2)
|
20
|
+
hashdiff (0.3.7)
|
21
|
+
httparty (0.16.2)
|
22
|
+
multi_xml (>= 0.5.2)
|
23
|
+
method_source (0.9.0)
|
24
|
+
multi_xml (0.6.0)
|
25
|
+
pry (0.11.3)
|
26
|
+
coderay (~> 1.1.0)
|
27
|
+
method_source (~> 0.9.0)
|
28
|
+
public_suffix (3.0.2)
|
29
|
+
rake (10.4.2)
|
30
|
+
rspec (3.7.0)
|
31
|
+
rspec-core (~> 3.7.0)
|
32
|
+
rspec-expectations (~> 3.7.0)
|
33
|
+
rspec-mocks (~> 3.7.0)
|
34
|
+
rspec-core (3.7.1)
|
35
|
+
rspec-support (~> 3.7.0)
|
36
|
+
rspec-expectations (3.7.0)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.7.0)
|
39
|
+
rspec-mocks (3.7.0)
|
40
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
+
rspec-support (~> 3.7.0)
|
42
|
+
rspec-support (3.7.1)
|
43
|
+
safe_yaml (1.0.4)
|
44
|
+
vcr (4.0.0)
|
45
|
+
webmock (3.3.0)
|
46
|
+
addressable (>= 2.3.6)
|
47
|
+
crack (>= 0.3.2)
|
48
|
+
hashdiff
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
bundler (~> 1.16)
|
55
|
+
file_sentry!
|
56
|
+
pry
|
57
|
+
rake (~> 10.0)
|
58
|
+
rspec (~> 3.0)
|
59
|
+
vcr
|
60
|
+
webmock
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# FileSentry
|
2
|
+
|
3
|
+
FileSentry is a gem that scans files for malware using a comprehensive suite of anti-malware engines.
|
4
|
+
It displays
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
First, make sure you have the latest version of Ruby installed. FileSentry was developed using Ruby 2.5.0, and might not work with older versions of Ruby.
|
9
|
+
|
10
|
+
If you do not have Ruby installed, follow the instructions on this blog post to install rbenv and Ruby 2.5.0:[Setup Ruby On Rails on Ubuntu 16.04 Xenial Xerus](https://gorails.com/setup/ubuntu/16.04).
|
11
|
+
|
12
|
+
Follow the instructions using rbenv, and only follow along on the 'Installing Ruby' section.
|
13
|
+
|
14
|
+
To install the gem, enter the following in your terminal of choice
|
15
|
+
|
16
|
+
$ gem install file_sentry
|
17
|
+
|
18
|
+
You can also clone this repo if you want to tweak FileSentry!
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Once FileSentry is installed, you can enter
|
23
|
+
|
24
|
+
$ file_sentry {}
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
After checking out the repo, run `bin/setup` to install development dependencies. Then, run `rspec` to run the tests.
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/<github username>/file_sentry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
37
|
+
|
38
|
+
## Code of Conduct
|
39
|
+
|
40
|
+
Everyone interacting in the FileSentry project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/<github username>/file_sentry/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "file_sentry"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/file_sentry
ADDED
data/bin/setup
ADDED
data/config/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# do not change this line. Config must be
|
2
|
+
# required before any other file
|
3
|
+
require_relative '../lib/file_sentry/configuration'
|
4
|
+
require_relative '../lib/file_sentry'
|
5
|
+
require_relative '../lib/file_sentry/api_wrapper'
|
6
|
+
require_relative '../lib/file_sentry/command_line'
|
7
|
+
require_relative '../lib/file_sentry/file_hash'
|
8
|
+
require_relative '../lib/file_sentry/op_file'
|
9
|
+
require 'digest'
|
10
|
+
require 'colorize'
|
11
|
+
require 'httparty'
|
12
|
+
require 'pry'
|
data/file_sentry.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "file_sentry/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "file_sentry"
|
8
|
+
spec.version = FileSentry::VERSION
|
9
|
+
spec.authors = ["Alexandra Wright"]
|
10
|
+
spec.email = ["superbiscuit@gmail.com"]
|
11
|
+
spec.summary = %q{A command line utility to scan files for malware risks. Uses the OPSWAT Defender Cloud API.}
|
12
|
+
spec.homepage = "https://github.com/f3mshep/file_sentry"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
21
|
+
"public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
# spec.bindir = "file_sentry"
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib", "config"]
|
30
|
+
|
31
|
+
|
32
|
+
spec.add_runtime_dependency "dotenv"
|
33
|
+
spec.add_runtime_dependency "httparty"
|
34
|
+
spec.add_runtime_dependency "colorize"
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
37
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
38
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
39
|
+
spec.add_development_dependency "pry"
|
40
|
+
spec.add_development_dependency "webmock"
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
class APIWrapper
|
2
|
+
|
3
|
+
BASE_URL = 'https://api.metadefender.com/v2'
|
4
|
+
|
5
|
+
attr_accessor :op_file
|
6
|
+
|
7
|
+
def initialize(attributes)
|
8
|
+
attributes.each {|attribute, value| self.send("#{attribute}=", value)}
|
9
|
+
end
|
10
|
+
|
11
|
+
def scan_file
|
12
|
+
hash_response = get_hash
|
13
|
+
if does_hash_exist?(hash_response, op_file.hash)
|
14
|
+
set_data_id(hash_response)
|
15
|
+
else
|
16
|
+
set_data_id(post_file)
|
17
|
+
end
|
18
|
+
monitor_scan
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def api_key
|
24
|
+
FileSentry.configuration.access_key
|
25
|
+
end
|
26
|
+
|
27
|
+
def monitor_scan
|
28
|
+
response = get_data_id
|
29
|
+
until is_scan_complete?(response)
|
30
|
+
sleep(0.1)
|
31
|
+
response = get_data_id
|
32
|
+
end
|
33
|
+
op_file.scan_results = response["scan_results"]
|
34
|
+
end
|
35
|
+
|
36
|
+
def post_file
|
37
|
+
response = HTTParty.post(
|
38
|
+
"#{BASE_URL}/file/",
|
39
|
+
headers: {"apikey"=> api_key},
|
40
|
+
body: {"filename" => File.open(op_file.filepath)}
|
41
|
+
)
|
42
|
+
error_check(response)
|
43
|
+
response
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_hash
|
47
|
+
raise "No hash set" if op_file.hash.nil?
|
48
|
+
response = HTTParty.get(
|
49
|
+
"#{BASE_URL}/hash/#{op_file.hash}",
|
50
|
+
headers: {"apikey"=> api_key}
|
51
|
+
)
|
52
|
+
error_check(response)
|
53
|
+
response
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_data_id
|
57
|
+
raise "No data_id set" if op_file.data_id.nil?
|
58
|
+
response = HTTParty.get(
|
59
|
+
"#{BASE_URL}/file/#{op_file.data_id}",
|
60
|
+
headers: {"apikey"=> api_key}
|
61
|
+
)
|
62
|
+
error_check(response)
|
63
|
+
response
|
64
|
+
end
|
65
|
+
|
66
|
+
def set_data_id(response)
|
67
|
+
op_file.data_id = response["data_id"]
|
68
|
+
end
|
69
|
+
|
70
|
+
def does_hash_exist?(response, hash)
|
71
|
+
if response[hash]
|
72
|
+
false
|
73
|
+
else
|
74
|
+
true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def error_check(response)
|
79
|
+
raise "Error: #{response.message}" if response.message != "OK"
|
80
|
+
end
|
81
|
+
|
82
|
+
def is_scan_complete?(response)
|
83
|
+
find_progress(response) == 100
|
84
|
+
end
|
85
|
+
|
86
|
+
def find_progress(response)
|
87
|
+
begin
|
88
|
+
progress = response["process_info"]["progress_percentage"]
|
89
|
+
rescue
|
90
|
+
progress = response["scan_results"]["scan_details"]["progress_percentage"]
|
91
|
+
end
|
92
|
+
progress ||= 0
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
class CommandLine
|
2
|
+
attr_accessor :filepath, :encryption, :op_file
|
3
|
+
|
4
|
+
def initialize(attributes)
|
5
|
+
attributes.each {|attribute, value| self.send("#{attribute}=", value) }
|
6
|
+
self.op_file = OPFile.new({filepath: filepath})
|
7
|
+
end
|
8
|
+
|
9
|
+
def start_utility
|
10
|
+
key = load_api_key
|
11
|
+
config_app(key)
|
12
|
+
op_file.filepath = filepath
|
13
|
+
if filepath
|
14
|
+
analyze_file
|
15
|
+
else
|
16
|
+
show_usage
|
17
|
+
show_config
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def print_result
|
25
|
+
raise "Scan not completed" if op_file.scan_results.nil?
|
26
|
+
status = op_file.scan_results["scan_all_result_a"]
|
27
|
+
status == "No threat detected" ? status = status.colorize(:green) : status = status.colorize(:red)
|
28
|
+
puts "\n" * 10
|
29
|
+
puts "Filename: #{File.basename(op_file.filepath)}"
|
30
|
+
puts "Overall Status: " + status
|
31
|
+
puts "\n"
|
32
|
+
op_file.scan_results["scan_details"].each do |engine_arr|
|
33
|
+
engine = engine_arr[1]
|
34
|
+
threats_found = engine["threat_found"].colorize(:red)
|
35
|
+
puts "Engine: #{engine_arr[0]}"
|
36
|
+
puts "Threats Found: #{threats_found.empty? ? "Clean".colorize(:green) : threats_found}"
|
37
|
+
puts "Scan Result: #{engine["scan_result_i"]}"
|
38
|
+
puts "Time: #{engine["def_time"]}"
|
39
|
+
puts "\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def analyze_file
|
44
|
+
encrypt = encryption || "md5"
|
45
|
+
print "Analyzing File... "
|
46
|
+
show_wait_spinner { op_file.process_file(encrypt) }
|
47
|
+
print_result
|
48
|
+
end
|
49
|
+
|
50
|
+
def show_config
|
51
|
+
puts "press 'y' to change API Key, or any other key to exit"
|
52
|
+
input = STDIN.gets.chomp
|
53
|
+
get_key_from_user if input.downcase == 'y'
|
54
|
+
end
|
55
|
+
|
56
|
+
def show_usage
|
57
|
+
puts "Usage: file_sentry filepath encryption"
|
58
|
+
puts "encryption is an optional argument"
|
59
|
+
puts "\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
def config_app(key)
|
63
|
+
FileSentry.configure do |config|
|
64
|
+
config.access_key = key
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def load_api_key
|
69
|
+
key = FileSentry.configuration.access_key
|
70
|
+
if key.nil?
|
71
|
+
begin
|
72
|
+
key = File.read("#{Dir.home}/.file_sentry")
|
73
|
+
rescue
|
74
|
+
key = get_key_from_user
|
75
|
+
end
|
76
|
+
end
|
77
|
+
key
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_key_from_user
|
81
|
+
puts "Please enter OPSWAT MetaDefender API Key: "
|
82
|
+
key = STDIN.gets.chomp
|
83
|
+
save_key(key)
|
84
|
+
key
|
85
|
+
end
|
86
|
+
|
87
|
+
def save_key(key)
|
88
|
+
begin
|
89
|
+
file = File.open("#{Dir.home}/.file_sentry", 'w')
|
90
|
+
file.write(key)
|
91
|
+
puts "API Key saved"
|
92
|
+
rescue
|
93
|
+
warn("Could not save API configuration file".colorize(:yellow))
|
94
|
+
ensure
|
95
|
+
file.close unless file.nil?
|
96
|
+
end
|
97
|
+
key
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def show_wait_spinner(fps=10)
|
102
|
+
# courtesy of Phrogz
|
103
|
+
# https://stackoverflow.com/questions/10262235/printing-an-ascii-spinning-cursor-in-the-console
|
104
|
+
|
105
|
+
chars = %w[⣾ ⣷ ⣯ ⣟ ⡿ ⢿ ⣻ ⣽].map {|symbol|symbol.colorize(:light_blue)}
|
106
|
+
delay = 1.0/fps
|
107
|
+
iter = 0
|
108
|
+
spinner = Thread.new do
|
109
|
+
while iter do # Keep spinning until told otherwise
|
110
|
+
print chars[(iter+=1) % chars.length]
|
111
|
+
sleep delay
|
112
|
+
print "\b"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
yield.tap{ # After yielding to the block, save the return value
|
116
|
+
iter = false # Tell the thread to exit, cleaning up after itself…
|
117
|
+
spinner.join # …and wait for it to do so.
|
118
|
+
} # Use the block's return value as the method's
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class FileHash
|
2
|
+
|
3
|
+
attr_accessor :op_file
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
attributes.each {|attribute, value| self.send("#{attribute}=", value)}
|
7
|
+
end
|
8
|
+
|
9
|
+
def hash_file(encryption)
|
10
|
+
begin
|
11
|
+
self.send("digest_#{encryption.downcase}")
|
12
|
+
rescue
|
13
|
+
raise "No encryption found for: #{encryption}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def digest_md5
|
20
|
+
digest = Digest::MD5.file op_file.filepath
|
21
|
+
op_file.hash = digest.hexdigest.upcase
|
22
|
+
end
|
23
|
+
|
24
|
+
def digest_sha1
|
25
|
+
digest = Digest::SHA1.file op_file.filepath
|
26
|
+
op_file.hash = digest.hexdigest.upcase
|
27
|
+
end
|
28
|
+
|
29
|
+
def digest_sha256
|
30
|
+
digest = Digest::SHA256.file op_file.filepath
|
31
|
+
op_file.hash = digest.hexdigest.upcase
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class OPFile
|
2
|
+
|
3
|
+
attr_accessor :filepath, :hash, :data_id, :scan_results, :file_hash, :api_wrapper
|
4
|
+
|
5
|
+
def initialize(attributes)
|
6
|
+
attributes.each {|attribute, value| self.send("#{attribute}=", value)}
|
7
|
+
self.file_hash ||= FileHash.new({op_file: self})
|
8
|
+
self.api_wrapper ||= APIWrapper.new({op_file: self})
|
9
|
+
end
|
10
|
+
|
11
|
+
def process_file(encrypt)
|
12
|
+
check_file
|
13
|
+
file_hash.hash_file(encrypt)
|
14
|
+
api_wrapper.scan_file
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def check_file
|
20
|
+
raise "Invalid file" if !File.file?(filepath)
|
21
|
+
raise "File size too large" if get_file_size > 140
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_file_size
|
25
|
+
('%.2f' % (File.size(filepath).to_f / 2**20)).to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/file_sentry.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module FileSentry
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_accessor :configuration
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.configuration
|
8
|
+
@configuration ||= Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.reset
|
12
|
+
@configuration = Configuration.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.configure
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: file_sentry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexandra Wright
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dotenv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httparty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: webmock
|
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
|
+
description:
|
126
|
+
email:
|
127
|
+
- superbiscuit@gmail.com
|
128
|
+
executables:
|
129
|
+
- console
|
130
|
+
- file_sentry
|
131
|
+
- setup
|
132
|
+
extensions: []
|
133
|
+
extra_rdoc_files: []
|
134
|
+
files:
|
135
|
+
- ".DS_Store"
|
136
|
+
- ".gitignore"
|
137
|
+
- ".rspec"
|
138
|
+
- ".travis.yml"
|
139
|
+
- CODE_OF_CONDUCT.md
|
140
|
+
- Gemfile
|
141
|
+
- Gemfile.lock
|
142
|
+
- LICENSE.txt
|
143
|
+
- README.md
|
144
|
+
- Rakefile
|
145
|
+
- bin/console
|
146
|
+
- bin/file_sentry
|
147
|
+
- bin/setup
|
148
|
+
- config/.DS_Store
|
149
|
+
- config/environment.rb
|
150
|
+
- file_sentry.gemspec
|
151
|
+
- lib/file_sentry.rb
|
152
|
+
- lib/file_sentry/api_wrapper.rb
|
153
|
+
- lib/file_sentry/command_line.rb
|
154
|
+
- lib/file_sentry/configuration.rb
|
155
|
+
- lib/file_sentry/file_hash.rb
|
156
|
+
- lib/file_sentry/op_file.rb
|
157
|
+
- lib/file_sentry/version.rb
|
158
|
+
homepage: https://github.com/f3mshep/file_sentry
|
159
|
+
licenses:
|
160
|
+
- MIT
|
161
|
+
metadata:
|
162
|
+
allowed_push_host: https://rubygems.org
|
163
|
+
post_install_message:
|
164
|
+
rdoc_options: []
|
165
|
+
require_paths:
|
166
|
+
- lib
|
167
|
+
- config
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 2.7.3
|
181
|
+
signing_key:
|
182
|
+
specification_version: 4
|
183
|
+
summary: A command line utility to scan files for malware risks. Uses the OPSWAT Defender
|
184
|
+
Cloud API.
|
185
|
+
test_files: []
|