GuardianUnivalle-Benito-Yucra 0.1.13__py3-none-any.whl → 0.1.15__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_sql.py +19 -16
- {guardianunivalle_benito_yucra-0.1.13.dist-info → guardianunivalle_benito_yucra-0.1.15.dist-info}/METADATA +1 -1
- {guardianunivalle_benito_yucra-0.1.13.dist-info → guardianunivalle_benito_yucra-0.1.15.dist-info}/RECORD +6 -6
- {guardianunivalle_benito_yucra-0.1.13.dist-info → guardianunivalle_benito_yucra-0.1.15.dist-info}/WHEEL +0 -0
- {guardianunivalle_benito_yucra-0.1.13.dist-info → guardianunivalle_benito_yucra-0.1.15.dist-info}/licenses/LICENSE +0 -0
- {guardianunivalle_benito_yucra-0.1.13.dist-info → guardianunivalle_benito_yucra-0.1.15.dist-info}/top_level.txt +0 -0
|
@@ -119,42 +119,45 @@ def detect_sqli_text(text: str) -> Tuple[bool, list]:
|
|
|
119
119
|
return (len(matches) > 0, matches)
|
|
120
120
|
|
|
121
121
|
|
|
122
|
+
def get_client_ip(request):
|
|
123
|
+
"""
|
|
124
|
+
Retorna la IP del cliente, manejando proxies.
|
|
125
|
+
"""
|
|
126
|
+
x_forwarded_for = request.META.get("HTTP_X_FORWARDED_FOR")
|
|
127
|
+
if x_forwarded_for:
|
|
128
|
+
# Puede contener varias IP separadas por coma
|
|
129
|
+
ip = x_forwarded_for.split(",")[0].strip()
|
|
130
|
+
else:
|
|
131
|
+
ip = request.META.get("REMOTE_ADDR")
|
|
132
|
+
return ip
|
|
133
|
+
|
|
134
|
+
|
|
122
135
|
# ==============================
|
|
123
136
|
# MIDDLEWARE
|
|
124
137
|
# ==============================
|
|
125
138
|
|
|
126
139
|
|
|
127
140
|
class SQLIDefenseMiddleware(MiddlewareMixin):
|
|
128
|
-
"""
|
|
129
|
-
Middleware para proteger la aplicación contra ataques de SQL Injection.
|
|
130
|
-
Analiza cada solicitud entrante y bloquea si detecta patrones maliciosos,
|
|
131
|
-
excepto en rutas definidas como confiables en settings.SQLI_DEFENSE_EXCLUDED_PATHS.
|
|
132
|
-
"""
|
|
133
|
-
|
|
134
141
|
def process_request(self, request):
|
|
135
|
-
# Obtener rutas excluidas desde settings
|
|
136
142
|
excluded_paths = getattr(settings, "SQLI_DEFENSE_EXCLUDED_PATHS", [])
|
|
137
|
-
|
|
138
|
-
# Saltar verificación si la ruta está excluida
|
|
139
143
|
if any(request.path.startswith(p) for p in excluded_paths):
|
|
140
144
|
return None
|
|
141
145
|
|
|
142
|
-
# Extraer texto de la solicitud
|
|
143
146
|
text = extract_payload_text(request)
|
|
144
147
|
if not text:
|
|
145
148
|
return None
|
|
146
149
|
|
|
147
|
-
# Detectar patrones SQL Injection
|
|
148
150
|
flagged, matches = detect_sqli_text(text)
|
|
149
151
|
if flagged:
|
|
150
|
-
|
|
151
|
-
logger.warning(
|
|
152
|
+
client_ip = get_client_ip(request)
|
|
153
|
+
logger.warning(
|
|
154
|
+
f"Ataque SQL detectado desde IP {client_ip}: {matches}, payload: {text}"
|
|
155
|
+
)
|
|
152
156
|
|
|
153
|
-
# Bloquear la solicitud y devolver mensaje
|
|
154
157
|
return JsonResponse(
|
|
155
|
-
{"mensaje": "Ataque detectado", "tipos": matches},
|
|
158
|
+
{"mensaje": "Ataque detectado", "tipos": matches, "ip": client_ip},
|
|
159
|
+
status=403,
|
|
156
160
|
)
|
|
157
|
-
|
|
158
161
|
return None
|
|
159
162
|
|
|
160
163
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: GuardianUnivalle-Benito-Yucra
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.15
|
|
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
|
|
@@ -7,14 +7,14 @@ GuardianUnivalle_Benito_Yucra/criptografia/kdf.py,sha256=_sbepEY1qHEKga0ExrX2WRg
|
|
|
7
7
|
GuardianUnivalle_Benito_Yucra/detectores/detector_csrf.py,sha256=EAYfLkHuxGC5rXSu4mZJ4yZDCbwBpTX8xZWGKz7i5wA,692
|
|
8
8
|
GuardianUnivalle_Benito_Yucra/detectores/detector_dos.py,sha256=lMWmCw6nccCEnek53nVjpoBCeiBqLdrSXxqRuI7VP2I,696
|
|
9
9
|
GuardianUnivalle_Benito_Yucra/detectores/detector_keylogger.py,sha256=rEDG-Q_R56OsG2ypfHVBK7erolYjdvATnAxB3yvPXts,729
|
|
10
|
-
GuardianUnivalle_Benito_Yucra/detectores/detector_sql.py,sha256=
|
|
10
|
+
GuardianUnivalle_Benito_Yucra/detectores/detector_sql.py,sha256=yBaJyZP13mN1IYhavzX2qb8AddzlVbFoUAUTxgZccHI,5841
|
|
11
11
|
GuardianUnivalle_Benito_Yucra/detectores/detector_xss.py,sha256=66V_xuxNOZEwluvWOT4-6pk5MJ3zWE1IwcVkBl7MZSg,719
|
|
12
12
|
GuardianUnivalle_Benito_Yucra/middleware_web/middleware_web.py,sha256=23pLLYqliUoMrIC6ZEwz3hKXeDjWfHSm9vYPWGmDDik,495
|
|
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.15.dist-info/licenses/LICENSE,sha256=5e4IdL542v1E8Ft0A24GZjrxZeTsVK7XrS3mZEUhPtM,37
|
|
17
|
+
guardianunivalle_benito_yucra-0.1.15.dist-info/METADATA,sha256=PKSr1QDnQBgB4YWIeg3lnIxQeLj-RoFQvmy7CeiLGsU,1893
|
|
18
|
+
guardianunivalle_benito_yucra-0.1.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
guardianunivalle_benito_yucra-0.1.15.dist-info/top_level.txt,sha256=HTWfZM64WAV_QYr5cnXnLuabQt92dvlxqlR3pCwpbDQ,30
|
|
20
|
+
guardianunivalle_benito_yucra-0.1.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|