forked from a4agarwal/dropzone-user-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVirusTotal.dropzone
executable file
·177 lines (136 loc) · 4.26 KB
/
VirusTotal.dropzone
1
2
3
4
5
6
7
8
9
10
11
12
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/ruby
# Dropzone Destination Info
# Name: VirusTotal
# Description: Sends the dropped files to virustotal.com and shows the corresponding antivirus reports on your web browser.
# Handles: NSFilenamesPboardType
# Events: Clicked, Dragged
# Creator: Victor M. Alvarez
# URL: http://www.hispasec.com
# IconURL: http://dl.dropbox.com/u/174999/virustotal.png
require 'digest/md5'
require 'net/http'
require 'net/https'
require 'pathname'
class Multipart
def initialize( file_names )
@file_names = file_names
end
def post( to_url )
boundary = '----RubyMultipartClient' + rand(1000000).to_s + 'ZZZZZ'
parts = []
streams = []
@file_names.each do |param_name, filepath|
pos = filepath.rindex('/')
filename = filepath[pos + 1, filepath.length - pos]
parts << StringPart.new ( "--" + boundary + "\r\n" +
"Content-Disposition: form-data; name=\"" + param_name.to_s + "\"; filename=\"" + filename + "\"\r\n" +
"Content-Type: video/x-msvideo\r\n\r\n")
stream = File.open(filepath, "rb")
streams << stream
parts << StreamPart.new (stream, File.size(filepath))
end
parts << StringPart.new ( "\r\n--" + boundary + "--\r\n" )
post_stream = MultipartStream.new( parts )
url = URI.parse( to_url )
req = Net::HTTP::Post.new(url.path)
req.content_length = post_stream.size
req.content_type = 'multipart/form-data; boundary=' + boundary
req.body_stream = post_stream
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
streams.each do |stream|
stream.close();
end
res
end
end
class StreamPart
def initialize( stream, size )
@stream, @size = stream, size
end
def size
@size
end
def read ( offset, how_much )
@stream.read ( how_much )
end
end
class StringPart
def initialize ( str )
@str = str
end
def size
@str.length
end
def read ( offset, how_much )
@str[offset, how_much]
end
end
class MultipartStream
def initialize( parts )
@parts = parts
@part_no = 0;
@part_offset = 0;
end
def size
total = 0
@parts.each do |part|
total += part.size
end
total
end
def read ( how_much )
if @part_no >= @parts.size
return nil;
end
how_much_current_part = @parts[@part_no].size - @part_offset
how_much_current_part = if how_much_current_part > how_much
how_much
else
how_much_current_part
end
how_much_next_part = how_much - how_much_current_part
current_part = @parts[@part_no].read(@part_offset, how_much_current_part )
if how_much_next_part > 0
@part_no += 1
@part_offset = 0
next_part = read ( how_much_next_part )
current_part + if next_part
next_part
else
''
end
else
@part_offset += how_much_current_part
current_part
end
end
end
def dragged
$dz.determinate(false)
$dz.begin("Talking to VirusTotal.com...")
for path in $items
if not File.directory?(path)
file_name = Pathname.new(path).basename
md5 = Digest::MD5.hexdigest(File.read(path))
http = Net::HTTP.new("www.virustotal.com", 80)
data = "hash=#{md5}"
response, data = http.post("/vt/en/consultamd5", data)
answer = 0
if not response["Location"].include?("notfound")
answer = `./CocoaDialog yesno-msgbox --string-output --no-newline --title "VirusTotal" --no-cancel --informative-text "This file was uploaded to VirusTotal before. Do you want to re-analyse it again?" --text "#{file_name}"`
end
if response["Location"].include?("notfound") or answer == "Yes"
$dz.begin("Uploading...")
multi = Multipart.new({:archivo => path})
response = multi.post('http://www.virustotal.com/vt/en/recepcionf')
url = response["Location"]
else
location = response["Location"]
url = "http://www.virustotal.com#{location}"
end
system("open #{url}")
end
end
$dz.finish("Completed")
$dz.url(url)
end