We had a task to build a simple solution for DDOS protection on the learning phase of attack. Main goals were:
- To build it fast: We chose Ubuntu … as everything needed is compiled and build in.
- Minimum network intervention: We opted for L2/L3 bridge with iptables integration which we plugged between our autonomous system (AS) and internet.
- Auto learning offenders: Using honeypot service to distinguish non-legitimate connections. Log source IP address and drop packet with iptables. Using suricata ids to additionally analyze client requests.
- Auto block offenders: Using fail2ban to pars logs generated by iptables and suricata and temporary disable all connections from offending sources.
- Have some connection limit capabilities: Again we used iptables with connlimit and conntrack modules activated.
Configure steps:
- Install software:
12345apt-get install mc iptraf iftop ssh bridge-utils vlanadd-apt-repository ppa:oisf/suricata-stableapt-get updateapt-get install suricataapt-get install fail2ban - Configure network interfaces
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748# The loopback network interfaceauto loiface lo inet loopbackauto enp26s0iface enp26s0 inet staticaddress 10.10.18.37netmask 255.255.255.248post-up route add -net 10.10.18.0 netmask 255.255.248.0 gw 10.10.18.34 metric 100post-up route add -net 10.10.0.0 netmask 255.0.0.0 gw 10.10.10.33 metric 200auto ens1f0 ens1f0.217 ens1f0.218 ens1f0.409iface ens1f0.217 inet manualvlan-raw-device ens1f0iface ens1f0.218 inet manualvlan-raw-device ens1f0iface ens1f0.409 inet manualvlan-raw-device ens1f0auto ens1f1 ens1f1.217 ens1f1.218 ens1f1.409iface ens1f1.217 inet manualvlan-raw-device ens1f1iface ens1f1.218 inet manualvlan-raw-device ens1f1iface ens1f1.409 inet manualvlan-raw-device ens1f1auto br217iface br217 inet manualbridge_ports ens1f0.217 ens1f1.217bridge_stp offbridge_fd 0bridge_maxwait 0auto br218iface br218 inet manualbridge_ports ens1f0.218 ens1f1.218bridge_stp offbridge_fd 0bridge_maxwait 0auto br409iface br409 inet manualbridge_ports ens1f0.409 ens1f1.409bridge_stp offbridge_fd 0bridge_maxwait
Here we have 3 bridges in 3 different vlans connecting our AS to 3 upstream internet providers and one management interface. - Design iptables structure:
1234567891011121314151617181920# Chain for all incoming packetsiptables -N IN# Chainf for Fail2ban checksiptables -N F2B# Chain for connection limit and connection tracking rulesiptables -N IN-CONN-LIMIT# Chain for implicitly drop rulesiptables -N IN-HARD-DROP# Chain that Logs and dropsiptables -N LD# Chain for Cloudflare as source checkiptables -N ONLY_FROM_CLOUDFLARE# Chain for outgoing pachagesiptables -N IN OUT
then add rules to direct packets:
1234567891011121314# Incomingiptables -A FORWARD -m physdev --physdev-in ens1f0.217 -j INiptables -A FORWARD -m physdev --physdev-in ens1f0.218 -j INiptables -A FORWARD -m physdev --physdev-in ens1f0.409 -j IN#Outgoingiptables -A FORWARD -m physdev --physdev-in ens1f1.217 -j OUTiptables -A FORWARD -m physdev --physdev-in ens1f1.218 -j OUTiptables -A FORWARD -m physdev --physdev-in ens1f1.409 -j OUT#Fail2Ban rulesiptables -A F2B -p tcp -m multiport --dports 0:65535 -j f2b-ipt-drop#Connlimitiptables -A IN -j IN-CONN-LIMIT#Dropiptables -A IN -j IN-HARD-DROP
conn&track limit:
12iptables -A IN-CONN-LIMIT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -m limit --limit 6/sec --limit-burst 12 -j RETURNiptables -A IN-CONN-LIMIT -m connlimit --connlimit-upto 16 --connlimit-mask 32 --connlimit-saddr -j RETURN
drop invalid packets:
1iptables -A IN-HARD-DROP -m state --state INVALID -j LD
honeypot NTP and SSH:
12iptables -A IN-HARD-DROP -p udp -m udp --dport 123 -j LDiptables -A IN-HARD-DROP -p tcp -m tcp --dport 22 -j LD
and finally log and drop:
12iptables -A LD -m limit --limit 2/min --limit-burst 1 -j LOG --log-prefix "IPtables_DROP:"iptables -A LD -j DROP
optionally filter for cloudflare networks
12345678910111213141516171819iptables -A ONLY_FROM_CLOUDFLARE -s 103.21.244.0/22 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 103.22.200.0/22 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 103.31.4.0/22 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 104.16.0.0/12 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 108.162.192.0/18 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 131.0.72.0/22 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 141.101.64.0/18 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 162.158.0.0/15 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 172.64.0.0/13 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 173.245.48.0/20 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 188.114.96.0/20 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 190.93.240.0/20 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 197.234.240.0/22 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 198.41.128.0/17 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -s 199.27.128.0/21 -j RETURNiptables -A ONLY_FROM_CLOUDFLARE -j LD## Add protected destanation as following rule:#iptables -A IN -d 212.xxx.yyy.zzz/32 -j ONLY_FROM_CLOUDFLARE - Configure fail2ban
12345678[ipt-drop]enabled = truechain = F2Bblocktype = DROP#protocol = allfilter = ipt-droplogpath = /var/log/syslogmaxretry = 2
12protocol = tcpblocktype = DROP
12[Definition]failregex = .*IPtables_DROP.*SRC=(?P<host>\S*)
Similar readings:
Fighting SPAM with postfix and fail2ban
One thought on “Adaptive DDOS IDS firewall”