Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- Dockerfile +10 -0
- README.md +1 -28
- app.py +17 -100
- requirements.txt +1 -6
Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -8,31 +8,4 @@ app_file: app.py
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
-
# Autoevaluación de Ciberseguridad
|
| 12 |
-
|
| 13 |
-
Herramienta interactiva para evaluar tu postura de ciberseguridad con análisis IA integrado.
|
| 14 |
-
|
| 15 |
-
## 🚀 Características
|
| 16 |
-
|
| 17 |
-
- ✅ Evaluación en 3 dominios clave
|
| 18 |
-
- 📊 Puntuación automática
|
| 19 |
-
- 🤖 Análisis con IA
|
| 20 |
-
- 📱 Diseño responsive
|
| 21 |
-
- ⚡ Resultados inmediatos
|
| 22 |
-
|
| 23 |
-
## 🛠️ Tecnologías
|
| 24 |
-
|
| 25 |
-
- FastAPI (Backend)
|
| 26 |
-
- Transformers (IA)
|
| 27 |
-
- HTML/CSS/JS (Frontend)
|
| 28 |
-
- Docker (Despliegue)
|
| 29 |
-
|
| 30 |
-
## 📋 Dominios Evaluados
|
| 31 |
-
|
| 32 |
-
1. **Perímetro/Firewall**
|
| 33 |
-
2. **Backups**
|
| 34 |
-
3. **Monitoreo**
|
| 35 |
-
|
| 36 |
-
---
|
| 37 |
-
|
| 38 |
-
*Desarrollado por Doctor Linux - Expertos en Ciberseguridad Operativa*
|
|
|
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# Autoevaluación de Ciberseguridad
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,43 +1,9 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from fastapi.responses import HTMLResponse
|
| 3 |
-
from fastapi.staticfiles import StaticFiles
|
| 4 |
from pydantic import BaseModel
|
| 5 |
-
from typing import List
|
| 6 |
-
import json
|
| 7 |
-
import os
|
| 8 |
|
| 9 |
-
app = FastAPI(
|
| 10 |
-
title="Cibertest IA - Doctor Linux",
|
| 11 |
-
description="Autoevaluación de Ciberseguridad Operativa con IA",
|
| 12 |
-
version="1.0.0"
|
| 13 |
-
)
|
| 14 |
-
|
| 15 |
-
# Servir archivos estáticos
|
| 16 |
-
app.mount("/static", StaticFiles(directory="."), name="static")
|
| 17 |
-
|
| 18 |
-
# ----- IA Simplificada -----
|
| 19 |
-
ia_generator = None
|
| 20 |
-
IA_AVAILABLE = False
|
| 21 |
-
|
| 22 |
-
def load_ia_model():
|
| 23 |
-
global ia_generator, IA_AVAILABLE
|
| 24 |
-
try:
|
| 25 |
-
from transformers import pipeline
|
| 26 |
-
# Modelo más liviano y rápido
|
| 27 |
-
ia_generator = pipeline(
|
| 28 |
-
"text2text-generation",
|
| 29 |
-
model="google/flan-t5-small",
|
| 30 |
-
max_length=300,
|
| 31 |
-
truncation=True
|
| 32 |
-
)
|
| 33 |
-
IA_AVAILABLE = True
|
| 34 |
-
print("✅ IA cargada correctamente")
|
| 35 |
-
except Exception as e:
|
| 36 |
-
IA_AVAILABLE = False
|
| 37 |
-
print(f"❌ IA no disponible: {e}")
|
| 38 |
-
|
| 39 |
-
# Cargar modelo al inicio
|
| 40 |
-
load_ia_model()
|
| 41 |
|
| 42 |
class DomainScore(BaseModel):
|
| 43 |
name: str
|
|
@@ -49,87 +15,38 @@ class AnalysisRequest(BaseModel):
|
|
| 49 |
|
| 50 |
@app.post("/analyze")
|
| 51 |
async def analyze(data: AnalysisRequest):
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
if not IA_AVAILABLE:
|
| 55 |
-
# Respuesta predeterminada si la IA falla
|
| 56 |
-
basic_analysis = f"""
|
| 57 |
🔒 **ANÁLISIS DE CIBERSEGURIDAD - DOCTOR LINUX**
|
| 58 |
|
| 59 |
**PUNTAJE GENERAL:** {data.overall}%
|
| 60 |
|
| 61 |
**RESUMEN:**
|
| 62 |
-
{"Excelente postura de seguridad" if data.overall >= 80 else
|
| 63 |
-
"Postura media que requiere mejoras" if data.overall >= 60 else
|
| 64 |
-
"Postura crítica que necesita atención inmediata"}
|
| 65 |
|
| 66 |
**ÁREAS EVALUADAS:**
|
| 67 |
{chr(10).join([f"• {domain.name}: {domain.score}%" for domain in data.domains])}
|
| 68 |
|
| 69 |
**RECOMENDACIONES PRIORITARIAS:**
|
| 70 |
-
1. Revisar
|
| 71 |
2. Implementar estrategia de backups 3-2-1
|
| 72 |
-
3. Establecer sistema de monitoreo
|
| 73 |
4. Implementar autenticación multifactor
|
| 74 |
-
5. Realizar pruebas de recuperación
|
| 75 |
|
| 76 |
**PRÓXIMOS PASOS:**
|
| 77 |
• Agenda diagnóstico técnico detallado
|
| 78 |
-
• Desarrolla plan de remediación
|
| 79 |
-
• Establece métricas de seguimiento
|
| 80 |
-
"""
|
| 81 |
-
return {"analysis": basic_analysis}
|
| 82 |
-
|
| 83 |
-
try:
|
| 84 |
-
# Prompt optimizado para el modelo
|
| 85 |
-
prompt = f"""
|
| 86 |
-
Eres Doctor Linux, experto en ciberseguridad operativa. Analiza estos resultados:
|
| 87 |
-
|
| 88 |
-
PUNTAJE GLOBAL: {data.overall}%
|
| 89 |
-
|
| 90 |
-
DETALLE POR ÁREAS:
|
| 91 |
-
{chr(10).join([f"- {domain.name}: {domain.score}%" for domain in data.domains])}
|
| 92 |
-
|
| 93 |
-
Genera un informe conciso con:
|
| 94 |
-
1. RESUMEN (1 párrafo breve)
|
| 95 |
-
2. 3 RIESGOS PRINCIPALES (puntos clave)
|
| 96 |
-
3. 3-5 RECOMENDACIONES PRIORITARIAS (acciones concretas)
|
| 97 |
-
4. PRÓXIMOS PASOS (2-3 acciones inmediatas)
|
| 98 |
-
|
| 99 |
-
Máximo 200 palabras. Sé directo y práctico.
|
| 100 |
"""
|
| 101 |
-
|
| 102 |
-
result = ia_generator(
|
| 103 |
-
prompt,
|
| 104 |
-
max_new_tokens=250,
|
| 105 |
-
do_sample=False,
|
| 106 |
-
temperature=0.3
|
| 107 |
-
)[0]["generated_text"]
|
| 108 |
-
|
| 109 |
-
return {"analysis": result.strip()}
|
| 110 |
-
|
| 111 |
-
except Exception as e:
|
| 112 |
-
print(f"Error en generación IA: {e}")
|
| 113 |
-
return {"analysis": "⚠️ El análisis IA no está disponible temporalmente. Contacta al administrador."}
|
| 114 |
|
| 115 |
@app.get("/")
|
| 116 |
async def read_root():
|
| 117 |
-
"""
|
| 118 |
-
|
| 119 |
-
with open("index.html", "r", encoding="utf-8") as f:
|
| 120 |
-
return HTMLResponse(content=f.read())
|
| 121 |
-
except Exception as e:
|
| 122 |
-
return HTMLResponse(content=f"<h1>Error cargando la aplicación: {e}</h1>")
|
| 123 |
-
|
| 124 |
-
@app.get("/health")
|
| 125 |
-
async def health_check():
|
| 126 |
-
"""Endpoint de salud para verificar que la app funciona"""
|
| 127 |
-
return {
|
| 128 |
-
"status": "healthy",
|
| 129 |
-
"ia_available": IA_AVAILABLE,
|
| 130 |
-
"service": "Cibertest Doctor Linux"
|
| 131 |
-
}
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
| 134 |
import uvicorn
|
| 135 |
-
uvicorn.run(app, host="0.0.0.0", port=7860
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
+
from typing import List
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
class DomainScore(BaseModel):
|
| 9 |
name: str
|
|
|
|
| 15 |
|
| 16 |
@app.post("/analyze")
|
| 17 |
async def analyze(data: AnalysisRequest):
|
| 18 |
+
analysis = f"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
🔒 **ANÁLISIS DE CIBERSEGURIDAD - DOCTOR LINUX**
|
| 20 |
|
| 21 |
**PUNTAJE GENERAL:** {data.overall}%
|
| 22 |
|
| 23 |
**RESUMEN:**
|
| 24 |
+
{"✅ Excelente postura de seguridad" if data.overall >= 80 else
|
| 25 |
+
"⚠️ Postura media que requiere mejoras" if data.overall >= 60 else
|
| 26 |
+
"🚨 Postura crítica que necesita atención inmediata"}
|
| 27 |
|
| 28 |
**ÁREAS EVALUADAS:**
|
| 29 |
{chr(10).join([f"• {domain.name}: {domain.score}%" for domain in data.domains])}
|
| 30 |
|
| 31 |
**RECOMENDACIONES PRIORITARIAS:**
|
| 32 |
+
1. Revisar configuración de firewall y reglas
|
| 33 |
2. Implementar estrategia de backups 3-2-1
|
| 34 |
+
3. Establecer sistema de monitoreo 24/7
|
| 35 |
4. Implementar autenticación multifactor
|
| 36 |
+
5. Realizar pruebas de recuperación mensuales
|
| 37 |
|
| 38 |
**PRÓXIMOS PASOS:**
|
| 39 |
• Agenda diagnóstico técnico detallado
|
| 40 |
+
• Desarrolla plan de remediación prioritario
|
| 41 |
+
• Establece métricas de seguimiento continuo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
"""
|
| 43 |
+
return {"analysis": analysis}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
@app.get("/")
|
| 46 |
async def read_root():
|
| 47 |
+
with open("index.html", "r", encoding="utf-8") as f:
|
| 48 |
+
return HTMLResponse(content=f.read())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
import uvicorn
|
| 52 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
CHANGED
|
@@ -1,7 +1,2 @@
|
|
| 1 |
fastapi==0.104.1
|
| 2 |
-
uvicorn==0.24.0
|
| 3 |
-
transformers==4.35.2
|
| 4 |
-
torch==2.1.1
|
| 5 |
-
accelerate==0.24.1
|
| 6 |
-
sentencepiece==0.1.99
|
| 7 |
-
protobuf==3.20.3
|
|
|
|
| 1 |
fastapi==0.104.1
|
| 2 |
+
uvicorn==0.24.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|