Configurer la sortie d'alertes Snort : Stocker les données IDS où vous en avez besoin
Snort **ne stocke pas les alertes par défaut**. Vous **devez configurer un plugin de sortie** pour diriger les événements unified2 vers une destination. Le chemin standard :
🔧 Configuration cœur : Plugin de sortie `unified2`
Dans `snort.conf` (ou fichier inclus) :
# Sortie fichier basique (rotation gérée en externe)
output unified2: filename /var/log/snort/alert.u2, limit 128, nostamp
# Ou avec unified2.conf pour config avancée (recommandé)
include $RULE_PATH/unified2.conf
**Exemple `unified2.conf` (fichier + rotation) :**
output unified2: \
filename /var/log/snort/alert.u2, \
limit 128, \
nostamp, \
mpls_event_types, \
vlan_event_types
🎯 Destinations courantes (Config via `unified2` + Outils externes)
| Destination | Outil / Méthode | Notes |
|---|---|---|
| SIEM (Splunk, Elastic, QRadar, Sentinel, Graylog) | Universal Forwarder / Filebeat / Logstash / Fluentd suit `.u2` → parse → indexe | **Meilleur pour entreprise.** Schema-on-read. Enrichissement alertes, corrélation, dashboards. |
| Base de données (MySQL, PostgreSQL, TimescaleDB) | Barnyard2 (legacy) / **Snort 3 `alert_csv` / `alert_sql`** / **Consumer Python/Go custom** | Barnyard2 non maintenu. **Écrivez votre propre consumer** lisant unified2 → SQL. Utilisez connection pooling. |
| Syslog / Rsyslog / Syslog-ng | barnyard2 → syslog / **Consumer custom → syslog()** | Centralisation logs. Format CEF/LEEF pour ingestion SIEM. |
| Fichier (JSON/CSV/Texte) | Snort 3 `alert_json` / `alert_csv` / **Consumer custom → JSON Lines** | Simple, portable. **Rotation avec `logrotate`.** Pas pour gros volume. |
| Elasticsearch / OpenSearch Direct | Filebeat (module: snort) → Elastic / **Logstash codec: unified2** | Indexation native. Dashboards prêts (Elastic SIEM). |
| Base séries temporelles (InfluxDB, TimescaleDB) | Telegraf exec/input → Influx / **Writer custom** | Métriques + alertes. Dashboards Grafana. |
🐍 Consumer Python minimal (Preuve de concept)
#!/usr/bin/env python3
# unified2_to_json.py — tail unified2, émet JSON Lines vers stdout/fichier
import sys, struct, json, socket, datetime
from pathlib import Path
FILE = Path('/var/log/snort/alert.u2')
# Types enregistrements unified2: 2=packet, 7=event, 104=event_v2, 105=packet_v2, 110=extra_data
# Simplifié: parse Event v2 (104) + Packet v2 (105)
# UTILISEZ UNE VRAIE LIB : `pysnort`, `idstools`, `unified2` (PyPI) — NE PARSEZ PAS BRUT EN PROD.
# Exemple avec idstools (pip install idstools)
# from idstools import unified2
# for event in unified2.EventIterator(open(FILE, 'rb')):
# print(json.dumps(event))
✅ Check-list production
- **Utilisez Snort 3** (sortie JSON/CSV native, inspecteurs branchables).
- **Déployez Barnyard2 SEULEMENT si bloqué sur Snort 2.9.x** (EOL 2022).
- **Dimensionnez stockage :** 1Gbps lien → 50–200Go/jour unified2. Planifiez rétention / tiering.
- **Sécurisez transport :** TLS pour Syslog/Beats/Forwarder.
- **Surveillez le pipeline :** File d'attente lettres mortes, alertes lag, alertes disque.
- **Testez règle → alerte → stockage → dashboard** bout en bout.
En résumé : Configurez sortie `unified2` → pipez vers **Filebeat/Logstash/Vector/Fluent Bit** → **Elastic/Splunk/Sentinel**. C'est le chemin moderne, scalable.
