virustotal_api 0.1.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +23 -0
  3. data/.github/CODE_OF_CONDUCT.md +46 -0
  4. data/.github/CONTRIBUTING.md +7 -0
  5. data/.github/ISSUE_TEMPLATE.md +15 -0
  6. data/.github/workflows/ruby.yml +26 -0
  7. data/.gitignore +1 -0
  8. data/.rubocop.yml +17 -5
  9. data/CHANGELOG.md +34 -0
  10. data/Gemfile +1 -1
  11. data/README.md +88 -31
  12. data/Rakefile +3 -2
  13. data/lib/virustotal_api.rb +7 -6
  14. data/lib/virustotal_api/analysis.rb +24 -0
  15. data/lib/virustotal_api/base.rb +41 -3
  16. data/lib/virustotal_api/domain.rb +24 -0
  17. data/lib/virustotal_api/exceptions.rb +9 -0
  18. data/lib/virustotal_api/file.rb +56 -0
  19. data/lib/virustotal_api/ip.rb +24 -0
  20. data/lib/virustotal_api/uri.rb +4 -2
  21. data/lib/virustotal_api/url.rb +46 -0
  22. data/lib/virustotal_api/version.rb +4 -2
  23. data/test/analysis_test.rb +23 -0
  24. data/test/base_test.rb +12 -13
  25. data/test/domain_test.rb +32 -0
  26. data/test/exceptions_test.rb +23 -0
  27. data/test/file_test.rb +68 -0
  28. data/test/fixtures/analysis.yml +544 -0
  29. data/test/fixtures/domain.yml +830 -0
  30. data/test/fixtures/file_analyse.yml +52 -0
  31. data/test/fixtures/file_find.yml +1236 -0
  32. data/test/fixtures/file_unauthorized.yml +51 -0
  33. data/test/fixtures/file_upload.yml +54 -0
  34. data/test/fixtures/ip.yml +716 -0
  35. data/test/fixtures/unscanned_url_find.yml +44 -0
  36. data/test/fixtures/url_analyse.yml +52 -0
  37. data/test/fixtures/url_find.yml +599 -0
  38. data/test/{ip_report_test.rb → ip_test.rb} +6 -5
  39. data/test/test_helper.rb +2 -1
  40. data/test/uri_test.rb +3 -2
  41. data/test/url_test.rb +65 -0
  42. data/test/version_test.rb +3 -3
  43. data/virustotal_api.gemspec +16 -13
  44. metadata +113 -77
  45. data/.travis.yml +0 -11
  46. data/lib/virustotal_api/domain_report.rb +0 -35
  47. data/lib/virustotal_api/file_report.rb +0 -36
  48. data/lib/virustotal_api/file_scan.rb +0 -36
  49. data/lib/virustotal_api/ip_report.rb +0 -35
  50. data/lib/virustotal_api/url_report.rb +0 -37
  51. data/test/domain_report_test.rb +0 -31
  52. data/test/file_report_test.rb +0 -34
  53. data/test/file_scan_test.rb +0 -29
  54. data/test/fixtures/domain_report.yml +0 -311
  55. data/test/fixtures/ip_report.yml +0 -1323
  56. data/test/fixtures/report.yml +0 -110
  57. data/test/fixtures/report_not_found.yml +0 -42
  58. data/test/fixtures/request_forbidden.yml +0 -38
  59. data/test/fixtures/scan.yml +0 -49
  60. data/test/fixtures/url_report.yml +0 -95
  61. data/test/url_report_test.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ef4844e6f5a7e7be0cf7ed1aa7c7f25027bc5522
4
- data.tar.gz: 34c4dcb450256151376eb1486ca2b9fed3a9a3be
2
+ SHA256:
3
+ metadata.gz: 68e1f3494830e62ef04f24a74431a540d3dd6943ee329b772b8a3629798f0856
4
+ data.tar.gz: 58e0b36a8a6745b2db5957ab4b48da429f9ec154b1116d0110933cbc54d9f456
5
5
  SHA512:
6
- metadata.gz: 2bb1845d91af6c8ed7fef6055ec3514aa86427d6e751877b5c3ac4630430b17beb1dc9138c8a5d3d71c33ef503a0da056f558fbe97605f0fd621cb09d585ab0d
7
- data.tar.gz: 2b73096b9aefc1aee739fb1bfb243f508a9e5b79118352dc34800c959ce1bb4ada3db7cfa2a8adccc834f65676c042ea4dfb1e5245adf480016d7212819e935c
6
+ metadata.gz: 03cf94231610ed5e8002c60dde3cc6d3b3d4ab52682be470023911559c0df6f2cf9230532fe3f002bd2587268405b086742e73a9edba86a4de49eaca37ab1b6b
7
+ data.tar.gz: a831140e24d0302e971a33f3b44d7c9760aa271b27d4036bf310ada72f09aa9cd11d1c685793d2a78a0ac6814725de873f8ea6419e92461febef84bb909f2065
@@ -0,0 +1,23 @@
1
+ version: 2
2
+ jobs:
3
+ test:
4
+ docker:
5
+ - image: circleci/ruby:2.5.3-stretch
6
+ steps:
7
+ - checkout
8
+ - run:
9
+ name: Setup
10
+ command: |
11
+ gem update bundler
12
+ bundle install
13
+ - run:
14
+ name: Rubocop
15
+ command: bundle exec rake rubocop
16
+ - run:
17
+ name: Run Tests
18
+ command: bundle exec rake test
19
+ workflows:
20
+ version: 2
21
+ test:
22
+ jobs:
23
+ - test
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at git@pwelch.net. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,7 @@
1
+ # Contributing
2
+
3
+ 1. Fork it ( https://github.com/pwelch/virustotal_api/fork )
4
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
5
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
6
+ 4. Push to the branch (`git push origin my-new-feature`)
7
+ 5. Create a new Pull Request
@@ -0,0 +1,15 @@
1
+ ## Expected Behavior
2
+
3
+
4
+ ## Actual Behavior
5
+
6
+
7
+ ## Steps to Reproduce the Problem
8
+
9
+ 1.
10
+
11
+ ## Specifications
12
+
13
+ - Version:
14
+ - Platform:
15
+ - Subsystem:
@@ -0,0 +1,26 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ Test:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
17
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
18
+ uses: ruby/setup-ruby@v1.46.0
19
+ with:
20
+ ruby-version: 2.6
21
+ - name: Install dependencies
22
+ run: bundle install
23
+ - name: Lint
24
+ run: bundle exec rake rubocop
25
+ - name: Run tests
26
+ run: bundle exec rake
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ .rake_tasks~
@@ -1,18 +1,16 @@
1
1
  # This is the configuration used to check the rubocop source code.
2
2
 
3
3
  AllCops:
4
+ NewCops: enable
4
5
  Exclude:
5
6
  - 'test/fixtures/*'
6
7
 
7
8
  Style/StringLiterals:
8
9
  Enabled: true
9
10
 
10
- Style/UnneededPercentQ:
11
+ Style/RedundantPercentQ:
11
12
  Enabled: true
12
13
 
13
- Style/HashSyntax:
14
- EnforcedStyle: hash_rockets
15
-
16
14
  # Disabled Checks
17
15
  Style/Documentation:
18
16
  Enabled: false
@@ -23,5 +21,19 @@ Style/PercentLiteralDelimiters:
23
21
  Style/RegexpLiteral:
24
22
  Enabled: false
25
23
 
26
- Style/BracesAroundHashParameters:
24
+ Lint/MissingCopEnableDirective:
25
+ Exclude:
26
+ - 'test/base_test.rb'
27
+
28
+ Naming/MethodParameterName:
29
+ Exclude:
30
+ - 'lib/virustotal_api/ip_report.rb'
31
+
32
+ Layout/LineLength:
33
+ Enabled: false
34
+
35
+ Metrics/MethodLength:
36
+ Enabled: false
37
+
38
+ Gemspec/RequiredRubyVersion:
27
39
  Enabled: false
@@ -0,0 +1,34 @@
1
+ # VirusTotal API Changelog
2
+
3
+ ## [0.5.0] - 2020-09-02
4
+
5
+ * Full rework to support API V3.
6
+ * [@crondaemon](https://github.com/crondaemon) & [@jonnynux](https://github.com/jonnynux)
7
+ * Move to Ruby 2.6 for minimum Ruby version
8
+
9
+ ## [0.4.1] - 2019-09-04
10
+
11
+ * Fixed Reponse Parsing
12
+ * [@jonnynux](https://github.com/jonnynux)
13
+
14
+ ## [0.4.0] - 2019-07-23
15
+
16
+ * Added ReScan [#15](https://github.com/pwelch/virustotal_api/pull/15)
17
+ * Added URL Scan [#16](https://github.com/pwelch/virustotal_api/pull/16)
18
+ * [@jonnynux](https://github.com/jonnynux)
19
+
20
+ ## [0.3.0] - 2018-03-31
21
+
22
+ * Added optional scan param for url report API [#5](https://github.com/pwelch/virustotal_api/pull/5)
23
+ * [@mkunkel ](https://github.com/mkunkel)
24
+
25
+ ## [0.2.0] - 2015-12-19
26
+
27
+ * Added Check if the respone is 204 [#2](https://github.com/pwelch/virustotal_api/pull/2)
28
+ * [@postmodern](https://github.com/postmodern)
29
+
30
+ ## [0.1.0] - 2014-12-26
31
+
32
+ * First Release
33
+
34
+ https://keepachangelog.com
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # VirustotalAPI
2
2
 
3
- Ruby Gem for [VirusTotal](https://www.virustotal.com) [V2 API](https://www.virustotal.com/en/documentation/public-api/)
3
+ Ruby Gem for [VirusTotal](https://www.virustotal.com) [V3 API](https://developers.virustotal.com/v3.0/reference).
4
+ If you want the version 2, check out the gem versions up to [0.4.0](https://github.com/crondaemon/virustotal_api/tree/v0.4.0).
4
5
 
5
- [![Build Status](https://secure.travis-ci.org/pwelch/virustotal_api.svg)](http://travis-ci.org/pwelch/virustotal_api)
6
+ ![Ruby](https://github.com/pwelch/virustotal_api/workflows/Ruby/badge.svg)
7
+
8
+ [![Gem Version](https://badge.fury.io/rb/virustotal_api.svg)](http://badge.fury.io/rb/virustotal_api)
6
9
 
7
10
  ## Installation
8
11
 
@@ -22,7 +25,11 @@ Or install it yourself as:
22
25
 
23
26
  ## Usage
24
27
 
25
- ### File Report
28
+ VirusTotal only allows 4 queries per minute for their Public API. https://www.virustotal.com/en/faq/
29
+
30
+ You will need a Private API Key if you require more queries per minute.
31
+
32
+ ### File Find
26
33
 
27
34
  ```ruby
28
35
  require 'virustotal_api'
@@ -30,7 +37,7 @@ require 'virustotal_api'
30
37
  sha256 = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
31
38
  api_key = 'MY_API_KEY'
32
39
 
33
- vtreport = VirustotalAPI::FileReport.find(sha256, api_key)
40
+ vtreport = VirustotalAPI::File.find(sha256, api_key)
34
41
 
35
42
  # Does the resource have any results?
36
43
  vtreport.exists?
@@ -38,14 +45,19 @@ vtreport.exists?
38
45
 
39
46
  # URL for File Report (if it exists)
40
47
  vtreport.report_url
41
- # => "https://www.virustotal.com/file/01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b/analysis/1418032127/"
48
+ # => "https://www.virustotal.com/api/v3/files/01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b"
42
49
 
43
50
  # Report results (if they exist) are available via #report
44
- vtreport.report["scans"]["ClamAV"]
45
- # => {"detected"=>false, "version"=>"0.98.5.0", "result"=>nil, "update"=>"20141208"}
51
+ vtreport.report['data']['attributes']['last_analysis_results']['ClamAV']
52
+ # => {"category"=>"undetected", "engine_name"=>"ClamAV", "engine_update"=>"20200826",
53
+ # "engine_version"=>"0.102.4.0", "method"=>"blacklist", "result"=>nil}
54
+
55
+ # Check whether an Antivirus detected this sample or not
56
+ vtreport.detected_by('ClamAV')
57
+ # => false
46
58
  ```
47
59
 
48
- ### File Scan
60
+ ### File Upload
49
61
 
50
62
  ```ruby
51
63
  require 'virustotal_api'
@@ -53,28 +65,43 @@ require 'virustotal_api'
53
65
  file = '/path/to/file'
54
66
  api_key = 'MY_API_KEY'
55
67
 
56
- vtscan = VirustotalAPI::FileScan.scan(file, api_key)
68
+ vtscan = VirustotalAPI::File.upload(file, api_key)
57
69
 
58
- # Scan ID of file
59
- vtscan.scan_id
70
+ # Virustotal ID of file
71
+ vtscan.id
60
72
  # => "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b-1419454668"
61
73
 
62
74
  # Response results are available via #response
63
- vtreport.response
75
+ vtscan.report
76
+ # =>
77
+ {"data"=>
78
+ {"id"=>"MTkxNDBmMjU4ZGY1OGZiYzZjNmU2ODcyMWNhYjhkZTM6MTU5ODUzMTE5OQ==",
79
+ "type"=>"analysis"}}
80
+ ```
81
+
82
+ ### File Analyse
83
+
84
+ ```ruby
85
+ require 'virustotal_api'
86
+
87
+ sha256 = '01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b'
88
+ api_key = 'MY_API_KEY'
89
+
90
+ vtrescan = VirustotalAPI::File.analyse(sha256, api_key)
91
+
92
+ # Virustotal ID of file
93
+ vtrescan.id
94
+ # => "MTkxNDBmMjU4ZGY1OGZiYzZjNmU2ODcyMWNhYjhkZTM6MTU5ODUzMTE5OQ=="
95
+
96
+ # Response results are available via #response
97
+ vtrescan.report
64
98
  # =>
65
- {
66
- "scan_id"=>"01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b-1419454668",
67
- "sha1"=>"adc83b19e793491b1c6ea0fd8b46cd9f32e592fc",
68
- "resource"=>"01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b",
69
- "response_code"=>1,
70
- "sha256"=>"01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b",
71
- "permalink"=>"https://www.virustotal.com/file/01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b/analysis/1419454668/",
72
- "md5"=>"68b329da9893e34099c7d8ad5cb9c940",
73
- "verbose_msg"=>"Scan request successfully queued, come back later for the report"
74
- }
99
+ {"data"=>
100
+ {"id"=>"MTkxNDBmMjU4ZGY1OGZiYzZjNmU2ODcyMWNhYjhkZTM6MTU5ODUzMTE5OQ==",
101
+ "type"=>"analysis"}}
75
102
  ```
76
103
 
77
- ### URL Report
104
+ ### URL find
78
105
 
79
106
  ```ruby
80
107
  require 'virustotal_api'
@@ -82,7 +109,7 @@ require 'virustotal_api'
82
109
  url = 'http://www.google.com'
83
110
  api_key = 'MY_API_KEY'
84
111
 
85
- vturl_report = VirustotalAPI::URLReport.find(url, api_key)
112
+ vturl_report = VirustotalAPI::URL.find(url, api_key)
86
113
 
87
114
  # Does the resource have any results?
88
115
  vturl_report.exists?
@@ -90,14 +117,37 @@ vturl_report.exists?
90
117
 
91
118
  # URL for Report (if it exists)
92
119
  vturl_report.report_url
93
- # => "https://www.virustotal.com/url/dd014af5ed6b38d9130e3f466f850e46d21b951199d53a18ef29ee9341614eaf/analysis/1419457210/"
120
+ # => "https://www.virustotal.com/api/v3/urls/dd014af5ed6b38d9130e3f466f850e46d21b951199d53a18ef29ee9341614eaf/"
94
121
 
95
122
  # Report results (if they exist) are available via #report
96
- vturl_report.report["scans"]["Opera"]
97
- # => {"detected"=>false, "result"=>"clean site"}
123
+ vturl_report.report['data']['attributes']['last_analysis_results']['Avira']
124
+ # => {"category"=>"harmless", "engine_name"=>"Avira", "method"=>"blacklist", "result"=>"clean"}
125
+ ```
126
+
127
+ ### URL Upload
128
+
129
+ ```ruby
130
+ require 'virustotal_api'
131
+
132
+ url = 'http://www.google.com'
133
+ api_key = 'MY_API_KEY'
134
+
135
+ vturl_scan = VirustotalAPI::URL.upload(url, api_key)
136
+
137
+ # Virustotal ID of file
138
+ vturl_scan.id
139
+ # => "u-dd014af5ed6b38d9130e3f466f850e46d21b951199d53a18ef29ee9341614eaf-1598531929"
140
+
141
+ # Response results are available via #response
142
+ vturl_scan.report
143
+ # =>
144
+ {"data"=>
145
+ {"id"=>
146
+ "u-dd014af5ed6b38d9130e3f466f850e46d21b951199d53a18ef29ee9341614eaf-1598531929",
147
+ "type"=>"analysis"}}
98
148
  ```
99
149
 
100
- ### IP Report
150
+ ### IP Find
101
151
 
102
152
  ```ruby
103
153
  require 'virustotal_api'
@@ -105,7 +155,7 @@ require 'virustotal_api'
105
155
  ip = '8.8.8.8'
106
156
  api_key = 'MY_API_KEY'
107
157
 
108
- vtip_report = VirustotalAPI::IPReport.find(ip, api_key)
158
+ vtip_report = VirustotalAPI::IP.find(ip, api_key)
109
159
 
110
160
  # Does the resource have any results?
111
161
  vtip_report.exists?
@@ -116,7 +166,7 @@ vtip_report.report
116
166
  # => Hash of report results
117
167
  ```
118
168
 
119
- ### Domain Report
169
+ ### Domain Find
120
170
 
121
171
  ```ruby
122
172
  require 'virustotal_api'
@@ -124,7 +174,7 @@ require 'virustotal_api'
124
174
  domain = 'virustotal.com'
125
175
  api_key = 'MY_API_KEY'
126
176
 
127
- vtdomain_report = VirustotalAPI::DomainReport.find(domain, api_key)
177
+ vtdomain_report = VirustotalAPI::Domain.find(domain, api_key)
128
178
 
129
179
  # Does the resource have any results?
130
180
  vtdomain_report.exists?
@@ -135,6 +185,13 @@ vtdomain_report.report
135
185
  # => Hash of report results
136
186
  ```
137
187
 
188
+ ## Contributors
189
+
190
+ - [@postmodern](https://github.com/postmodern)
191
+ - [@mkunkel](https://github.com/mkunkel)
192
+ - [@jonnynux](https://github.com/jonnynux)
193
+ - [@crondaemon](https://github.com/crondaemon/)
194
+
138
195
  ## Contributing
139
196
 
140
197
  1. Fork it ( https://github.com/pwelch/virustotal_api/fork )
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'bundler/gem_tasks'
3
4
  require 'rake/testtask'
4
5
  require 'rubocop/rake_task'
@@ -21,4 +22,4 @@ namespace :yard do
21
22
  end
22
23
  end
23
24
 
24
- task :default => :test
25
+ task default: :test