weekly lynis

This commit is contained in:
Eduardo David Paredes Vara
2025-12-05 00:55:03 +00:00
parent a651474dac
commit 80245f3227
2 changed files with 98 additions and 1 deletions

View File

@@ -148,7 +148,65 @@ lynis/
├── templates/
│ └── report.html.j2 # Plantilla HTML del reporte
├── venv/ # Entorno virtual (opcional)
└── README.md # Este archivo
└── # Lynis Security Report Generator
Generador automático de informes de seguridad Lynis con formato HTML/PDF y envío por correo electrónico.
## Instalación
1. Instalar dependencias del sistema:
```bash
sudo apt install lynis wkhtmltopdf
```
2. Instalar dependencias de Python:
```bash
pip install -r requirements.txt
```
## Configuración
Edita `config.py` con tus parámetros:
- Servidor SMTP y credenciales
- Direcciones de correo
- Directorio de salida
- Comando de Lynis
## Ejecución Manual
```bash
python3 lynis_report.py
```
## Instalación del Cron Semanal
Para ejecutar automáticamente cada semana:
```bash
sudo cp lynis-weekly /etc/cron.weekly/
sudo chmod +x /etc/cron.weekly/lynis-weekly
```
El script se ejecutará automáticamente cada semana y guardará logs en `/var/log/lynis-report.log`.
### Verificar la configuración del cron
```bash
# Ver logs de ejecución
sudo tail -f /var/log/lynis-report.log
# Probar ejecución manual del cron
sudo /etc/cron.weekly/lynis-weekly
```
## Características
- Ejecuta Lynis y genera informes en formato TXT, HTML y PDF
- Envía informes por correo electrónico con los archivos adjuntos
- Parsing de métricas clave (Hardening Index, warnings, suggestions)
- Formato HTML con estilos CSS modernos
- Limpieza automática de archivos temporales
- Ejecución semanal automática vía cron # Este archivo
```
## 📊 Archivos Temporales

39
lynis/lynis-weekly Executable file
View File

@@ -0,0 +1,39 @@
#!/bin/bash
#
# Lynis Security Report - Weekly Cron Job
# Place this file in /etc/cron.weekly/
# Make it executable: chmod +x /etc/cron.weekly/lynis-weekly
#
# Script directory
SCRIPT_DIR="/opt/lynis-report"
# Python virtual environment
VENV_DIR="$SCRIPT_DIR/venv"
# Log file
LOG_FILE="/var/log/lynis-report.log"
# Change to script directory
cd "$SCRIPT_DIR" || {
echo "$(date): ERROR - Cannot change to directory $SCRIPT_DIR" >> "$LOG_FILE"
exit 1
}
# Log execution start
echo "$(date): Starting Lynis weekly report" >> "$LOG_FILE"
# Activate virtual environment and run the script
if [ -d "$VENV_DIR" ]; then
"$VENV_DIR/bin/python3" "$SCRIPT_DIR/lynis_report.py" >> "$LOG_FILE" 2>&1
else
# Fallback to system python3 if venv doesn't exist
python3 "$SCRIPT_DIR/lynis_report.py" >> "$LOG_FILE" 2>&1
fi
# Log execution result
if [ $? -eq 0 ]; then
echo "$(date): Lynis weekly report completed successfully" >> "$LOG_FILE"
else
echo "$(date): ERROR - Lynis weekly report failed with exit code $?" >> "$LOG_FILE"
fi