08. Juni 2006
Aus Labor für Echtzeitsysteme
Inhaltsverzeichnis |
Aufgabe
Aufgabe jeder Gruppe war es ein Netzwerk mit verschiedenene Diensten entsprechend der Anforderungen in Firewall.png aufzubauen. Dazu wurden mehrere Kabel und ein Switch pro Gruppe bereitgestellt.
Lösungsweg Gruppe 1 (FireFuckers):
btw.) Firefuckers --> Toller Name :-)
Es wurden zwei Shell-Scripte angefertigt, welche die Firewall-Regeln aufsetzen/zurücksetzt:
1.) firewall_up.sh
#!/bin/bash MODPROBE="/sbin/modprobe" A4=172.16.10.5 A3_0=192.168.50.1 A3_1=172.16.10.1 B3=192.168.50.2 B4=192.168.50.3
# --- Start ---- echo echo "Setting up Firewall......." $MODPROBE ip_tables # Benutze iptables $MODPROBE ip_conntrack # Um einzelne Verbindungen zu zuordnen $MODPROBE iptable_nat # NAT Unterstützdung $MODPROBE ipt_MASQUERADE # MASQUERADE
echo "Modules loaded!" echo echo "Applying rules....." echo
echo "1" > /proc/sys/net/ipv4/ip_forward # Damit Paketweiterleitung zwischen ETH's funzt
# Gehe von restriktiver Firewall aus! Verbiete alles und lasse einzelne Dinge zu iptables -P INPUT DROP iptables -P FORWARD DROP
# -- Damit bestende oder aufgebaute Verbinungen zugelassen werden iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A PREROUTING -t nat -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A POSTROUTING -t nat -m state --state ESTABLISHED,RELATED -j ACCEPT
# -- SSH von A4 auf A3 iptables -A INPUT -s $A4 -d $A3_1 -p TCP --dport 22 -j ACCEPT
# -- ssh A4 auf B3/B4 iptables -A FORWARD -t filter -p TCP -s $A4 -m iprange --src-range $B3-$B4 --dport 22 -j ACCEPT
# -- ssh B3/B4 auf A4 iptables -A FORWARD -t filter -p TCP -m iprange --src-range $B3-$B4 -d $A4 --dport 22 -j ACCEPT
# -- PORT-FORWARDING (DNAT) von extern (alle) auf intern (B3) iptables -A PREROUTING -t nat -p tcp -d $A3_1 --dport 80 -j DNAT --to $B3 iptables -A FORWARD -t filter -d $B3 -p tcp --dport 80 -j ACCEPT
# -- telnet/finger > Mirror ??
# -- Ping Pakete > 32 Byte DROP iptables -A PREROUTING -t nat -p ICMP -m length --length 33: -j DROP
# -- Alle Übrigen Pakete DROP + LOG iptables -A PREROUTING -t nat -j LOG -m limit --limit 5/s --limit-burst 20 iptables -A PREROUTING -t nat -j DROP
exit 0;
2.) firewall_down.sh
- /bin/bash
iptables -F INPUT
iptables -F OUTPUT
iptables -F FORWARD
iptables -t nat -F PREROUTING
iptables -t nat -F POSTROUTING
iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -t nat -P PREROUTING ACCEPT iptables -t nat -P POSTROUTING ACCEPT
exit 0;
Lösungsweg Gruppe 2 (Gruppe ohne Namen):
(!!! Unvollständig !!!)
Konfiguration der beiden B Rechner:
Auf beiden muss A2 als Default-Gateway eingerichtet sein.
Konfiguration des Firewall Rechners:
Netzwerkkonfiguration aus /etc/network/interfaces :
Die Datei entsprechend editieren und mittels ifdown <if>, ifup <if> die Interfaces aktivieren.
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # This is a list of hotpluggable network interfaces. # They will be activated automatically by the hotplug subsystem. mapping hotplug script grep map eth1 # The primary network interface auto eth0 iface eth0 inet static address 172.16.10.1 network 172.16.10.0 netmask 255.255.0.0 broadcast 172.16.10.255 auto eth1 iface eth1 inet static address 192.168.5.3 network 192.168.5.0 netmask 255.255.255.0 broadcast 192.168.5.255
Ausgabe von ifconfig :
eth0 Protokoll:Ethernet Hardware Adresse 00:06:4F:0E:33:94 inet Adresse:172.16.10.1 Bcast:172.16.10.255 Maske:255.255.0.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:1189 errors:0 dropped:0 overruns:0 frame:0 TX packets:950 errors:0 dropped:0 overruns:2 carrier:0 Kollisionen:0 Sendewarteschlangenlänge:1000 RX bytes:117090 (114.3 KiB) TX bytes:213067 (208.0 KiB) Interrupt:11 Basisadresse:0xd400 eth1 Protokoll:Ethernet Hardware Adresse 00:04:76:95:C9:83 inet Adresse:192.168.5.3 Bcast:192.168.5.255 Maske:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1898 errors:0 dropped:0 overruns:0 frame:0 TX packets:1830 errors:0 dropped:0 overruns:0 carrier:0 Kollisionen:0 Sendewarteschlangenlänge:1000 RX bytes:333857 (326.0 KiB) TX bytes:279720 (273.1 KiB) Interrupt:10 Basisadresse:0x2000
Ausgabe von route -n :
Kernel IP Routentabelle Ziel Router Genmask Flags Metric Ref Use Iface 192.168.5.0 * 255.255.255.0 U 0 0 0 eth1 172.16.0.0 * 255.255.0.0 U 0 0 0 eth0
Script zur konfiguration von iptables :
Da das Target MIRROR nicht mehr im aktuellen Kernel verfügbar ist, wäre REJECT eine mögliche Alternative.
#! /bin/sh #Forwarding aktivieren echo 1 > /proc/sys/net/ipv4/ip_forward ############################################################################### #vars iptbin="/sbin/iptables" a1_ip="172.16.10.5" a2_ip="172.16.10.1" b1_ip="192.168.5.1" b2_ip="192.168.5.2" ############################################################################### # Flush all tables ${iptbin} -F ${iptbin} --table nat --flush # Delete the optional user-defined chain specified ${iptbin} --delete-chain # a policy to block all input and forwarding ${iptbin} -P INPUT DROP ${iptbin} -P OUTPUT DROP ${iptbin} -P FORWARD DROP # Create a LOGDROP chain to log and drop packets ${iptbin} -N LOGDROP ${iptbin} -A LOGDROP -j LOG --log-prefix "DROP: " ${iptbin} -A LOGDROP -j DROP ############################################################################### # Allow unlimited traffic on the loopback interface ${iptbin} -A INPUT -i lo -j ACCEPT ${iptbin} -A OUTPUT -o lo -j ACCEPT # Allow unlimited outbound traffic ${iptbin} -A OUTPUT -j ACCEPT ############################################################################### # allow SSH from A1 to A2, B1, B2 ${iptbin} -A INPUT --source $a1_ip -p tcp --dport 22 --destination $a2_ip -j ACCEPT ${iptbin} -A FORWARD --source $a1_ip -p tcp --dport 22 --destination $b1_ip -j ACCEPT ${iptbin} -A FORWARD --source $b1_ip -p tcp --sport 22 --destination $a1_ip -j ACCEPT ${iptbin} -A FORWARD --source $a1_ip -p tcp --dport 22 --destination $b2_ip -j ACCEPT ${iptbin} -A FORWARD --source $b2_ip -p tcp --sport 22 --destination $a1_ip -j ACCEPT # allow SSH from B1 auf A1 ${iptbin} -A FORWARD --source $b1_ip -p tcp --dport 22 --destination $a1_ip -j ACCEPT ${iptbin} -A FORWARD --source $a1_ip -p tcp --sport 22 --destination $b1_ip -j ACCEPT # allow SSH from B2 auf A1 ${iptbin} -A FORWARD --source $b2_ip -p tcp --dport 22 --destination $a1_ip -j ACCEPT ${iptbin} -A FORWARD --source $a1_ip -p tcp --sport 22 --destination $b2_ip -j ACCEPT #http von A1/A2 auf B1 ${iptbin} -A FORWARD --source $a1_ip -p tcp --destination $b1_ip --dport 80 -j ACCEPT ${iptbin} -A FORWARD --source $a2_ip -p tcp --destination $b1_ip --dport 80 -j ACCEPT ${iptbin} -A FORWARD --source $b1_ip -p tcp --destination $a1_ip --sport 80 -j ACCEPT ${iptbin} -A FORWARD --source $b1_ip -p tcp --destination $a2_ip --sport 80 -j ACCEPT #telnet/finger --> Mirror # nur kernel 2.3 und 2.4 #${iptbin} -A. INPUT -p tcp --dport 23 -j MIRROR #${iptbin} -A INPUT -p tcp --dport 79 -j MIRROR #Ping-Pakete > 32 Byte --> Drop ${iptbin} -A INPUT -p icmp --icmp-type 8 -m length --length :32 -j ACCEPT ${iptbin} -A INPUT -p icmp --icmp-type 0 -m length --length :32 -j ACCEPT ${iptbin} -A FORWARD -p icmp --icmp-type 8 -m length --length :32 -j ACCEPT ${iptbin} -A FORWARD -p icmp --icmp-type 0 -m length --length :32 -j ACCEPT ${iptbin} -A OUTPUT -p icmp --icmp-type 8 -m length --length :32 -j ACCEPT ${iptbin} -A OUTPUT -p icmp --icmp-type 0 -m length --length :32 -j ACCEPT ############################################################################### # !!! Letzte Regel !!! # Drop all other traffic ${iptbin} -A INPUT -j LOGDROP ${iptbin} -A OUTPUT -j LOGDROP ${iptbin} -A FORWARD -j LOGDROP
Resultierende Firewall-Regeln :
Chain INPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- lo any anywhere anywhere 0 0 ACCEPT tcp -- any any 172.16.10.5 172.16.10.1 tcp dpt:ssh 0 0 ACCEPT icmp -- any any anywhere anywhere icmp echo-request length 0:32 0 0 ACCEPT icmp -- any any anywhere anywhere icmp echo-reply length 0:32 15 4920 LOGDROP all -- any any anywhere anywhere Chain FORWARD (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT tcp -- any any 172.16.10.5 192.168.5.1 tcp dpt:ssh 0 0 ACCEPT tcp -- any any 192.168.5.1 172.16.10.5 tcp spt:ssh 0 0 ACCEPT tcp -- any any 172.16.10.5 192.168.5.2 tcp dpt:ssh 0 0 ACCEPT tcp -- any any 192.168.5.2 172.16.10.5 tcp spt:ssh 0 0 ACCEPT tcp -- any any 192.168.5.1 172.16.10.5 tcp dpt:ssh 0 0 ACCEPT tcp -- any any 172.16.10.5 192.168.5.1 tcp spt:ssh 0 0 ACCEPT tcp -- any any 192.168.5.2 172.16.10.5 tcp dpt:ssh 0 0 ACCEPT tcp -- any any 172.16.10.5 192.168.5.2 tcp spt:ssh 0 0 ACCEPT tcp -- any any 172.16.10.5 192.168.5.1 tcp dpt:www 0 0 ACCEPT tcp -- any any 172.16.10.1 192.168.5.1 tcp dpt:www 0 0 ACCEPT tcp -- any any 192.168.5.1 172.16.10.5 tcp spt:www 0 0 ACCEPT tcp -- any any 192.168.5.1 172.16.10.1 tcp spt:www 12 361 ACCEPT icmp -- any any anywhere anywhere icmp echo-request length 0:32 12 361 ACCEPT icmp -- any any anywhere anywhere icmp echo-reply length 0:32 9 469 LOGDROP all -- any any anywhere anywhere Chain LOGDROP (3 references) pkts bytes target prot opt in out source destination 24 5389 LOG all -- any any anywhere anywhere LOG level warning prefix `DROP: ' 24 5389 DROP all -- any any anywhere anywhere Chain OUTPUT (policy DROP 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 0 0 ACCEPT all -- any lo anywhere anywhere 185 20648 ACCEPT all -- any any anywhere anywhere 0 0 ACCEPT icmp -- any any anywhere anywhere icmp echo-request length 0:32 0 0 ACCEPT icmp -- any any anywhere anywhere icmp echo-reply length 0:32 0 0 LOGDROP all -- any any anywhere anywhere