This commit introduces detailed documentation for deploying the Intrusion Detection System (IDS) on AlmaLinux 9, including setup scripts, MikroTik router configuration, and update procedures via git. It also includes the syslog parser script for processing router logs and saving them to PostgreSQL. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: b2b01a4a-55da-4f33-9143-6bf0399e0a03 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/c9ITWqD
217 lines
5.6 KiB
Markdown
217 lines
5.6 KiB
Markdown
# 📡 Configurazione Router MikroTik per IDS
|
|
|
|
Questa guida spiega come configurare i router MikroTik per inviare i log al server IDS.
|
|
|
|
## 🎯 Obiettivo
|
|
|
|
Configurare i router MikroTik per:
|
|
1. Generare log delle connessioni di rete (firewall)
|
|
2. Inviare i log tramite Syslog al server AlmaLinux
|
|
3. Popolare automaticamente il database PostgreSQL
|
|
|
|
## 🔧 Configurazione Passo-Passo
|
|
|
|
### Step 1: Connettiti al Router MikroTik
|
|
|
|
Via SSH o Winbox, connettiti al router MikroTik con utente amministratore.
|
|
|
|
### Step 2: Crea Azione Syslog
|
|
|
|
Configura il router per inviare log al server IDS:
|
|
|
|
```mikrotik
|
|
/system logging action
|
|
add name=ids-server target=remote remote=192.168.1.100 remote-port=514
|
|
```
|
|
|
|
**IMPORTANTE**: Sostituisci `192.168.1.100` con l'**IP reale del tuo server AlmaLinux**.
|
|
|
|
### Step 3: Abilita Logging Firewall
|
|
|
|
Configura quali log inviare al server IDS:
|
|
|
|
```mikrotik
|
|
/system logging
|
|
add action=ids-server topics=firewall,info
|
|
add action=ids-server topics=account,info
|
|
add action=ids-server topics=system,error
|
|
```
|
|
|
|
Questo invia:
|
|
- **firewall,info**: Log di connessioni firewall (accept/drop/reject)
|
|
- **account,info**: Log di autenticazione
|
|
- **system,error**: Errori di sistema
|
|
|
|
### Step 4: Abilita Logging Connessioni Firewall
|
|
|
|
Aggiungi regole firewall per loggare le connessioni:
|
|
|
|
```mikrotik
|
|
# Log connessioni accettate (per analisi traffico normale)
|
|
/ip firewall filter
|
|
add chain=forward action=accept log=yes log-prefix="ACCEPT: " comment="Log accepted connections"
|
|
|
|
# Log connessioni droppate (potenziali attacchi)
|
|
add chain=forward action=drop log=yes log-prefix="DROP: " comment="Log dropped connections"
|
|
|
|
# Log connessioni da internet (input chain)
|
|
add chain=input action=accept log=yes log-prefix="INPUT-ACCEPT: " in-interface=ether1 comment="Log input from WAN"
|
|
```
|
|
|
|
**NOTA**: Modifica `ether1` con il nome della tua interfaccia WAN.
|
|
|
|
### Step 5: (Opzionale) Abilita Connection Tracking
|
|
|
|
Per statistiche dettagliate sulle connessioni:
|
|
|
|
```mikrotik
|
|
/ip firewall connection tracking
|
|
set enabled=yes
|
|
|
|
/system logging
|
|
add action=ids-server topics=firewall,connection
|
|
```
|
|
|
|
## 📊 Verifica Configurazione
|
|
|
|
### Sul Router MikroTik
|
|
|
|
Verifica che i log vengano generati:
|
|
|
|
```mikrotik
|
|
/log print where topics~"firewall"
|
|
```
|
|
|
|
Dovresti vedere log delle connessioni.
|
|
|
|
### Sul Server AlmaLinux
|
|
|
|
Verifica ricezione log:
|
|
|
|
```bash
|
|
# Controlla log syslog
|
|
tail -f /var/log/mikrotik/raw.log
|
|
|
|
# Verifica porta 514 in ascolto
|
|
netstat -ulnp | grep 514
|
|
|
|
# Controlla database
|
|
psql -U ids_user -d ids_database -c "SELECT COUNT(*) FROM network_logs;"
|
|
```
|
|
|
|
## 🔍 Esempio Log MikroTik
|
|
|
|
Log firewall tipico che arriva al server:
|
|
|
|
```
|
|
Jan 15 10:30:45 router1 firewall,info: DROP: in:ether1 out:bridge, src-mac 00:11:22:33:44:55, proto TCP, 203.0.113.45:54321->192.168.1.10:80, len 60
|
|
```
|
|
|
|
Questo viene parsato e salvato nel database come:
|
|
|
|
```json
|
|
{
|
|
"timestamp": "2025-01-15 10:30:45",
|
|
"router_name": "router1",
|
|
"source_ip": "203.0.113.45",
|
|
"source_port": 54321,
|
|
"destination_ip": "192.168.1.10",
|
|
"destination_port": 80,
|
|
"protocol": "tcp",
|
|
"packet_length": 60,
|
|
"action": "drop"
|
|
}
|
|
```
|
|
|
|
## ⚙️ Configurazione Avanzata
|
|
|
|
### Filtrare Solo Traffico Esterno
|
|
|
|
Per loggare solo traffico da internet (non LAN):
|
|
|
|
```mikrotik
|
|
/ip firewall filter
|
|
add chain=forward action=accept log=yes log-prefix="WAN-TRAFFIC: " \
|
|
in-interface=ether1 comment="Log only WAN traffic"
|
|
```
|
|
|
|
### Rate Limiting Log
|
|
|
|
Per evitare troppi log e sovraccarico:
|
|
|
|
```mikrotik
|
|
/ip firewall filter
|
|
add chain=forward action=accept log=yes log-prefix="ACCEPT: " \
|
|
limit=100/1s,5:packet comment="Rate limited logging"
|
|
```
|
|
|
|
Questo limita a max 100 log/secondo.
|
|
|
|
## 🚀 Automazione Multi-Router
|
|
|
|
Per configurare automaticamente più router, crea uno script:
|
|
|
|
```bash
|
|
#!/bin/bash
|
|
# configure_all_routers.sh
|
|
|
|
ROUTERS=(
|
|
"192.168.1.1:admin:password"
|
|
"192.168.2.1:admin:password"
|
|
"192.168.3.1:admin:password"
|
|
)
|
|
|
|
IDS_SERVER="192.168.100.50" # IP server AlmaLinux
|
|
|
|
for router in "${ROUTERS[@]}"; do
|
|
IFS=':' read -r ip user pass <<< "$router"
|
|
|
|
echo "Configurando router $ip..."
|
|
|
|
sshpass -p "$pass" ssh "$user@$ip" "/system logging action add name=ids-server target=remote remote=$IDS_SERVER remote-port=514"
|
|
sshpass -p "$pass" ssh "$user@$ip" "/system logging add action=ids-server topics=firewall,info"
|
|
|
|
echo "Router $ip configurato!"
|
|
done
|
|
```
|
|
|
|
## 📝 Note Importanti
|
|
|
|
### Prestazioni
|
|
- Ogni router invia ~100-1000 log/minuto in base al traffico
|
|
- Il server può gestire facilmente 10+ router
|
|
- I log vengono processati in tempo reale dal syslog_parser.py
|
|
|
|
### Sicurezza
|
|
- Syslog usa UDP porta 514 (non criptato)
|
|
- Configura firewall per accettare solo da IP router fidati:
|
|
```bash
|
|
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.0.0/16" port port="514" protocol="udp" accept'
|
|
```
|
|
|
|
### Risoluzione Problemi
|
|
|
|
**Log non arrivano al server:**
|
|
1. Verifica connettività: `ping <IP_SERVER>` dal router
|
|
2. Controlla firewall server: `firewall-cmd --list-all`
|
|
3. Verifica rsyslog: `systemctl status rsyslog`
|
|
|
|
**Database non si popola:**
|
|
1. Verifica syslog_parser in esecuzione: `ps aux | grep syslog_parser`
|
|
2. Controlla log parser: `tail -f /var/log/ids/syslog_parser.log`
|
|
3. Verifica permessi file: `ls -la /var/log/mikrotik/raw.log`
|
|
|
|
## ✅ Checklist Finale
|
|
|
|
- [ ] Server rsyslog configurato e in ascolto su porta 514
|
|
- [ ] Firewall server aperto per UDP 514
|
|
- [ ] Router configurati per inviare log a server IDS
|
|
- [ ] Log visibili in `/var/log/mikrotik/raw.log`
|
|
- [ ] Syslog parser in esecuzione e popola database
|
|
- [ ] Database contiene log: `SELECT COUNT(*) FROM network_logs;`
|
|
- [ ] Sistema ML può addestrare con dati reali
|
|
|
|
---
|
|
|
|
**Prossimo Step**: Dopo 24h di raccolta log, esegui il primo training ML!
|