virustotal_api 0.5.3 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/pull_request_template.md +11 -0
- data/.github/workflows/ruby.yml +24 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +23 -0
- data/README.md +6 -2
- data/lib/virustotal_api/base.rb +16 -6
- data/lib/virustotal_api/file.rb +20 -1
- data/lib/virustotal_api/version.rb +1 -1
- data/test/base_test.rb +16 -0
- data/test/file_test.rb +10 -0
- data/test/fixtures/domain_bad_request.yml +52 -0
- data/test/fixtures/file_upload.yml +1 -1
- data/test/fixtures/large_file_upload.yml +99 -0
- data/test/fixtures/url_encoding_find.yml +651 -0
- data/virustotal_api.gemspec +4 -4
- metadata +31 -23
- data/.github/ISSUE_TEMPLATE.md +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cc7f702a37c929aa442614681a5b34d12d11d5f1e1e04c8190c89184edb588f
|
4
|
+
data.tar.gz: 98e21db2c21a632610e0d9961ff7884bbae0df2072e9647d17c608c06881b0c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 278d6a9c1ff7aa68b05f131afcca21935720fc7c5db760a09f6db6d6cd693e7fa48ad2e5397b953ebb24da00d25cebf105ba52575c9e96ea79e2b20a3c21eda0
|
7
|
+
data.tar.gz: 965e4304dfa6e52287d05c3ebba817fbb0e3801f7fb353f8253fea98d7a1b118a2f0d14486883b94f2ce465cf807b151a9b69e5da75c18d9f4f075d066748af8
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
Steps to reproduce the behavior:
|
15
|
+
1. Go to '...'
|
16
|
+
2. Click on '....'
|
17
|
+
3. Scroll down to '....'
|
18
|
+
4. See error
|
19
|
+
|
20
|
+
**Expected behavior**
|
21
|
+
A clear and concise description of what you expected to happen.
|
22
|
+
|
23
|
+
**Screenshots**
|
24
|
+
If applicable, add screenshots to help explain your problem.
|
25
|
+
|
26
|
+
**Desktop (please complete the following information):**
|
27
|
+
- OS: [e.g. iOS]
|
28
|
+
- Browser [e.g. chrome, safari]
|
29
|
+
- Version [e.g. 22]
|
30
|
+
|
31
|
+
**Smartphone (please complete the following information):**
|
32
|
+
- Device: [e.g. iPhone6]
|
33
|
+
- OS: [e.g. iOS8.1]
|
34
|
+
- Browser [e.g. stock browser, safari]
|
35
|
+
- Version [e.g. 22]
|
36
|
+
|
37
|
+
**Additional context**
|
38
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
A clear and concise description of what you want to happen.
|
15
|
+
|
16
|
+
**Describe alternatives you've considered**
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
18
|
+
|
19
|
+
**Additional context**
|
20
|
+
Add any other context or screenshots about the feature request here.
|
data/.github/workflows/ruby.yml
CHANGED
@@ -7,17 +7,37 @@ on:
|
|
7
7
|
branches: [ master ]
|
8
8
|
|
9
9
|
jobs:
|
10
|
-
Test:
|
10
|
+
Test-Ruby-2-7:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby
|
15
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
16
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
17
|
+
uses: ruby/setup-ruby@v1.70.1
|
18
|
+
with:
|
19
|
+
ruby-version: 2.7
|
20
|
+
- name: Show Ruby Version
|
21
|
+
run: ruby --version
|
22
|
+
- name: Install dependencies
|
23
|
+
run: bundle install
|
24
|
+
- name: Lint
|
25
|
+
run: bundle exec rake rubocop
|
26
|
+
- name: Run tests
|
27
|
+
run: bundle exec rake
|
28
|
+
|
29
|
+
Test-Ruby-3-0:
|
11
30
|
runs-on: ubuntu-latest
|
12
|
-
|
13
31
|
steps:
|
14
32
|
- uses: actions/checkout@v2
|
15
33
|
- name: Set up Ruby
|
16
34
|
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
17
35
|
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
18
|
-
uses: ruby/setup-ruby@v1.
|
36
|
+
uses: ruby/setup-ruby@v1.70.1
|
19
37
|
with:
|
20
|
-
ruby-version:
|
38
|
+
ruby-version: 3.0
|
39
|
+
- name: Show Ruby Version
|
40
|
+
run: ruby --version
|
21
41
|
- name: Install dependencies
|
22
42
|
run: bundle install
|
23
43
|
- name: Lint
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,28 @@
|
|
1
1
|
# VirusTotal API Changelog
|
2
2
|
|
3
|
+
## [0.5.7] - 2021-09-20
|
4
|
+
|
5
|
+
* Remove EOL Ruby 2.5
|
6
|
+
|
7
|
+
## [0.5.6] - 2021-09-20
|
8
|
+
|
9
|
+
* Use urlsafe base64 encoding
|
10
|
+
* Fix changelog
|
11
|
+
* [@jonnynux](https://github.com/jonnynux)
|
12
|
+
|
13
|
+
## [0.5.5] - 2021-05-10
|
14
|
+
|
15
|
+
* Add support for larger files
|
16
|
+
* [@Grandman](https://github.com/Grandman)
|
17
|
+
|
18
|
+
## [0.5.4] - 2020-12-10
|
19
|
+
|
20
|
+
* Manage bad requests like not found
|
21
|
+
* Use strict base64 encoding
|
22
|
+
* [@crondaemon](https://github.com/crondaemon)
|
23
|
+
|
24
|
+
## [0.5.3] = 2020-10-12
|
25
|
+
|
3
26
|
## [0.5.2] - 2020-10-06
|
4
27
|
|
5
28
|
* Fix Fix exists? check
|
data/README.md
CHANGED
@@ -65,7 +65,10 @@ require 'virustotal_api'
|
|
65
65
|
file = '/path/to/file'
|
66
66
|
api_key = 'MY_API_KEY'
|
67
67
|
|
68
|
+
# for upload file
|
68
69
|
vtscan = VirustotalAPI::File.upload(file, api_key)
|
70
|
+
# or large file (more than 32MB)
|
71
|
+
vtscan = VirustotalAPI::File.upload_large(file, api_key)
|
69
72
|
|
70
73
|
# Virustotal ID of file
|
71
74
|
vtscan.id
|
@@ -233,10 +236,11 @@ vtgroup_report.report
|
|
233
236
|
|
234
237
|
## Contributors
|
235
238
|
|
236
|
-
- [@postmodern](https://github.com/postmodern)
|
237
|
-
- [@mkunkel](https://github.com/mkunkel)
|
238
239
|
- [@jonnynux](https://github.com/jonnynux)
|
239
240
|
- [@crondaemon](https://github.com/crondaemon/)
|
241
|
+
- [@postmodern](https://github.com/postmodern)
|
242
|
+
- [@mkunkel](https://github.com/mkunkel)
|
243
|
+
- [@Grandman](https://github.com/Grandman)
|
240
244
|
|
241
245
|
## Contributing
|
242
246
|
|
data/lib/virustotal_api/base.rb
CHANGED
@@ -12,9 +12,9 @@ module VirustotalAPI
|
|
12
12
|
attr_reader :report, :report_url, :id
|
13
13
|
|
14
14
|
def initialize(report)
|
15
|
-
@report
|
15
|
+
@report = report
|
16
16
|
@report_url = report&.dig('data', 'links', 'self')
|
17
|
-
@id
|
17
|
+
@id = report&.dig('data', 'id')
|
18
18
|
end
|
19
19
|
|
20
20
|
# @return [String] string of API URI class method
|
@@ -22,6 +22,14 @@ module VirustotalAPI
|
|
22
22
|
VirustotalAPI::URI
|
23
23
|
end
|
24
24
|
|
25
|
+
def self.perform(path, api_key, method = :get, options = {})
|
26
|
+
base_perform(api_uri + path, api_key, method, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.perform_absolute(url, api_key, method = :get, options = {})
|
30
|
+
base_perform(url, api_key, method, options)
|
31
|
+
end
|
32
|
+
|
25
33
|
# The actual method performing a call to Virustotal
|
26
34
|
#
|
27
35
|
# @param [String] url The url of the API
|
@@ -29,15 +37,15 @@ module VirustotalAPI
|
|
29
37
|
# @param [String] method The HTTP method to use
|
30
38
|
# @param [Hash] options Options to pass as payload
|
31
39
|
# @return [VirustotalAPI::Domain] Report Search Result
|
32
|
-
def self.
|
40
|
+
def self.base_perform(url, api_key, method = :get, options = {})
|
33
41
|
response = RestClient::Request.execute(
|
34
42
|
method: method,
|
35
|
-
url:
|
43
|
+
url: url,
|
36
44
|
headers: { 'x-apikey': api_key },
|
37
45
|
payload: options
|
38
46
|
)
|
39
47
|
JSON.parse(response.body)
|
40
|
-
rescue RestClient::NotFound
|
48
|
+
rescue RestClient::NotFound, RestClient::BadRequest
|
41
49
|
{}
|
42
50
|
rescue RestClient::Unauthorized
|
43
51
|
# Raise a custom exception not to expose the underlying
|
@@ -49,6 +57,8 @@ module VirustotalAPI
|
|
49
57
|
raise VirustotalAPI::RateLimitError
|
50
58
|
end
|
51
59
|
|
60
|
+
private_class_method :base_perform
|
61
|
+
|
52
62
|
# @return [String] string of API URI instance method
|
53
63
|
def api_uri
|
54
64
|
self.class.api_uri
|
@@ -62,7 +72,7 @@ module VirustotalAPI
|
|
62
72
|
# Generate a URL identifier.
|
63
73
|
# @see https://developers.virustotal.com/v3.0/reference#url
|
64
74
|
def self.url_identifier(url)
|
65
|
-
Base64.
|
75
|
+
Base64.urlsafe_encode64(url).strip.gsub('=', '')
|
66
76
|
end
|
67
77
|
end
|
68
78
|
end
|
data/lib/virustotal_api/file.rb
CHANGED
@@ -23,7 +23,20 @@ module VirustotalAPI
|
|
23
23
|
# @return [VirusotalAPI::File] Report
|
24
24
|
def self.upload(file_path, api_key, opts = {})
|
25
25
|
filename = opts.fetch('filename') { ::File.basename(file_path) }
|
26
|
-
report
|
26
|
+
report = perform('/files', api_key, :post, filename: filename, file: ::File.open(file_path, 'r'))
|
27
|
+
new(report)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Upload a new file with size more than 32MB.
|
31
|
+
#
|
32
|
+
# @param [String] file_path for file to be sent for scan
|
33
|
+
# @param [String] api_key The key for virustotal
|
34
|
+
# @param [Hash] opts hash for additional options
|
35
|
+
# @return [VirusotalAPI::File] Report
|
36
|
+
def self.upload_large(file_path, api_key, opts = {})
|
37
|
+
filename = opts.fetch('filename') { ::File.basename(file_path) }
|
38
|
+
url = upload_url(api_key)
|
39
|
+
report = perform_absolute(url, api_key, :post, filename: filename, file: ::File.open(file_path, 'r'))
|
27
40
|
new(report)
|
28
41
|
end
|
29
42
|
|
@@ -37,6 +50,12 @@ module VirustotalAPI
|
|
37
50
|
new(report)
|
38
51
|
end
|
39
52
|
|
53
|
+
# @return [String] url for upload file
|
54
|
+
def self.upload_url(api_key)
|
55
|
+
data = perform('/files/upload_url', api_key)
|
56
|
+
data&.dig('data')
|
57
|
+
end
|
58
|
+
|
40
59
|
# Check if the submitted hash is detected by an AV engine.
|
41
60
|
#
|
42
61
|
# @param [String] engine The engine to check.
|
data/test/base_test.rb
CHANGED
@@ -4,7 +4,9 @@ require './test/test_helper'
|
|
4
4
|
|
5
5
|
class VirustotalAPIBaseTest < Minitest::Test
|
6
6
|
def setup
|
7
|
+
@domain = 'xpressco.za'
|
7
8
|
@sha256 = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
|
9
|
+
@url = 'https://www.dropbox.com/s/qmi112rc4ns75eb/Confidential_123.xls?dl=1'
|
8
10
|
@api_key = 'testapikey'
|
9
11
|
end
|
10
12
|
|
@@ -43,5 +45,19 @@ class VirustotalAPIBaseTest < Minitest::Test
|
|
43
45
|
|
44
46
|
assert !virustotal_report.exists?
|
45
47
|
end
|
48
|
+
|
49
|
+
VCR.use_cassette('domain_bad_request') do
|
50
|
+
virustotal_report = VirustotalAPI::Domain.find(@domain, @api_key)
|
51
|
+
|
52
|
+
assert !virustotal_report.exists?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_url_encoding
|
57
|
+
VCR.use_cassette('url_encoding_find') do
|
58
|
+
virustotal_report = VirustotalAPI::URL.find(@url, @api_key)
|
59
|
+
|
60
|
+
assert virustotal_report.exists?
|
61
|
+
end
|
46
62
|
end
|
47
63
|
end
|
data/test/file_test.rb
CHANGED
@@ -51,6 +51,16 @@ class VirustotalAPIFileTest < Minitest::Test
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
def test_upload_large
|
55
|
+
VCR.use_cassette('large_file_upload') do
|
56
|
+
vt_file_upload = VirustotalAPI::File.upload_large(@file_path, @api_key)
|
57
|
+
|
58
|
+
assert vt_file_upload.exists?
|
59
|
+
assert vt_file_upload.report.is_a?(Hash)
|
60
|
+
assert vt_file_upload.id.is_a?(String)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
54
64
|
def test_analyse
|
55
65
|
VCR.use_cassette('file_analyse') do
|
56
66
|
vt_file_analyse = VirustotalAPI::File.analyse(@sha256, @api_key)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://www.virustotal.com/api/v3/domains/xpressco.za
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- "*/*"
|
12
|
+
User-Agent:
|
13
|
+
- rest-client/2.1.0 (linux-gnu x86_64) ruby/2.5.1p57
|
14
|
+
X-Apikey:
|
15
|
+
- testapikey
|
16
|
+
Content-Length:
|
17
|
+
- '0'
|
18
|
+
Content-Type:
|
19
|
+
- application/x-www-form-urlencoded
|
20
|
+
Accept-Encoding:
|
21
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
22
|
+
Host:
|
23
|
+
- www.virustotal.com
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 400
|
27
|
+
message: Bad Request
|
28
|
+
headers:
|
29
|
+
Cache-Control:
|
30
|
+
- no-cache
|
31
|
+
Content-Type:
|
32
|
+
- application/json; charset=utf-8
|
33
|
+
X-Cloud-Trace-Context:
|
34
|
+
- f9f5f005efc95b0390a91fb6306201d6
|
35
|
+
Date:
|
36
|
+
- Mon, 28 Dec 2020 13:56:50 GMT
|
37
|
+
Server:
|
38
|
+
- Google Frontend
|
39
|
+
Content-Length:
|
40
|
+
- '138'
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: |-
|
44
|
+
{
|
45
|
+
"error": {
|
46
|
+
"code": "InvalidArgumentError",
|
47
|
+
"message": "Domain \"xpressco.za\" is not a valid domain pattern"
|
48
|
+
}
|
49
|
+
}
|
50
|
+
http_version:
|
51
|
+
recorded_at: Mon, 28 Dec 2020 13:56:50 GMT
|
52
|
+
recorded_with: VCR 5.0.0
|
@@ -0,0 +1,99 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://www.virustotal.com/api/v3/files/upload_url
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
Accept:
|
9
|
+
- "*/*"
|
10
|
+
User-Agent:
|
11
|
+
- rest-client/2.1.0 (linux-gnu x86_64) ruby/2.5.1p57
|
12
|
+
X-Apikey:
|
13
|
+
- testapikey
|
14
|
+
Content-Length:
|
15
|
+
- '282'
|
16
|
+
Content-Type:
|
17
|
+
- multipart/form-data; boundary=----RubyFormBoundaryjv5FxFNLpwqDoUQA
|
18
|
+
Accept-Encoding:
|
19
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
20
|
+
Host:
|
21
|
+
- www.virustotal.com
|
22
|
+
response:
|
23
|
+
status:
|
24
|
+
code: 200
|
25
|
+
message: OK
|
26
|
+
headers:
|
27
|
+
Cache-Control:
|
28
|
+
- no-cache
|
29
|
+
Content-Type:
|
30
|
+
- application/json; charset=utf-8
|
31
|
+
X-Cloud-Trace-Context:
|
32
|
+
- 9c3d1ae8f345c5ca8060a4b793174891
|
33
|
+
Date:
|
34
|
+
- Wed, 02 Sep 2020 14:02:36 GMT
|
35
|
+
Server:
|
36
|
+
- Google Frontend
|
37
|
+
Content-Length:
|
38
|
+
- '128'
|
39
|
+
body:
|
40
|
+
encoding: UTF-8
|
41
|
+
string: |-
|
42
|
+
{
|
43
|
+
"data": "https://www.virustotal.com/_ah/upload/AMmfu6b-_DXUeFe36Sb3b0F4B8mH9Nb-CHbRoUNVOPwG/"
|
44
|
+
}
|
45
|
+
http_version:
|
46
|
+
recorded_at: Wed, 02 Sep 2020 14:02:37 GMT
|
47
|
+
|
48
|
+
- request:
|
49
|
+
method: post
|
50
|
+
uri: https://www.virustotal.com/_ah/upload/AMmfu6b-_DXUeFe36Sb3b0F4B8mH9Nb-CHbRoUNVOPwG/
|
51
|
+
body:
|
52
|
+
encoding: ASCII-8BIT
|
53
|
+
string: "------RubyFormBoundaryjv5FxFNLpwqDoUQA\r\nContent-Disposition: form-data;
|
54
|
+
name=\"filename\"\r\n\r\nnull_file\r\n------RubyFormBoundaryjv5FxFNLpwqDoUQA\r\nContent-Disposition:
|
55
|
+
form-data; name=\"file\"; filename=\"null_file\"\r\nContent-Type: text/plain\r\n\r\n\n\r\n------RubyFormBoundaryjv5FxFNLpwqDoUQA--\r\n"
|
56
|
+
headers:
|
57
|
+
Accept:
|
58
|
+
- "*/*"
|
59
|
+
User-Agent:
|
60
|
+
- rest-client/2.1.0 (linux-gnu x86_64) ruby/2.5.1p57
|
61
|
+
X-Apikey:
|
62
|
+
- testapikey
|
63
|
+
Content-Length:
|
64
|
+
- '282'
|
65
|
+
Content-Type:
|
66
|
+
- multipart/form-data; boundary=----RubyFormBoundaryjv5FxFNLpwqDoUQA
|
67
|
+
Accept-Encoding:
|
68
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
69
|
+
Host:
|
70
|
+
- www.virustotal.com
|
71
|
+
response:
|
72
|
+
status:
|
73
|
+
code: 200
|
74
|
+
message: OK
|
75
|
+
headers:
|
76
|
+
Cache-Control:
|
77
|
+
- no-cache
|
78
|
+
Content-Type:
|
79
|
+
- application/json; charset=utf-8
|
80
|
+
X-Cloud-Trace-Context:
|
81
|
+
- 9c3d1ae8f345c5ca8060a4b793174891
|
82
|
+
Date:
|
83
|
+
- Wed, 02 Sep 2020 14:02:36 GMT
|
84
|
+
Server:
|
85
|
+
- Google Frontend
|
86
|
+
Content-Length:
|
87
|
+
- '128'
|
88
|
+
body:
|
89
|
+
encoding: UTF-8
|
90
|
+
string: |-
|
91
|
+
{
|
92
|
+
"data": {
|
93
|
+
"id": "NjhiMzI5ZGE5ODkzZTM0MDk5YzdkOGFkNWNiOWM5NDA6MTU5OTA1NTM1Ng==",
|
94
|
+
"type": "analysis"
|
95
|
+
}
|
96
|
+
}
|
97
|
+
http_version:
|
98
|
+
recorded_at: Wed, 02 Sep 2020 14:02:37 GMT
|
99
|
+
recorded_with: VCR 5.0.0
|