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 =
"http://www.virustotal.com/vtapi/v2/file/scan"
REPORT_URL =
"https://www.virustotal.com/vtapi/v2/file/report"

Class Method Summary collapse

Class Method Details

.query_report(api_key, resource) ⇒ JSON

Queries a report from Virustotal.com

Parameters:

  • api_key

    Virustotal.com API key

  • resource

    MD5/sha1/sha256/scan_id to search for

Returns:

  • (JSON)

    Parsed response



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/uirusu/vtfile.rb', line 14

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
	end
end

.scan_file(api_key, path_to_file) ⇒ JSON

Submits a file to Virustotal.com for analysis

Parameters:

  • api_key

    Virustotal.com API key

  • path_to_file

    Path to file on disk to upload

Returns:

  • (JSON)

    Parsed response



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/uirusu/vtfile.rb', line 43

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