-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvt_api.py
More file actions
315 lines (247 loc) · 7.86 KB
/
vt_api.py
File metadata and controls
315 lines (247 loc) · 7.86 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
from flask import Flask, Blueprint, abort, request, url_for, jsonify
import requests
import virustotal
from os.path import join
from virustotal import VirusTotal
import config
vt = Blueprint('vt', __name__, url_prefix='/vt')
#### VIRUSTOTAL API ####
def getVTRoutes(vt):
res = []
endpoints = vt.getEndpoints()
for base in endpoints:
for idx in endpoints[base]['endpoints']:
res.append(idx)
return res
@vt.route('/', methods=["GET"])
def vt_main():
vt = config.VT['VT']
return jsonify({'endpoints': vt.getEndpoints()})
@vt.route('/file')
@vt.route('/file/')
def vt_file():
vt = config.VT['VT']
return jsonify({'endpoints': vt.File.getEndpoints()})
@vt.route('/file/report', methods=["GET"])
def vt_file_report():
vt = config.VT['VT']
args = request.args
resource = args.get('resource')
try:
allinfo = bool(args.get('allinfo', False))
except:
return "Invalid value for allinfo, expected True/False!"
try:
res = vt.File.report(resource, allinfo=allinfo)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/scan', methods=["GET"])
def vt_file_scan():
vt = config.VT['VT']
args = request.args
filename = args.get('file')
if filename is not None:
filename = join(config.UPLOAD_FOLDER, filename)
specialurl = args.get('specialurl')
try:
res = vt.File.scan(filename, specialurl=specialurl)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/scan/uploadurl', methods=["GET"])
@vt.route('/file/scan/upload_url', methods=["GET"])
def vt_file_scan_uploadurl():
vt = config.VT['VT']
try:
res = vt.File.scan_uploadurl()
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/rescan', methods=["GET"])
def vt_file_rescan():
vt = config.VT['VT']
args = request.args
resource = args.get('resource')
try:
res = vt.File.rescan(resource)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/download', methods=["GET"])
def vt_file_download():
vt = config.VT['VT']
args = request.args
hash = args.get('hash')
try:
res = vt.File.download(hash)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/behavior', methods=["GET"])
@vt.route('/file/behaviour', methods=["GET"])
def vt_file_behaviour():
vt = config.VT['VT']
args = request.args
hash = args.get('hash')
try:
res = vt.File.behaviour(hash)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/networktraffic', methods=["GET"])
@vt.route('/file/network-traffic', methods=["GET"])
def vt_file_networktraffic():
vt = config.VT['VT']
args = request.args
hash = args.get('hash')
try:
res = vt.File.networktraffic(hash)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/feed', methods=["GET"])
def vt_file_feed():
vt = config.VT['VT']
args = request.args
timestamp = args.get('timestamp')
try:
res = vt.File.feed(timestamp)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/clusters', methods=["GET"])
def vt_file_clusters():
vt = config.VT['VT']
args = request.args
date = args.get('date')
try:
res = vt.File.clusters(date)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/file/search', methods=["GET"])
def vt_file_search():
vt = config.VT['VT']
args = request.args
query = args.get('query')
offset = args.get('offset')
try:
res = vt.File.search(query, offset=offset)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/url')
@vt.route('/url/')
def vt_url():
vt = config.VT['VT']
return jsonify({'endpoints': vt.URL.getEndpoints()})
@vt.route('/url/report', methods=["GET"])
def vt_url_report():
vt = config.VT['VT']
args = request.args
resource = args.get('resource')
try:
allinfo = bool(args.get('allinfo', False))
except:
return "Invalid value for allinfo, expected True/False!"
try:
scan = int(args.get('scan', 0))
except:
return "Invalid value for scan, expected int!"
try:
res = vt.URL.report(resource, allinfo=allinfo, scan=scan)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/url/scan', methods=["GET"])
def vt_url_scan():
vt = config.VT['VT']
args = request.args
url = args.get('url')
try:
res = vt.URL.scan(url)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/url/feed', methods=["GET"])
def vt_url_feed():
vt = config.VT['VT']
args = request.args
timestamp = args.get('timestamp')
try:
res = vt.URL.feed(timestamp)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/domain')
@vt.route('/domain/')
def vt_domain():
vt = config.VT['VT']
return jsonify({'endpoints': vt.Domain.getEndpoints()})
@vt.route('/domain/report', methods=["GET"])
def vt_domain_report():
vt = config.VT['VT']
args = request.args
domain = args.get('domain')
try:
res = vt.Domain.report(domain)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/ipaddress')
@vt.route('/ipaddress/')
@vt.route('/ip-address')
@vt.route('/ip-address/')
def vt_ipaddress():
vt = config.VT['VT']
return jsonify({'endpoints': vt.IpAddress.getEndpoints()})
@vt.route('/ipaddress/report', methods=["GET"])
@vt.route('/ip-address/report', methods=["GET"])
def vt_ipaddress_report():
vt = config.VT['VT']
args = request.args
ip = args.get('ip')
try:
res = vt.IpAddress.report(ip)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/comments')
@vt.route('/comments/')
def vt_comments():
vt = config.VT['VT']
return jsonify({'endpoints': vt.Comments.getEndpoints()})
@vt.route('/comments/get', methods=["GET"])
def vt_comments_get():
vt = config.VT['VT']
args = request.args
resource = args.get('resource')
before = args.get('before')
try:
res = vt.Comments.get(resource, before=before)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
@vt.route('/comments/put', methods=["POST"])
def vt_comments_put():
vt = config.VT['VT']
args = request.args
resource = args.get('resource')
# comment = args.get('comment')
# modify to accept data from post contents
comment = None
try:
res = vt.Comments.put(resource, comment)
except virustotal.VT_Error as msg:
return jsonify({'error': str(msg)}), 500
return jsonify({'results': res})
########################
def searchVT(query, offset=None):
vt = config.VT['VT']
try:
res = vt.File.search(query, offset=offset)
except virustotal.VT_Error as msg:
print(msg)
return {'error': str(msg)}
return {"data": res}