virustotal_api 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +42 -3
- data/CHANGELOG.md +4 -0
- data/README.md +6 -2
- data/lib/virustotal_api/base.rb +14 -4
- data/lib/virustotal_api/file.rb +20 -1
- data/lib/virustotal_api/version.rb +1 -1
- data/test/file_test.rb +10 -0
- data/test/fixtures/file_upload.yml +1 -1
- data/test/fixtures/large_file_upload.yml +99 -0
- metadata +7 -3
- 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: 4d61c90abdeb3a513e29da52a083c10044eace4aa1f51e6b758798abfee9137a
|
4
|
+
data.tar.gz: eae6f4130f49c3e5b6d17553aaf4c4e6725e7e74260ae2c0c250bc0130823c55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef0c2142c1e1ad07be96a88a035f7c906c22c67bb183e7c5906256a1ba83a03378eb985eb02fae68362bb9d9e1439fffef7c82eccfd9a3004144ac6640dd14f3
|
7
|
+
data.tar.gz: 2016ad82dadcc09fd03e3ca89cc324bcf7670a3a762a0ea1464569171e589e9d83052f7f95210406747f3d7b3b0ff93e8f67801a35c8d1d42bb482270b036717
|
@@ -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,56 @@ on:
|
|
7
7
|
branches: [ master ]
|
8
8
|
|
9
9
|
jobs:
|
10
|
-
Test:
|
10
|
+
Test-Ruby-2-5:
|
11
11
|
runs-on: ubuntu-latest
|
12
|
-
|
13
12
|
steps:
|
14
13
|
- uses: actions/checkout@v2
|
15
14
|
- name: Set up Ruby
|
16
15
|
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
17
16
|
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
18
|
-
uses: ruby/setup-ruby@v1
|
17
|
+
uses: ruby/setup-ruby@v1.70.1
|
19
18
|
with:
|
20
19
|
ruby-version: 2.5
|
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-2-7:
|
30
|
+
runs-on: ubuntu-latest
|
31
|
+
steps:
|
32
|
+
- uses: actions/checkout@v2
|
33
|
+
- name: Set up Ruby
|
34
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
35
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
36
|
+
uses: ruby/setup-ruby@v1.70.1
|
37
|
+
with:
|
38
|
+
ruby-version: 2.7
|
39
|
+
- name: Show Ruby Version
|
40
|
+
run: ruby --version
|
41
|
+
- name: Install dependencies
|
42
|
+
run: bundle install
|
43
|
+
- name: Lint
|
44
|
+
run: bundle exec rake rubocop
|
45
|
+
- name: Run tests
|
46
|
+
run: bundle exec rake
|
47
|
+
|
48
|
+
Test-Ruby-3-0:
|
49
|
+
runs-on: ubuntu-latest
|
50
|
+
steps:
|
51
|
+
- uses: actions/checkout@v2
|
52
|
+
- name: Set up Ruby
|
53
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
54
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
55
|
+
uses: ruby/setup-ruby@v1.70.1
|
56
|
+
with:
|
57
|
+
ruby-version: 3.0
|
58
|
+
- name: Show Ruby Version
|
59
|
+
run: ruby --version
|
21
60
|
- name: Install dependencies
|
22
61
|
run: bundle install
|
23
62
|
- name: Lint
|
data/CHANGELOG.md
CHANGED
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,10 +37,10 @@ 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
|
)
|
@@ -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
|
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/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,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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: virustotal_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pwelch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -183,7 +183,9 @@ extra_rdoc_files: []
|
|
183
183
|
files:
|
184
184
|
- ".github/CODE_OF_CONDUCT.md"
|
185
185
|
- ".github/CONTRIBUTING.md"
|
186
|
-
- ".github/ISSUE_TEMPLATE.md"
|
186
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
187
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
188
|
+
- ".github/pull_request_template.md"
|
187
189
|
- ".github/workflows/ruby.yml"
|
188
190
|
- ".gitignore"
|
189
191
|
- ".rubocop.yml"
|
@@ -220,6 +222,7 @@ files:
|
|
220
222
|
- test/fixtures/file_upload.yml
|
221
223
|
- test/fixtures/group_find.yml
|
222
224
|
- test/fixtures/ip.yml
|
225
|
+
- test/fixtures/large_file_upload.yml
|
223
226
|
- test/fixtures/null_file
|
224
227
|
- test/fixtures/unscanned_url_find.yml
|
225
228
|
- test/fixtures/url_analyse.yml
|
@@ -273,6 +276,7 @@ test_files:
|
|
273
276
|
- test/fixtures/file_upload.yml
|
274
277
|
- test/fixtures/group_find.yml
|
275
278
|
- test/fixtures/ip.yml
|
279
|
+
- test/fixtures/large_file_upload.yml
|
276
280
|
- test/fixtures/null_file
|
277
281
|
- test/fixtures/unscanned_url_find.yml
|
278
282
|
- test/fixtures/url_analyse.yml
|