Layer 4 ve Layer 7 DDoS Saldırıları: Tespit ve Koruma
TCP/UDP flood, SYN flood, HTTP flood, slowloris ve amplification saldırılarının tespiti, analizi ve korunma yöntemleri hakkında kapsamlı rehber.
İçindekiler
Layer 4 ve Layer 7 DDoS Saldırıları: Tespit ve Koruma
DDoS (Distributed Denial of Service) saldırıları, sunucunuzu veya ağınızı aşırı trafikle boğarak hizmet dışı bırakmayı amaçlar. Bu saldırılar OSI modelinin farklı katmanlarında gerçekleşir. Bu rehberde Layer 4 (Transport) ve Layer 7 (Application) saldırı türlerini, tespit yöntemlerini ve koruma stratejilerini ele alacağız.
REXE altyapısı, Path Panel ile Layer 3/4 saldırılarına karşı ağ seviyesinde koruma sağlar. Layer 7 koruması için Cloudflare WAF veya özel yapılandırmalar kullanılabilir.
OSI Modeli ve DDoS Katmanları
| Katman | İsim | Saldırı Türleri | Hedef |
|---|---|---|---|
| Layer 3 | Network | IP flood, ICMP flood | Ağ bant genişliği |
| Layer 4 | Transport | SYN flood, UDP flood, TCP flood | Bağlantı tablosu |
| Layer 7 | Application | HTTP flood, Slowloris, DNS query | Uygulama kaynakları |
Layer 4 Saldırıları
Layer 4 saldırıları, TCP ve UDP protokollerini hedef alarak sunucunun bağlantı kaynaklarını tüketir.
SYN Flood
TCP üçlü el sıkışma (three-way handshake) sürecini istismar eder. Saldırgan çok sayıda SYN paketi gönderir ancak ACK ile yanıt vermez.
Normal TCP Bağlantı:
İstemci → SYN → Sunucu
İstemci ← SYN-ACK ← Sunucu
İstemci → ACK → Sunucu
✓ Bağlantı kuruldu
SYN Flood:
Saldırgan → SYN → Sunucu
Saldırgan ← SYN-ACK ← Sunucu
Saldırgan → (ACK göndermez)
✗ Yarı açık bağlantı (half-open) birikir
SYN Flood Tespiti
# Yarı açık bağlantıları kontrol et
ss -s
# SYN-RECV durumundaki bağlantı sayısına dikkat edin
# SYN-RECV bağlantılarını listele
ss -tnp state syn-recv
# Bağlantı durumu dağılımı
ss -ant | awk '{print $1}' | sort | uniq -c | sort -rn
# Kaynak IP bazında SYN sayısı
ss -tnp state syn-recv | awk '{print $4}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -20
SYN Flood Koruması
# SYN cookies etkinleştir
sudo sysctl -w net.ipv4.tcp_syncookies=1
# SYN backlog artır
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65536
# SYN-ACK yeniden deneme sayısını azalt
sudo sysctl -w net.ipv4.tcp_synack_retries=2
# Kalıcı hale getir
cat >> /etc/sysctl.conf << 'EOF'
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 65536
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.core.somaxconn = 65536
EOF
sudo sysctl -p
UDP Flood
UDP bağlantısız (connectionless) bir protokol olduğundan, sahte kaynak IP'lerle büyük miktarda UDP paketi gönderilebilir.
# UDP trafiğini izle
sudo tcpdump -i eth0 udp -c 1000 -nn
# UDP paket sayısını kontrol et
sudo iptables -L -v -n | grep udp
# Belirli portlara gelen UDP trafiği
sudo tcpdump -i eth0 'udp and port 53' -c 100 -nn
UDP Flood Koruması
# Gereksiz UDP portlarını kapat
sudo iptables -A INPUT -p udp --dport 19 -j DROP # chargen
sudo iptables -A INPUT -p udp --dport 69 -j DROP # TFTP
sudo iptables -A INPUT -p udp --dport 111 -j DROP # portmap
sudo iptables -A INPUT -p udp --dport 137 -j DROP # NetBIOS
sudo iptables -A INPUT -p udp --dport 161 -j DROP # SNMP
# UDP rate limiting
sudo iptables -A INPUT -p udp -m limit --limit 100/s --limit-burst 200 -j ACCEPT
sudo iptables -A INPUT -p udp -j DROP
TCP Flood (ACK/RST/FIN Flood)
# TCP flag dağılımını izle
sudo tcpdump -i eth0 'tcp[tcpflags] & (tcp-syn|tcp-fin|tcp-rst) != 0' -c 500 -nn
# ACK flood tespiti
sudo tcpdump -i eth0 'tcp[tcpflags] & tcp-ack != 0' -c 1000 -nn | wc -l
Amplification Saldırıları
Saldırgan, küçük bir istek göndererek büyük yanıtlar oluşturur. Kaynak IP olarak kurbanın IP'si kullanılır.
| Protokol | Amplification Faktörü | Port |
|---|---|---|
| DNS | 28-54x | 53 |
| NTP | 556x | 123 |
| Memcached | 51000x | 11211 |
| SSDP | 30x | 1900 |
| CLDAP | 56-70x | 389 |
# NTP amplification kontrolü
sudo tcpdump -i eth0 'udp and port 123' -c 100 -nn
# DNS amplification kontrolü
sudo tcpdump -i eth0 'udp and port 53' -c 100 -nn
# Amplification'a açık servisleri kontrol et
# NTP monlist devre dışı bırak
echo "disable monitor" >> /etc/ntp.conf
sudo systemctl restart ntpd
# Memcached'i sadece localhost'a bağla
echo "-l 127.0.0.1" >> /etc/memcached.conf
sudo systemctl restart memcached
Layer 7 Saldırıları
Layer 7 saldırıları, HTTP/HTTPS protokolünü hedef alarak web sunucusunun uygulama kaynaklarını tüketir. Bu saldırılar meşru trafiğe benzediğinden tespit edilmesi daha zordur.
HTTP Flood
Çok sayıda HTTP GET veya POST isteği göndererek web sunucusunu aşırı yükler.
# HTTP istek sayısını izle (Nginx)
tail -f /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -20
# Saniyedeki istek sayısı
awk '{print $4}' /var/log/nginx/access.log | cut -d: -f1-3 | sort | uniq -c | sort -rn | head -10
# En çok istenen URL'ler
awk '{print $7}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
# Şüpheli User-Agent'lar
awk -F'"' '{print $6}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
HTTP Flood Koruması (Nginx)
# /etc/nginx/conf.d/rate-limit.conf
# Rate limiting zone tanımla
limit_req_zone $binary_remote_addr zone=general:10m rate=10r/s;
limit_req_zone $binary_remote_addr zone=api:10m rate=5r/s;
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
# Bağlantı limiti
limit_conn_zone $binary_remote_addr zone=addr:10m;
server {
# Genel rate limit
limit_req zone=general burst=20 nodelay;
limit_conn addr 50;
# API endpoint'leri için
location /api/ {
limit_req zone=api burst=10 nodelay;
}
# Login sayfası için
location /login {
limit_req zone=login burst=3 nodelay;
}
}
Slowloris
Slowloris, HTTP bağlantılarını mümkün olduğunca uzun süre açık tutarak sunucunun bağlantı havuzunu tüketir.
Slowloris Mekanizması:
1. HTTP isteği başlat (GET / HTTP/1.1)
2. Header'ları çok yavaş gönder
3. Bağlantıyı asla tamamlama
4. Sunucunun tüm bağlantı slotlarını doldur
Slowloris Tespiti
# Uzun süreli bağlantıları kontrol et
ss -tnp | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -20
# ESTABLISHED bağlantı sayısı
ss -ant state established | wc -l
# Belirli IP'den gelen bağlantı sayısı
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -10
Slowloris Koruması (Nginx)
# Nginx yapılandırması
http {
# İstemci zaman aşımları
client_header_timeout 10s;
client_body_timeout 10s;
send_timeout 10s;
keepalive_timeout 15s;
# Maksimum bağlantı sayısı
limit_conn_zone $binary_remote_addr zone=conn:10m;
limit_conn conn 20;
}
# Apache için mod_reqtimeout
sudo a2enmod reqtimeout
# /etc/apache2/mods-enabled/reqtimeout.conf
# RequestReadTimeout header=10-20,MinRate=500 body=10,MinRate=500
Genel Koruma Stratejileri
Kernel Parametreleri Optimizasyonu
# /etc/sysctl.conf - DDoS koruma parametreleri
cat >> /etc/sysctl.conf << 'EOF'
# SYN flood koruması
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 65536
net.ipv4.tcp_synack_retries = 2
# Bağlantı takibi
net.netfilter.nf_conntrack_max = 1000000
net.netfilter.nf_conntrack_tcp_timeout_established = 600
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 30
# Ağ tamponu
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 65536
net.core.somaxconn = 65536
# ICMP flood koruması
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ratelimit = 100
# IP spoofing koruması
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
EOF
sudo sysctl -p
iptables ile DDoS Koruması
#!/bin/bash
# ddos-protection.sh
# Geçersiz paketleri düşür
iptables -A INPUT -m state --state INVALID -j DROP
# Yeni bağlantılar için SYN kontrolü
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
# XMAS paketlerini düşür
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
# NULL paketlerini düşür
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
# SYN flood koruması
iptables -A INPUT -p tcp --syn -m limit --limit 100/s --limit-burst 200 -j ACCEPT
# ICMP rate limiting
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 10/s -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j DROP
# IP başına bağlantı limiti
iptables -A INPUT -p tcp --dport 80 -m connlimit --connlimit-above 50 -j DROP
iptables -A INPUT -p tcp --dport 443 -m connlimit --connlimit-above 50 -j DROP
echo "DDoS koruma kuralları uygulandı."
Fail2Ban ile Otomatik Engelleme
# /etc/fail2ban/jail.local
[nginx-http-auth]
enabled = true
port = http,https
filter = nginx-http-auth
logpath = /var/log/nginx/error.log
maxretry = 5
bantime = 3600
[nginx-botsearch]
enabled = true
port = http,https
filter = nginx-botsearch
logpath = /var/log/nginx/access.log
maxretry = 2
bantime = 86400
[nginx-req-limit]
enabled = true
port = http,https
filter = nginx-limit-req
logpath = /var/log/nginx/error.log
maxretry = 10
bantime = 7200
Saldırı Tespit Araçları
# Gerçek zamanlı trafik izleme
sudo iftop -i eth0
# Paket analizi
sudo tcpdump -i eth0 -c 10000 -w capture.pcap
# Bağlantı istatistikleri
watch -n 1 'ss -s'
# Nginx durum sayfası
# nginx.conf'a ekle:
# location /nginx_status {
# stub_status on;
# allow 127.0.0.1;
# deny all;
# }
curl http://localhost/nginx_status
Sonuç
Layer 4 ve Layer 7 DDoS saldırıları farklı stratejiler gerektirir. Layer 4 saldırıları ağ seviyesinde (Path Panel, iptables) engellenirken, Layer 7 saldırıları uygulama seviyesinde (rate limiting, WAF, Cloudflare) filtrelenir. Çok katmanlı koruma yaklaşımı en etkili savunmayı sağlar.
İlgili Makaleler
Path Panel DDoS Koruma Yönetim Paneli Kullanım Rehberi
REXE Path Panel tam kullanım rehberi: Dashboard, IP'lerim, TR koruma durumu, kural yönetimi, saldırı geçmişi, abuse filtered, şifre değiştirme ve API erişimi.
Oyun Sunucuları İçin DDoS Filtresi Seçim Rehberi
Path.net DDoS koruma sisteminin desteklediği oyun filtreleri: Arma/DayZ, Source Engine, CS:GO, CS2, FiveM, Minecraft, Rust ve daha fazlası için rehber.
Uygulama ve Servisler İçin DDoS Filtresi Rehberi
Path.net DDoS koruma sisteminin desteklediği uygulama filtreleri: OpenVPN, Wireguard, DTLS, RTP, QUIC, SIP, TCP Symmetric ve daha fazlası.