Class: VirusTotal::VirusTotalResult

Inherits:
Object
  • Object
show all
Defined in:
lib/virustotal/virustotalresult.rb

Overview

A Wrapper class for the results from a virustotal.com

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash, type, result) ⇒ VirusTotalResult

Creates a new instance of the [VirusTotalResult] class



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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/virustotal/virustotalresult.rb', line 13

def initialize hash, type, result
	@type = type
	@results = Array.new
	fres = Hash.new		
	
	if result["result"] == 0
			
		fres = Hash.new
		fres['hash'] = hash
		fres['scanner'] = '-'
		fres['date'] = '-'
		fres['permalink'] = '-'
		
		if @type == :hash
			fres['result'] = "Hash Not Found"
		elsif @type == :site
			fres['result'] = "Site Not Found"
		end

		@results.push fres
	elsif result["result"] == -1
		puts "[!] Invalid API KEY! Please correct this!"
		exit
	else				
		permalink = result["permalink"]
		date = result["report"][0]
		result["report"][1].each do |scanner, res|
			if res != ''
				fres = Hash.new
				fres['hash'] = hash
				fres['scanner'] = scanner
				fres['date'] = date
				fres['permalink'] = permalink unless permalink == nil
				fres['result'] = res

				@results.push fres
			end
		end
	end
	
	#if we didn't have any results let create a fake not found
	if @results.size == 0
		fres = Hash.new
		fres['hash'] = hash
		fres['scanner'] = '-'
		fres['date'] = '-'
		fres['permalink'] = '-'
		if @type == :hash
			fres['result'] = "No Results for Hash"
		elsif @type == :site
			fres['result'] = "No Results for Site"
		end
		@results.push fres				
	end			
end

Instance Attribute Details

#resultsObject

Returns the value of attribute results.



9
10
11
# File 'lib/virustotal/virustotalresult.rb', line 9

def results
  @results
end

Instance Method Details

#to_stdoutObject

Prints the [VirusTotalResult] object to screen



71
72
73
74
75
76
77
# File 'lib/virustotal/virustotalresult.rb', line 71

def to_stdout
	result_string = String.new
	@results.each do |result|
		result_string << "#{result['hash']}: Scanner: #{result['scanner']} Result: #{result['result']}\n"
	end
	print result_string
end

#to_xmlObject

Prints the [VirusTotalResult] object as a xml string to the screen



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/virustotal/virustotalresult.rb', line 81

def to_xml
	result_string = String.new
	@results.each do |result|
		result_string << "\t<vtresult>\n"
		result_string << "\t\t<hash>#{result['hash']}</hash>\n"
		result_string << "\t\t<scanner>#{result['scanner']}</scanner>\n"
		result_string << "\t\t<date>#{result['date']}</date>\n"
		result_string << "\t\t<permalink>#{result['permalink']}</permalink>\n" unless result['permalink'] == nil
		result_string << "\t\t<result>#{result['result']}</result>\n"
		result_string << "\t</vtresult>\n"
	end
	print result_string			
end

#to_yamlObject

Prints the [VirusTotalResult] object as a yaml string to the screen



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/virustotal/virustotalresult.rb', line 97

def to_yaml
	result_string = String.new
	@results.each do |result|
		result_string << "vt-result:\n"
		result_string << "  hash: #{result['hash']}\n"
		result_string << "  scanner: #{result['scanner']}\n"
		result_string << "  date: #{result['date']}\n"
		result_string << "  permalink: #{result['permalink']}\n" unless result['permalink'] == nil
		result_string << "  result: #{result['result']}\n\n"
	end
	print result_string
end