Module: Dorothy::Vtotal

Extended by:
Vtotal
Included in:
Vtotal
Defined in:
lib/dorothy2/vtotal.rb

Instance Method Summary collapse

Instance Method Details

#analyse_file(file) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dorothy2/vtotal.rb', line 32

def analyse_file(file)
f = File.open(file, 'r')
begin
	results = RestClient.post 'https://www.virustotal.com/vtapi/v2/file/scan' , { :key => @api_key, :file => f}
	parsed = JSON.parse(results)
	LOGGER.info "VTOTAL]", " Ok, received with scan id " + parsed["scan_id"] if parsed["response_code"]
	#puts "[VTOTAL] ".yellow + parsed["verbose_msg"]
	@scanid = parsed["scan_id"] 
	rescue
	LOGGER.error "VTOTAL", "An error accurred while quering Virustotal"
	LOGGER.debug "DEBUG", "#{$!}"
end
return @scanid 
end

#check_hash(hash) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dorothy2/vtotal.rb', line 10

def check_hash(hash)
  @api_key = DoroSettings.virustotal[:vtapikey]

  scans = Uirusu::VTFile.query_report(@api_key, hash)
  if (scans["response_code"] == 1 )

    positive = ( scans["positives"] > 0 ? true : false  )
    @rate = scans["positives"].to_s + "/" + scans["total"].to_s
    @permalink = (scans["permalink"] != "-" ? scans["permalink"] : "null")
    @result_date = scans["scan_date"]
    @results = scans["scans"]


    return {:rate => @rate, :link => @permalink, :date => @result_date, :results => @results, :positive => positive}

  else
    LOGGER.error "VTOTAL", scans["verbose_msg"]
    return false
  end
end

#get_report(id) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/dorothy2/vtotal.rb', line 51

def get_report(id)
	begin
		report = RestClient.post 'https://www.virustotal.com/vtapi/v2/file/report' , { :resource => id.to_s, :key => @api_key }
		rescue
		LOGGER.error "VTOTAL", "An error accurred while quering Virustotal"
		LOGGER.debug "DEBUG", "#{$!}"
	end
	
	if !report.empty?
		
		parsed = JSON.parse(report)
		
		if (parsed["response_code"] == 1 )
			if (parsed["scans"]["McAfee"]["detected"] == true ) 
				@rate = parsed["positives"].to_s + "/" + parsed["total"].to_s
				@family = parsed["scans"]["McAfee"]["result"]
				@permalink = (parsed["permalink"] != "-" ? parsed["permalink"] : "null")
				@vendor = "McAfee" #TODO Move to config file!
				@updated = (parsed["scans"]["McAfee"]["update"] != "-" ? parsed["scans"]["McAfee"]["update"] : "null")
				@version = (parsed["scans"]["McAfee"]["version"] != "-" ? parsed["scans"]["McAfee"]["version"] : "null")
				@detected = true
				else #not detected by McAfee
				@rate = parsed["positives"].to_s + "/" + parsed["total"].to_s
				@family = "Unknown"
				@permalink = "null"
				@vendor = "McAfee" #TODO Move to config file!
				@updated = "null" 
				@version = "null"
				@detected = false
			end
			else
			LOGGER.error "VTOTAL", parsed["verbose_msg"]
			return false
		end
		else
		LOGGER.error "VTOTAL", "No data received "
		return false			
	end
	return parsed
end