Configuration Suricata IDS pour la Détection C2 et DDoS
🛡️ Configuration Suricata IDS pour la Détection C2 et DDoS
Section titled “🛡️ Configuration Suricata IDS pour la Détection C2 et DDoS”🎯 Objectif
Section titled “🎯 Objectif”Installer et configurer Suricata IDS/IPS sur Kali Linux pour détecter automatiquement les communications Command & Control (C2) et les attaques DDoS, avec un focus particulier sur l’amplification DNS.
Durée estimée : 45-60 minutes
Niveau : Intermédiaire
Résultat : Un système de détection opérationnel avec 37 règles personnalisées actives
📋 Prérequis
Section titled “📋 Prérequis”Système
Section titled “Système”- OS : Kali Linux (ou Debian/Ubuntu)
- RAM : Minimum 2 GB (4 GB recommandé)
- Espace disque : 500 MB libres
- Droits : Accès root/sudo
Réseau
Section titled “Réseau”- Interface réseau active (eth0, wlan0, etc.)
- Connexion Internet pour les tests
- Accès au réseau local pour les tests offline
Connaissances
Section titled “Connaissances”- Utilisation basique du terminal Linux
- Compréhension des concepts réseau (TCP/IP, DNS)
- Notions de sécurité informatique
📖 Définition et Contexte
Section titled “📖 Définition et Contexte”Qu’est-ce que Suricata ?
Section titled “Qu’est-ce que Suricata ?”Suricata est un moteur de détection d’intrusion (IDS) et de prévention d’intrusion (IPS) open source, haute performance et multi-threadé. Il analyse le trafic réseau en temps réel et détecte les activités suspectes selon des règles définies.
Analogie Simple
Section titled “Analogie Simple”Imaginez Suricata comme un agent de sécurité à l’entrée d’un bâtiment. Il examine chaque personne (paquet réseau) qui entre ou sort, vérifie son badge (signature), observe son comportement (patterns), et déclenche une alarme si quelque chose semble suspect.
Historique
Section titled “Historique”Créé en 2009 par l’Open Information Security Foundation (OISF), Suricata est né du besoin d’un IDS moderne capable de tirer parti des processeurs multi-cœurs, contrairement à son prédécesseur Snort qui utilisait un seul thread.
Utilisations Courantes
Section titled “Utilisations Courantes”- Détection d’intrusions dans les entreprises et data centers
- Analyse forensique du trafic réseau
- Monitoring de sécurité en temps réel
- Détection de malwares communiquant avec des serveurs C2
- Protection contre les DDoS et attaques réseau
🔧 Installation
Section titled “🔧 Installation”Étape 1 : Mettre à jour le système
Section titled “Étape 1 : Mettre à jour le système”# Mise à jour des paquetssudo apt update && sudo apt upgrade -yÉtape 2 : Installer Suricata
Section titled “Étape 2 : Installer Suricata”# Installation depuis les dépôts officielssudo apt install suricata -y
# Vérifier l'installationsuricata --versionSortie attendue :
Suricata version 8.0.1 RELEASEÉtape 3 : Installer les outils nécessaires
Section titled “Étape 3 : Installer les outils nécessaires”# Outils pour les tests d'attaquessudo apt install -y hping3 nmap dnsutils wget curlÉtape 4 : Vérifier le service
Section titled “Étape 4 : Vérifier le service”# Vérifier le statut de Suricatasudo systemctl status suricata⚙️ Configuration Système
Section titled “⚙️ Configuration Système”Identifier votre interface réseau
Section titled “Identifier votre interface réseau”# Lister les interfaces disponiblesip link show
# Exemples de sortie :# eth0 - Ethernet câblé# wlan0 - WiFi# ens33 - Interface VMwareConfigurer l’interface dans Suricata
Section titled “Configurer l’interface dans Suricata”# Éditer le fichier de configuration principalsudo nano /etc/suricata/suricata.yamlChercher la section af-packet: et modifier :
# Linux high speed capture supportaf-packet: - interface: wlan0 # ⚠️ REMPLACER par votre interface cluster-id: 99 cluster-type: cluster_flow defrag: yesConfigurer le réseau local
Section titled “Configurer le réseau local”# Dans le même fichier, section vars:vars: address-groups: HOME_NET: "[192.168.10.0/24]" # ⚠️ AJUSTER à votre réseau EXTERNAL_NET: "!$HOME_NET"Pour trouver votre réseau :
# Afficher votre IP et réseauip addr show | grep inet📝 Création des Règles Personnalisées
Section titled “📝 Création des Règles Personnalisées”Comprendre les emplacements
Section titled “Comprendre les emplacements”Suricata lit les règles depuis deux emplacements possibles :
| Emplacement | Usage |
|---|---|
/etc/suricata/rules/ | Configuration (souvent vide) |
/var/lib/suricata/rules/ | Règles actives (utiliser celui-ci) |
# Vérifier l'emplacement par défautgrep "default-rule-path" /etc/suricata/suricata.yaml
Créer le fichier de règles
Section titled “Créer le fichier de règles”# Créer le fichier custom.rulessudo nano /var/lib/suricata/rules/custom.rulesTemplate des règles complètes
Section titled “Template des règles complètes”# ============================================# REGLES PERSONNALISEES - C2 ET DDoS# Version optimisee et testee# ============================================
# -------------------------------------------# PARTIE 1 : DETECTION C2 (Command & Control)# -------------------------------------------
# 1.1 User-Agent anormaux/suspectsalert http any any -> any any (msg:"CUSTOM C2 - curl User-Agent"; flow:established,to_server; content:"curl"; http_user_agent; nocase; classtype:trojan-activity; sid:9000001; rev:1;)
alert http any any -> any any (msg:"CUSTOM C2 - wget User-Agent"; flow:established,to_server; content:"Wget"; http_user_agent; nocase; classtype:trojan-activity; sid:9000002; rev:1;)
alert http any any -> any any (msg:"CUSTOM C2 - Python User-Agent"; flow:established,to_server; content:"python"; http_user_agent; nocase; classtype:trojan-activity; sid:9000003; rev:1;)
alert http any any -> any any (msg:"CUSTOM C2 - PowerShell User-Agent"; flow:established,to_server; content:"PowerShell"; http_user_agent; nocase; classtype:trojan-activity; sid:9000004; rev:1;)
alert http any any -> any any (msg:"CUSTOM C2 - Suspicious Mozilla/4.0 User-Agent"; flow:established,to_server; content:"Mozilla/4.0"; http_user_agent; classtype:trojan-activity; sid:9000005; rev:1;)
# 1.2 Intervalles reguliers (Beaconing)alert tcp any any -> any any (msg:"CUSTOM C2 Beaconing - Multiple SYN connections"; flags:S; threshold:type both, track by_src, count 20, seconds 60; classtype:trojan-activity; sid:9000010; rev:1;)
alert http any any -> any any (msg:"CUSTOM C2 Beaconing - HTTP repetitif"; flow:established,to_server; threshold:type both, track by_src, count 15, seconds 120; classtype:trojan-activity; sid:9000011; rev:1;)
alert tcp any any -> any [443,8080,8443] (msg:"CUSTOM C2 Beaconing - HTTPS connections repetitives"; flow:to_server; flags:S; threshold:type both, track by_src, count 20, seconds 300; classtype:trojan-activity; sid:9000012; rev:1;)
alert http any any -> any any (msg:"CUSTOM C2 - POST repetitifs (exfiltration)"; flow:established,to_server; content:"POST"; http_method; threshold:type both, track by_src, count 10, seconds 60; classtype:trojan-activity; sid:9000013; rev:1;)
alert http any any -> any any (msg:"CUSTOM C2 - GET repetitifs sur meme URI"; flow:established,to_server; content:"GET"; http_method; threshold:type both, track by_src, count 20, seconds 120; classtype:trojan-activity; sid:9000014; rev:1;)
# -------------------------------------------# PARTIE 2 : DETECTION DDoS - DNS AMPLIFICATION# -------------------------------------------
# 2.1 Amplification DNS - Reponses volumineusesalert udp any 53 -> any any (msg:"CUSTOM DDoS - Large DNS Response (>512 bytes)"; dsize:>512; threshold:type both, track by_dst, count 20, seconds 10; classtype:attempted-dos; sid:9000020; rev:1;)
alert udp any 53 -> any any (msg:"CUSTOM DDoS - Very Large DNS Response (>1024 bytes)"; dsize:>1024; threshold:type both, track by_dst, count 10, seconds 10; classtype:attempted-dos; sid:9000021; rev:1;)
# 2.2 Flood de requetes DNSalert udp any any -> any 53 (msg:"CUSTOM DDoS - DNS Query Flood"; threshold:type both, track by_src, count 50, seconds 10; classtype:attempted-dos; sid:9000022; rev:1;)
alert udp any any -> any 53 (msg:"CUSTOM DDoS - DNS Query Flood Severe"; threshold:type both, track by_src, count 100, seconds 10; classtype:attempted-dos; sid:9000023; rev:1;)
# 2.3 Requetes DNS ANY (amplification)alert udp any any -> any 53 (msg:"CUSTOM DDoS - DNS ANY Query (amplification)"; content:"|00 00 ff 00 01|"; offset:12; depth:5; threshold:type both, track by_src, count 5, seconds 30; classtype:attempted-dos; sid:9000024; rev:1;)
# 2.4 Victime d'amplification DNSalert udp any 53 -> any any (msg:"CUSTOM DDoS - Victime amplification DNS"; threshold:type both, track by_dst, count 100, seconds 30; classtype:attempted-dos; sid:9000025; rev:1;)
# 2.5 NXDOMAIN Floodalert udp any any -> any 53 (msg:"CUSTOM DDoS - NXDOMAIN Flood"; content:"|00 01 00 00 00 00 00|"; offset:4; threshold:type both, track by_src, count 50, seconds 30; classtype:attempted-dos; sid:9000026; rev:1;)
# 2.6 Scan de serveurs DNS ouvertsalert udp any any -> any 53 (msg:"CUSTOM DDoS - Scan DNS ouverts"; threshold:type both, track by_src, count 30, seconds 60; classtype:attempted-recon; sid:9000027; rev:1;)
# -------------------------------------------# PARTIE 3 : DETECTION DDoS - ATTAQUES RESEAU# -------------------------------------------
# 3.1 SYN Floodalert tcp any any -> any any (msg:"CUSTOM DDoS - SYN Flood detected"; flags:S,12; threshold:type both, track by_dst, count 100, seconds 10; classtype:attempted-dos; sid:9000030; rev:1;)
alert tcp any any -> any any (msg:"CUSTOM DDoS - SYN Flood Severe"; flags:S,12; threshold:type both, track by_dst, count 500, seconds 10; classtype:attempted-dos; sid:9000031; rev:1;)
alert tcp any any -> any [80,443] (msg:"CUSTOM DDoS - SYN Flood on Web Services"; flags:S,12; threshold:type both, track by_dst, count 200, seconds 10; classtype:attempted-dos; sid:9000032; rev:1;)
# 3.2 UDP Floodalert udp any any -> any any (msg:"CUSTOM DDoS - UDP Flood detected"; threshold:type both, track by_dst, count 200, seconds 10; classtype:attempted-dos; sid:9000040; rev:1;)
alert udp any any -> any any (msg:"CUSTOM DDoS - UDP Flood Severe"; threshold:type both, track by_dst, count 500, seconds 10; classtype:attempted-dos; sid:9000041; rev:1;)
alert udp any any -> any ![53,123,67,68] (msg:"CUSTOM DDoS - UDP Flood on non-standard ports"; threshold:type both, track by_dst, count 300, seconds 10; classtype:attempted-dos; sid:9000042; rev:1;)
# 3.3 ICMP Flood (Ping Flood)alert icmp any any -> any any (msg:"CUSTOM DDoS - ICMP Flood detected"; threshold:type both, track by_dst, count 100, seconds 10; classtype:attempted-dos; sid:9000050; rev:1;)
alert icmp any any -> any any (msg:"CUSTOM DDoS - ICMP Flood Severe"; threshold:type both, track by_dst, count 300, seconds 10; classtype:attempted-dos; sid:9000051; rev:1;)
alert icmp any any -> any any (msg:"CUSTOM DDoS - Ping of Death (large ICMP)"; dsize:>1024; classtype:attempted-dos; sid:9000052; rev:1;)
alert icmp any any -> any any (msg:"CUSTOM DDoS - ICMP Echo Request Flood"; itype:8; threshold:type both, track by_dst, count 200, seconds 10; classtype:attempted-dos; sid:9000053; rev:1;)
# 3.4 ACK Floodalert tcp any any -> any any (msg:"CUSTOM DDoS - ACK Flood detected"; flags:A; threshold:type both, track by_dst, count 500, seconds 10; classtype:attempted-dos; sid:9000060; rev:1;)
# 3.5 RST Floodalert tcp any any -> any any (msg:"CUSTOM DDoS - RST Flood detected"; flags:R; threshold:type both, track by_dst, count 300, seconds 10; classtype:attempted-dos; sid:9000061; rev:1;)
# 3.6 FIN Floodalert tcp any any -> any any (msg:"CUSTOM DDoS - FIN Flood detected"; flags:F; threshold:type both, track by_dst, count 300, seconds 10; classtype:attempted-dos; sid:9000062; rev:1;)
# -------------------------------------------# PARTIE 4 : DETECTION DDoS - ATTAQUES APPLICATIVES# -------------------------------------------
# 4.1 HTTP Flood (Layer 7)alert http any any -> any any (msg:"CUSTOM DDoS - HTTP GET Flood"; flow:established,to_server; content:"GET"; http_method; threshold:type both, track by_dst, count 100, seconds 10; classtype:attempted-dos; sid:9000070; rev:1;)
alert http any any -> any any (msg:"CUSTOM DDoS - HTTP POST Flood"; flow:established,to_server; content:"POST"; http_method; threshold:type both, track by_dst, count 50, seconds 10; classtype:attempted-dos; sid:9000071; rev:1;)
# 4.2 Slowlorisalert tcp any any -> any [80,443] (msg:"CUSTOM DDoS - Slowloris Attack (multiple slow connections)"; flags:S; threshold:type both, track by_src, count 50, seconds 60; classtype:attempted-dos; sid:9000080; rev:1;)
# 4.3 NTP Amplificationalert udp any 123 -> any any (msg:"CUSTOM DDoS - NTP Amplification Response"; dsize:>468; threshold:type both, track by_dst, count 20, seconds 10; classtype:attempted-dos; sid:9000090; rev:1;)
alert udp any any -> any 123 (msg:"CUSTOM DDoS - NTP Monlist Query"; content:"|17 00 03 2a|"; offset:0; depth:4; classtype:attempted-dos; sid:9000091; rev:1;)
# -------------------------------------------# PARTIE 5 : DETECTION DE SCANS ET RECONNAISSANCE# -------------------------------------------
# 5.1 Port Scanalert tcp any any -> any any (msg:"CUSTOM SCAN - Port Scan detected"; flags:S; threshold:type both, track by_src, count 50, seconds 30; classtype:attempted-recon; sid:9000100; rev:1;)
# 5.2 SYN Scanalert tcp any any -> any any (msg:"CUSTOM SCAN - SYN Scan"; flags:S,12; threshold:type both, track by_src, count 30, seconds 30; classtype:attempted-recon; sid:9000101; rev:1;)Activer les règles dans la configuration
Section titled “Activer les règles dans la configuration”# Éditer suricata.yamlsudo nano /etc/suricata/suricata.yaml
# Chercher la section rule-files: et ajouterrule-files: - suricata.rules - custom.rules # ⚠️ AJOUTER cette ligne🚀 Lancement et Tests
Section titled “🚀 Lancement et Tests”Méthode 1 : Via le service systemd (recommandé)
Section titled “Méthode 1 : Via le service systemd (recommandé)”# Tester la configuration avant de démarrersudo suricata -T -c /etc/suricata/suricata.yaml
# Si OK, redémarrer le servicesudo systemctl restart suricata
# Vérifier le statutsudo systemctl status suricata
# Activer au démarrage (optionnel)sudo systemctl enable suricataMéthode 2 : Mode manuel (debugging)
Section titled “Méthode 2 : Mode manuel (debugging)”# Lancer en mode verbeux pour voir les détailssudo suricata -c /etc/suricata/suricata.yaml -i wlan0 -v
# Arrêter avec Ctrl+CMéthode 3 : Mode capture PCAP
Section titled “Méthode 3 : Mode capture PCAP”# Analyser un fichier de capture existantsudo suricata -r capture.pcap -c /etc/suricata/suricata.yaml🧪 Tests d’Attaques
Section titled “🧪 Tests d’Attaques”Test 1 : C2 User-Agent (2 minutes)
Section titled “Test 1 : C2 User-Agent (2 minutes)”Terminal 1 - Surveillance :
sudo tail -f /var/log/suricata/fast.log | grep CUSTOMTerminal 2 - Attaque :
# Test curlcurl http://www.google.com
# Test wgetwget -O- http://www.google.com
# Test Pythonpython3 -c "import urllib.request; urllib.request.urlopen('http://www.google.com')"Résultat attendu :
[1:9000001:1] CUSTOM C2 - curl User-Agent[1:9000002:1] CUSTOM C2 - wget User-Agent[1:9000003:1] CUSTOM C2 - Python User-AgentTest 2 : Beaconing (5 minutes)
Section titled “Test 2 : Beaconing (5 minutes)”# 20 connexions HTTP espacées de 6 secondesfor i in {1..20}; do curl -s http://www.google.com > /dev/null echo "Connexion $i" sleep 6doneAlerte attendue :
[1:9000011:1] CUSTOM C2 Beaconing - HTTP repetitifTest 3 : DNS Amplification (1 minute)
Section titled “Test 3 : DNS Amplification (1 minute)”# DNS Query Floodfor i in {1..100}; do dig @8.8.8.8 google.com +short > /dev/nulldone
# DNS ANY Queryfor i in {1..10}; do dig ANY @8.8.8.8 google.com sleep 2done
# NXDOMAIN Floodfor i in {1..80}; do dig @8.8.8.8 "fake$RANDOM.invalid" +short > /dev/nulldoneAlertes attendues :
[1:9000022:1] CUSTOM DDoS - DNS Query Flood[1:9000024:1] CUSTOM DDoS - DNS ANY Query (amplification)[1:9000026:1] CUSTOM DDoS - NXDOMAIN FloodTest 4 : SYN Flood (30 secondes)
Section titled “Test 4 : SYN Flood (30 secondes)”# Installation de hping3 si nécessairesudo apt install hping3 -y
# Lancer le SYN Floodsudo hping3 -S -p 80 -c 200 --fast 8.8.8.8Alerte attendue :
[1:9000030:1] CUSTOM DDoS - SYN Flood detectedTest 5 : Port Scan (1 minute)
Section titled “Test 5 : Port Scan (1 minute)”# Scan rapidesudo nmap -sS --top-ports 100 192.168.10.1Alertes attendues :
[1:9000100:1] CUSTOM SCAN - Port Scan detected[1:9000101:1] CUSTOM SCAN - SYN Scan🎨 Personnalisation des Règles
Section titled “🎨 Personnalisation des Règles”Tableau des modifications courantes
Section titled “Tableau des modifications courantes”| Élément | Valeur par défaut | Modification suggérée | Impact |
|---|---|---|---|
| Seuil HTTP Beaconing | 15 req / 120s | 10 req / 60s | Plus sensible |
| Seuil DNS Flood | 50 req / 10s | 100 req / 10s | Moins d’alertes |
| Seuil SYN Flood | 100 SYN / 10s | 200 SYN / 10s | Moins sensible |
| User-Agent curl | Détection active | Désactiver (commenter) | Moins de faux positifs |
| Ports HTTPS | 443, 8080, 8443 | Ajouter 8888, 9443 | Plus de couverture |
Exemple : Ajuster les seuils
Section titled “Exemple : Ajuster les seuils”# Rendre la détection DNS plus stricte# Ancien : count 50, seconds 10# Nouveau : count 30, seconds 10
alert udp any any -> any 53 (msg:"CUSTOM DDoS - DNS Query Flood"; threshold:type both, track by_src, count 30, seconds 10; classtype:attempted-dos; sid:9000022; rev:2;)Exemple : Ajouter une nouvelle règle
Section titled “Exemple : Ajouter une nouvelle règle”# Détecter les connexions SSH suspectesalert tcp any any -> any 22 (msg:"CUSTOM SCAN - SSH Brute Force Attempt"; flags:S; threshold:type both, track by_src, count 10, seconds 60; classtype:attempted-admin; sid:9000200; rev:1;)Désactiver temporairement une règle
Section titled “Désactiver temporairement une règle”# Méthode 1 : Commenter la ligne# alert http any any -> any any (msg:"CUSTOM C2 - curl User-Agent"; ...)
# Méthode 2 : Désactiver via configuration# Dans suricata.yaml, section rule-files:# Retirer custom.rules temporairement❌ Problèmes Courants
Section titled “❌ Problèmes Courants”Problème 1 : Service ne démarre pas
Section titled “Problème 1 : Service ne démarre pas”Symptômes :
Failed to start suricata.serviceMain process exited, code=exited, status=1/FAILURECauses et solutions :
| Cause | Vérification | Solution |
|---|---|---|
| Interface incorrecte | ip link show | Modifier interface: dans suricata.yaml |
| Erreur de syntaxe | suricata -T -c /etc/suricata/suricata.yaml | Corriger les règles |
| Règles non trouvées | ls /var/lib/suricata/rules/ | Créer custom.rules au bon endroit |
Commande de diagnostic :
# Voir les logs d'erreursudo journalctl -xeu suricata.service | tail -50
# Tester la configurationsudo suricata -T -c /etc/suricata/suricata.yamlProblème 2 : Aucune alerte générée
Section titled “Problème 2 : Aucune alerte générée”Causes possibles :
- Règles non chargées
# Vérifier le fichier existels -l /var/lib/suricata/rules/custom.rules
# Vérifier dans la configgrep "custom.rules" /etc/suricata/suricata.yaml- Trafic non capturé
# Vérifier que l'interface capture du traficsudo tcpdump -i wlan0 -c 10- Seuils trop élevés
# Réduire les seuils dans les règles# Par exemple : count 50 → count 10Problème 3 : Erreur “http_method before content”
Section titled “Problème 3 : Erreur “http_method before content””Message d’erreur :
"http_method" keyword found inside the rule without a content contextSolution :
# ❌ INCORRECThttp_method; content:"POST";
# ✅ CORRECTcontent:"POST"; http_method;L’ordre est important : content doit toujours précéder les modificateurs comme http_method.
Problème 4 : Trop de faux positifs
Section titled “Problème 4 : Trop de faux positifs”Symptômes : Des milliers d’alertes pour du trafic légitime
Solutions :
# 1. Augmenter les seuilsthreshold:type both, track by_src, count 100, seconds 10 # Au lieu de count 10
# 2. Exclure des IPs de confiance# Dans suricata.yaml :pass ip 192.168.10.100 any -> any any (msg:"Trusted Host"; sid:1;)
# 3. Affiner les règles# Ajouter des conditions supplémentaires pour réduire les détectionsProblème 5 : Performance dégradée
Section titled “Problème 5 : Performance dégradée”Symptômes : CPU à 100%, système lent
Solutions :
# 1. Limiter les threads# Dans suricata.yaml :threading: set-cpu-affinity: no cpu-affinity: - management-cpu-set: cpu: [ 0 ] - receive-cpu-set: cpu: [ 0-1 ]
# 2. Désactiver les règles non critiques# Commenter les règles de scan si non nécessaires
# 3. Réduire la verbosité des logs# Dans suricata.yaml :outputs: - fast: enabled: yes filename: fast.log append: no # Éviter les fichiers trop gros📚 Ressources
Section titled “📚 Ressources”Documentation Officielle
Section titled “Documentation Officielle”Outils Complémentaires
Section titled “Outils Complémentaires”| Outil | Usage | Installation |
|---|---|---|
| Suricata-Update | Mise à jour des règles | Inclus avec Suricata |
| EveBox | Visualisation des alertes | sudo apt install evebox |
| Scirius | Interface web de gestion | GitHub Scirius |
| Moloch | Capture et analyse PCAP | Moloch Website |
Bases de règles publiques
Section titled “Bases de règles publiques”# Emerging Threats (gratuit)sudo suricata-update
# Activer des sources supplémentairessudo suricata-update list-sourcessudo suricata-update enable-source et/opensudo suricata-update