Skip to content

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”

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

  • OS : Kali Linux (ou Debian/Ubuntu)
  • RAM : Minimum 2 GB (4 GB recommandé)
  • Espace disque : 500 MB libres
  • Droits : Accès root/sudo
  • Interface réseau active (eth0, wlan0, etc.)
  • Connexion Internet pour les tests
  • Accès au réseau local pour les tests offline
  • Utilisation basique du terminal Linux
  • Compréhension des concepts réseau (TCP/IP, DNS)
  • Notions de sécurité informatique

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.

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.

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.

  • 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
Terminal window
# Mise à jour des paquets
sudo apt update && sudo apt upgrade -y
Terminal window
# Installation depuis les dépôts officiels
sudo apt install suricata -y
# Vérifier l'installation
suricata --version

Sortie attendue :

Suricata version 8.0.1 RELEASE

Étape 3 : Installer les outils nécessaires

Section titled “Étape 3 : Installer les outils nécessaires”
Terminal window
# Outils pour les tests d'attaques
sudo apt install -y hping3 nmap dnsutils wget curl
Terminal window
# Vérifier le statut de Suricata
sudo systemctl status suricata
Terminal window
# Lister les interfaces disponibles
ip link show
# Exemples de sortie :
# eth0 - Ethernet câblé
# wlan0 - WiFi
# ens33 - Interface VMware
Terminal window
# Éditer le fichier de configuration principal
sudo nano /etc/suricata/suricata.yaml

Chercher la section af-packet: et modifier :

# Linux high speed capture support
af-packet:
- interface: wlan0 # ⚠️ REMPLACER par votre interface
cluster-id: 99
cluster-type: cluster_flow
defrag: yes
# 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 :

Terminal window
# Afficher votre IP et réseau
ip addr show | grep inet

📝 Création des Règles Personnalisées

Section titled “📝 Création des Règles Personnalisées”

Suricata lit les règles depuis deux emplacements possibles :

EmplacementUsage
/etc/suricata/rules/Configuration (souvent vide)
/var/lib/suricata/rules/Règles actives (utiliser celui-ci)
/var/lib/suricata/rules
# Vérifier l'emplacement par défaut
grep "default-rule-path" /etc/suricata/suricata.yaml
Terminal window
# Créer le fichier custom.rules
sudo nano /var/lib/suricata/rules/custom.rules
Terminal window
# ============================================
# REGLES PERSONNALISEES - C2 ET DDoS
# Version optimisee et testee
# ============================================
# -------------------------------------------
# PARTIE 1 : DETECTION C2 (Command & Control)
# -------------------------------------------
# 1.1 User-Agent anormaux/suspects
alert 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 volumineuses
alert 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 DNS
alert 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 DNS
alert 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 Flood
alert 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 ouverts
alert 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 Flood
alert 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 Flood
alert 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 Flood
alert 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 Flood
alert 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 Flood
alert 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 Slowloris
alert 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 Amplification
alert 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 Scan
alert 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 Scan
alert 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;)
Terminal window
# Éditer suricata.yaml
sudo nano /etc/suricata/suricata.yaml
# Chercher la section rule-files: et ajouter
rule-files:
- suricata.rules
- custom.rules # ⚠️ AJOUTER cette ligne

Méthode 1 : Via le service systemd (recommandé)

Section titled “Méthode 1 : Via le service systemd (recommandé)”
Terminal window
# Tester la configuration avant de démarrer
sudo suricata -T -c /etc/suricata/suricata.yaml
# Si OK, redémarrer le service
sudo systemctl restart suricata
# Vérifier le statut
sudo systemctl status suricata
# Activer au démarrage (optionnel)
sudo systemctl enable suricata
Terminal window
# Lancer en mode verbeux pour voir les détails
sudo suricata -c /etc/suricata/suricata.yaml -i wlan0 -v
# Arrêter avec Ctrl+C
Terminal window
# Analyser un fichier de capture existant
sudo suricata -r capture.pcap -c /etc/suricata/suricata.yaml

Terminal 1 - Surveillance :

Terminal window
sudo tail -f /var/log/suricata/fast.log | grep CUSTOM

Terminal 2 - Attaque :

Terminal window
# Test curl
curl http://www.google.com
# Test wget
wget -O- http://www.google.com
# Test Python
python3 -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-Agent
Terminal window
# 20 connexions HTTP espacées de 6 secondes
for i in {1..20}; do
curl -s http://www.google.com > /dev/null
echo "Connexion $i"
sleep 6
done

Alerte attendue :

[1:9000011:1] CUSTOM C2 Beaconing - HTTP repetitif
Terminal window
# DNS Query Flood
for i in {1..100}; do
dig @8.8.8.8 google.com +short > /dev/null
done
# DNS ANY Query
for i in {1..10}; do
dig ANY @8.8.8.8 google.com
sleep 2
done
# NXDOMAIN Flood
for i in {1..80}; do
dig @8.8.8.8 "fake$RANDOM.invalid" +short > /dev/null
done

Alertes attendues :

[1:9000022:1] CUSTOM DDoS - DNS Query Flood
[1:9000024:1] CUSTOM DDoS - DNS ANY Query (amplification)
[1:9000026:1] CUSTOM DDoS - NXDOMAIN Flood
Terminal window
# Installation de hping3 si nécessaire
sudo apt install hping3 -y
# Lancer le SYN Flood
sudo hping3 -S -p 80 -c 200 --fast 8.8.8.8

Alerte attendue :

[1:9000030:1] CUSTOM DDoS - SYN Flood detected
Terminal window
# Scan rapide
sudo nmap -sS --top-ports 100 192.168.10.1

Alertes attendues :

[1:9000100:1] CUSTOM SCAN - Port Scan detected
[1:9000101:1] CUSTOM SCAN - SYN Scan
ÉlémentValeur par défautModification suggéréeImpact
Seuil HTTP Beaconing15 req / 120s10 req / 60sPlus sensible
Seuil DNS Flood50 req / 10s100 req / 10sMoins d’alertes
Seuil SYN Flood100 SYN / 10s200 SYN / 10sMoins sensible
User-Agent curlDétection activeDésactiver (commenter)Moins de faux positifs
Ports HTTPS443, 8080, 8443Ajouter 8888, 9443Plus de couverture
Terminal window
# 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;)
Terminal window
# Détecter les connexions SSH suspectes
alert 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;)
Terminal window
# 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

Symptômes :

Failed to start suricata.service
Main process exited, code=exited, status=1/FAILURE

Causes et solutions :

CauseVérificationSolution
Interface incorrecteip link showModifier interface: dans suricata.yaml
Erreur de syntaxesuricata -T -c /etc/suricata/suricata.yamlCorriger les règles
Règles non trouvéesls /var/lib/suricata/rules/Créer custom.rules au bon endroit

Commande de diagnostic :

Terminal window
# Voir les logs d'erreur
sudo journalctl -xeu suricata.service | tail -50
# Tester la configuration
sudo suricata -T -c /etc/suricata/suricata.yaml

Causes possibles :

  1. Règles non chargées
Terminal window
# Vérifier le fichier existe
ls -l /var/lib/suricata/rules/custom.rules
# Vérifier dans la config
grep "custom.rules" /etc/suricata/suricata.yaml
  1. Trafic non capturé
Terminal window
# Vérifier que l'interface capture du trafic
sudo tcpdump -i wlan0 -c 10
  1. Seuils trop élevés
Terminal window
# Réduire les seuils dans les règles
# Par exemple : count 50 → count 10

Problè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 context

Solution :

Terminal window
# ❌ INCORRECT
http_method; content:"POST";
# ✅ CORRECT
content:"POST"; http_method;

L’ordre est important : content doit toujours précéder les modificateurs comme http_method.

Symptômes : Des milliers d’alertes pour du trafic légitime

Solutions :

Terminal window
# 1. Augmenter les seuils
threshold: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étections

Symptômes : CPU à 100%, système lent

Solutions :

Terminal window
# 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
OutilUsageInstallation
Suricata-UpdateMise à jour des règlesInclus avec Suricata
EveBoxVisualisation des alertessudo apt install evebox
SciriusInterface web de gestionGitHub Scirius
MolochCapture et analyse PCAPMoloch Website
Terminal window
# Emerging Threats (gratuit)
sudo suricata-update
# Activer des sources supplémentaires
sudo suricata-update list-sources
sudo suricata-update enable-source et/open
sudo suricata-update


À propos de l'auteur

Riyad ODJOUADEExpert en cybersécurité & infrastructure

Je partage des guides techniques pratiques sur la cybersécurité, l'administration système et le développement web. Tous les contenus sont basés sur des expérimentations réelles.