Module: Uirusu::VTFile
- Defined in:
- lib/uirusu/vtfile.rb
Overview
Module for Accessing the File scan and report functionalities of the Virustotal.com public API
Constant Summary collapse
- SCAN_URL =
Uirusu::VT_API + "/file/scan"
- RESCAN_URL =
Uirusu::VT_API + "/file/rescan"
- REPORT_URL =
Uirusu::VT_API + "/file/report"
Class Method Summary collapse
-
.query_report(api_key, resource) ⇒ JSON
Queries a report from Virustotal.com.
-
.rescan_file(api_key, resource) ⇒ JSON
Requests an existing file to be rescanned.
-
.scan_file(api_key, path_to_file) ⇒ JSON
Submits a file to Virustotal.com for analysis.
Class Method Details
.query_report(api_key, resource) ⇒ JSON
Queries a report from Virustotal.com
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/uirusu/vtfile.rb', line 44 def VTFile.query_report(api_key, resource) if api_key == nil raise "Invalid API Key" end if resource == nil raise "Invalid resource, must be md5/sha1/sha256/scan_id" end response = RestClient.post REPORT_URL, :apikey => api_key, :resource => resource case response.code when 429 raise "Virustotal limit reached. Try again later." when 403 raise "Invalid privileges, please check your API key." when 200 JSON.parse(response) when 500 nil else raise "Unknown Server error." end end |
.rescan_file(api_key, resource) ⇒ JSON
Requests an existing file to be rescanned.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/uirusu/vtfile.rb', line 104 def self.rescan_file(api_key, resource) if api_key == nil raise "Invalid API Key" end if resource == nil raise "Invalid resource, must be md5/sha1/sha256/scan_id" end response = RestClient.post RESCAN_URL, :apikey => api_key, :resource => resource case response.code when 429 raise "Virustotal limit reached. Try again later." when 403 raise "Invalid privileges, please check your API key." when 200 JSON.parse(response) when 500 nil else raise "Unknown Server error." end end |
.scan_file(api_key, path_to_file) ⇒ JSON
Submits a file to Virustotal.com for analysis
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/uirusu/vtfile.rb', line 75 def self.scan_file(api_key, path_to_file) if !File.exists?(path_to_file) raise Errno::ENOENT end if api_key == nil raise "Invalid API Key" end response = RestClient.post SCAN_URL, :apikey => api_key, :filename=> path_to_file, :file => File.new(path_to_file, 'rb') case response.code when 429 raise "Virustotal limit reached. Try again later." when 403 raise "Invalid privileges, please check your API key." when 200 JSON.parse(response) else raise "Unknown Server error." end end |