GuardianUnivalle-Benito-Yucra 0.1.64__py3-none-any.whl → 0.1.65__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of GuardianUnivalle-Benito-Yucra might be problematic. Click here for more details.
- GuardianUnivalle_Benito_Yucra/detectores/detector_dos.py +7 -13
- {guardianunivalle_benito_yucra-0.1.64.dist-info → guardianunivalle_benito_yucra-0.1.65.dist-info}/METADATA +1 -1
- {guardianunivalle_benito_yucra-0.1.64.dist-info → guardianunivalle_benito_yucra-0.1.65.dist-info}/RECORD +6 -6
- {guardianunivalle_benito_yucra-0.1.64.dist-info → guardianunivalle_benito_yucra-0.1.65.dist-info}/WHEEL +0 -0
- {guardianunivalle_benito_yucra-0.1.64.dist-info → guardianunivalle_benito_yucra-0.1.65.dist-info}/licenses/LICENSE +0 -0
- {guardianunivalle_benito_yucra-0.1.64.dist-info → guardianunivalle_benito_yucra-0.1.65.dist-info}/top_level.txt +0 -0
|
@@ -7,9 +7,9 @@ from typing import Dict, List, Set
|
|
|
7
7
|
from django.conf import settings
|
|
8
8
|
from django.utils.deprecation import MiddlewareMixin
|
|
9
9
|
from django.http import HttpResponseForbidden
|
|
10
|
-
import requests #
|
|
11
|
-
import re #
|
|
12
|
-
from ipaddress import ip_address, IPv4Address, IPv4Network # Necesario para el Escaneo Avanzado (CIDR)
|
|
10
|
+
import requests # Necesario para la función de scraping
|
|
11
|
+
import re # Necesario para el parseo de IPs/CIDR
|
|
12
|
+
from ipaddress import ip_address, IPv4Address, IPv4Network # Necesario para el Escaneo Avanzado (CIDR) check ip
|
|
13
13
|
|
|
14
14
|
# =====================================================
|
|
15
15
|
# === CONFIGURACIÓN GLOBAL Y LOGGER ===
|
|
@@ -27,19 +27,18 @@ if not logger.handlers:
|
|
|
27
27
|
# URLs CONCEPTUALES de donde EXTRAERÍAS IPs/CIDR
|
|
28
28
|
IP_BLACKLIST_SOURCES = [
|
|
29
29
|
# 1. FireHOL (Agregador General de Nivel 1)
|
|
30
|
-
# Resultado: Éxito al obtener
|
|
30
|
+
# Resultado: Éxito al obtener
|
|
31
31
|
"https://iplists.firehol.org/files/firehol_level1.netset",
|
|
32
32
|
|
|
33
33
|
# 2. Abuse.ch Feodo Tracker (Botnets C&C)
|
|
34
|
-
# Resultado: Éxito al obtener
|
|
34
|
+
# Resultado: Éxito al obtener
|
|
35
35
|
"https://feodotracker.abuse.ch/downloads/ipblocklist.txt",
|
|
36
36
|
|
|
37
37
|
# 3. Tor Project (Nodos de Salida)
|
|
38
|
-
# Resultado: Éxito al obtener
|
|
38
|
+
# Resultado: Éxito al obtener
|
|
39
39
|
"https://check.torproject.org/torbulkexitlist?ip=1.1.1.1"
|
|
40
40
|
]
|
|
41
41
|
|
|
42
|
-
# Cabeceras para simular un navegador
|
|
43
42
|
SCRAPING_HEADERS = {
|
|
44
43
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
|
45
44
|
}
|
|
@@ -59,7 +58,7 @@ def fetch_and_parse_blacklists() -> Set[str]:
|
|
|
59
58
|
|
|
60
59
|
for url in IP_BLACKLIST_SOURCES:
|
|
61
60
|
try:
|
|
62
|
-
response = requests.get(url, headers=SCRAPING_HEADERS, timeout=
|
|
61
|
+
response = requests.get(url, headers=SCRAPING_HEADERS, timeout=15)
|
|
63
62
|
response.raise_for_status()
|
|
64
63
|
|
|
65
64
|
found_ips = ip_pattern.findall(response.text)
|
|
@@ -158,7 +157,6 @@ def get_client_ip(request) -> str:
|
|
|
158
157
|
|
|
159
158
|
def limpiar_registro_global():
|
|
160
159
|
"""Elimina IPs sin actividad reciente y desbloquea IPs temporales."""
|
|
161
|
-
# ... (La implementación de limpiar_registro_global permanece igual)
|
|
162
160
|
ahora = time.time()
|
|
163
161
|
expiracion = VENTANA_SEGUNDOS * 2
|
|
164
162
|
inactivas = []
|
|
@@ -178,7 +176,6 @@ def limpiar_registro_global():
|
|
|
178
176
|
|
|
179
177
|
def limpiar_registro(ip: str):
|
|
180
178
|
"""Limpia peticiones antiguas fuera de la ventana de tiempo."""
|
|
181
|
-
# ... (La implementación de limpiar_registro permanece igual)
|
|
182
179
|
ahora = time.time()
|
|
183
180
|
if ip not in REGISTRO_SOLICITUDES:
|
|
184
181
|
REGISTRO_SOLICITUDES[ip] = deque()
|
|
@@ -188,7 +185,6 @@ def limpiar_registro(ip: str):
|
|
|
188
185
|
|
|
189
186
|
def calcular_nivel_amenaza_dos(tasa_peticion: int, limite: int = LIMITE_PETICIONES) -> float:
|
|
190
187
|
"""Calcula la puntuación de amenaza DoS (Rate Limiting)."""
|
|
191
|
-
# ... (La implementación de calcular_nivel_amenaza_dos permanece igual)
|
|
192
188
|
proporcion = tasa_peticion / max(limite, 1)
|
|
193
189
|
s_dos = PESO_DOS * min(proporcion, 2.0)
|
|
194
190
|
return round(min(s_dos, 1.0), 3)
|
|
@@ -218,7 +214,6 @@ def registrar_evento(tipo: str, descripcion: str, severidad: str = "MEDIA"):
|
|
|
218
214
|
|
|
219
215
|
def detectar_dos(ip: str, tasa_peticion: int, limite: int = LIMITE_PETICIONES) -> bool:
|
|
220
216
|
"""Evalúa si la tasa de peticiones excede el umbral permitido y aplica mitigación."""
|
|
221
|
-
# ... (La implementación de detectar_dos permanece igual)
|
|
222
217
|
if tasa_peticion > limite:
|
|
223
218
|
registrar_evento(
|
|
224
219
|
tipo="DoS",
|
|
@@ -237,7 +232,6 @@ def detectar_dos(ip: str, tasa_peticion: int, limite: int = LIMITE_PETICIONES) -
|
|
|
237
232
|
|
|
238
233
|
def analizar_headers_avanzado(user_agent: str, referer: str) -> List[str]:
|
|
239
234
|
"""Detecta patrones sospechosos, penalizando User-Agents automatizados."""
|
|
240
|
-
# ... (La implementación de analizar_headers_avanzado permanece igual)
|
|
241
235
|
sospechas = []
|
|
242
236
|
|
|
243
237
|
if not user_agent or len(user_agent) < 10 or user_agent.lower() == "python-requests/2.25.1":
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: GuardianUnivalle-Benito-Yucra
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.65
|
|
4
4
|
Summary: Middleware y detectores de seguridad (SQLi, XSS, CSRF, DoS, Keylogger) para Django/Flask
|
|
5
5
|
Author-email: Andres Benito Calle Yucra <benitoandrescalle035@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -5,7 +5,7 @@ GuardianUnivalle_Benito_Yucra/criptografia/cifrado_aead.py,sha256=wfoRpaKvOqPbol
|
|
|
5
5
|
GuardianUnivalle_Benito_Yucra/criptografia/intercambio_claves.py,sha256=9djnlzb022hUhrDbQyWz7lWLbkn_vQZ4K7qar1FXYmo,829
|
|
6
6
|
GuardianUnivalle_Benito_Yucra/criptografia/kdf.py,sha256=_sbepEY1qHEKga0ExrX2WRg1HeCPY5MC5CfXZWYyl-A,709
|
|
7
7
|
GuardianUnivalle_Benito_Yucra/detectores/detector_csrf.py,sha256=VASJJztJtKwYpjuEUXc-biHSVbIYXhwCzOPrLNXu3qY,7832
|
|
8
|
-
GuardianUnivalle_Benito_Yucra/detectores/detector_dos.py,sha256
|
|
8
|
+
GuardianUnivalle_Benito_Yucra/detectores/detector_dos.py,sha256=31riNrqe87uaKPcP3tSduknSOp2YYJReP9mw7fZRmoA,14514
|
|
9
9
|
GuardianUnivalle_Benito_Yucra/detectores/detector_keylogger.py,sha256=L5RQ0Sdgg7hTU1qkZYwt7AcDqtAzT6u-jwBGo7YWfsw,8078
|
|
10
10
|
GuardianUnivalle_Benito_Yucra/detectores/detector_sql.py,sha256=toYXgxLo1Wy_QCnqcboD7_qYbgudPtP4kEzci7GoDkA,12089
|
|
11
11
|
GuardianUnivalle_Benito_Yucra/detectores/detector_xss.py,sha256=Cirjf1fo0j-wOO2baG8GFehAvjPy5JUF9krUg5AtofU,14452
|
|
@@ -13,8 +13,8 @@ GuardianUnivalle_Benito_Yucra/middleware_web/middleware_web.py,sha256=23pLLYqliU
|
|
|
13
13
|
GuardianUnivalle_Benito_Yucra/mitigacion/limitador_peticion.py,sha256=ipMOebYhql-6mSyHs0ddYXOcXq9w8P_IXLlpiIqGncw,246
|
|
14
14
|
GuardianUnivalle_Benito_Yucra/mitigacion/lista_bloqueo.py,sha256=6AYWII4mrmwCLHCvGTyoBxR4Oasr4raSHpFbVjqn7d8,193
|
|
15
15
|
GuardianUnivalle_Benito_Yucra/puntuacion/puntuacion_amenaza.py,sha256=Wx5XfcII4oweLvZsTBEJ7kUc9pMpP5-36RfI5C5KJXo,561
|
|
16
|
-
guardianunivalle_benito_yucra-0.1.
|
|
17
|
-
guardianunivalle_benito_yucra-0.1.
|
|
18
|
-
guardianunivalle_benito_yucra-0.1.
|
|
19
|
-
guardianunivalle_benito_yucra-0.1.
|
|
20
|
-
guardianunivalle_benito_yucra-0.1.
|
|
16
|
+
guardianunivalle_benito_yucra-0.1.65.dist-info/licenses/LICENSE,sha256=5e4IdL542v1E8Ft0A24GZjrxZeTsVK7XrS3mZEUhPtM,37
|
|
17
|
+
guardianunivalle_benito_yucra-0.1.65.dist-info/METADATA,sha256=4m-wJsof2PGapob-mYLjxeq3q3OQWSVgshHGoCec4ok,1893
|
|
18
|
+
guardianunivalle_benito_yucra-0.1.65.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
guardianunivalle_benito_yucra-0.1.65.dist-info/top_level.txt,sha256=HTWfZM64WAV_QYr5cnXnLuabQt92dvlxqlR3pCwpbDQ,30
|
|
20
|
+
guardianunivalle_benito_yucra-0.1.65.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|