class VirustotalAPI::File

A class for '/files' API

Public Class Methods

analyse(resource, api_key) click to toggle source

Analyse a hash again.

@param [String] resource file as a md5/sha1/sha256 hash @param [String] api_key The key for virustotal @return [VirustotalAPI::File] Report

# File lib/virustotal_api/file.rb, line 48
def self.analyse(resource, api_key)
  report = perform("/files/#{resource}/analyse", api_key, :post)
  new(report)
end
find(resource, api_key) click to toggle source

Find a hash.

@param [String] resource file as a md5/sha1/sha256 hash @param [String] api_key The key for virustotal @return [VirustotalAPI::File] Report Search Result

# File lib/virustotal_api/file.rb, line 13
def self.find(resource, api_key)
  report = perform("/files/#{resource}", api_key)
  new(report)
end
upload(file_path, api_key, opts = {}) click to toggle source

Upload a new file.

@param [String] file_path for file to be sent for scan @param [String] api_key The key for virustotal @param [Hash] opts hash for additional options @return [VirusotalAPI::File] Report

# File lib/virustotal_api/file.rb, line 24
def self.upload(file_path, api_key, opts = {})
  filename = opts.fetch('filename') { ::File.basename(file_path) }
  report   = perform('/files', api_key, :post, filename: filename, file: ::File.open(file_path, 'r'))
  new(report)
end
upload_large(file_path, api_key, opts = {}) click to toggle source

Upload a new file with size more than 32MB.

@param [String] file_path for file to be sent for scan @param [String] api_key The key for virustotal @param [Hash] opts hash for additional options @return [VirusotalAPI::File] Report

# File lib/virustotal_api/file.rb, line 36
def self.upload_large(file_path, api_key, opts = {})
  filename = opts.fetch('filename') { ::File.basename(file_path) }
  url      = upload_url(api_key)
  report   = perform_absolute(url, api_key, :post, filename: filename, file: ::File.open(file_path, 'r'))
  new(report)
end
upload_url(api_key) click to toggle source

@return [String] url for upload file

# File lib/virustotal_api/file.rb, line 54
def self.upload_url(api_key)
  data = perform('/files/upload_url', api_key)
  data&.dig('data')
end

Public Instance Methods

detected_by(engine) click to toggle source

Check if the submitted hash is detected by an AV engine.

@param [String] engine The engine to check. @return [Boolean] true if detected

# File lib/virustotal_api/file.rb, line 63
def detected_by(engine)
  report&.dig('data', 'attributes', 'last_analysis_results', engine, 'category') == 'malicious'
end