-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
45 lines (35 loc) · 1.54 KB
/
app.py
File metadata and controls
45 lines (35 loc) · 1.54 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
from flask import Flask, request, jsonify, render_template
import requests
app = Flask(__name__)
@app.route('/', methods=['GET'])
def index():
return render_template("index.html")
@app.route('/consultar', methods=['POST'])
def consultar_virus_total():
data = request.json
ioc = data.get('ioc')
api_key = data.get('apiKey')
if not ioc or not api_key:
return jsonify({'error': 'Falta el IOC o la API Key'}), 400
# Usamos el endpoint de search que es versátil
url = f'https://www.virustotal.com/api/v3/search?query={ioc}'
headers = {
'x-apikey': api_key,
'User-Agent': 'IOC-Checker-Tool/1.0' # Buena práctica identificar el cliente
}
try:
response = requests.get(url, headers=headers, timeout=10)
if response.status_code == 200:
return jsonify(response.json())
elif response.status_code == 429:
return jsonify({'error': 'Límite de API excedido (Rate Limit)'}), 429
elif response.status_code == 401:
return jsonify({'error': 'API Key inválida'}), 401
elif response.status_code == 404:
return jsonify({'data': []}), 200 # No encontrado, devolvemos data vacía
else:
return jsonify({'error': f'Error de VirusTotal: {response.status_code}'}), response.status_code
except requests.exceptions.RequestException as e:
return jsonify({'error': f'Error de conexión: {str(e)}'}), 500
if __name__ == '__main__':
app.run(debug=True)