From 80245f32279075451dd93967b2debdbba6790b08 Mon Sep 17 00:00:00 2001 From: Eduardo David Paredes Vara Date: Fri, 5 Dec 2025 00:55:03 +0000 Subject: [PATCH] weekly lynis --- lynis/README.md | 60 +++++++++++++++++++++++++++++++++++++++++++++- lynis/lynis-weekly | 39 ++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100755 lynis/lynis-weekly diff --git a/lynis/README.md b/lynis/README.md index 1bd9e34..6371aca 100644 --- a/lynis/README.md +++ b/lynis/README.md @@ -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 diff --git a/lynis/lynis-weekly b/lynis/lynis-weekly new file mode 100755 index 0000000..bc26866 --- /dev/null +++ b/lynis/lynis-weekly @@ -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