PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : IPTables script gut und sicher? :)



aRved
22.04.05, 11:04
Hallo,
ich hab mir unter http://harry.homelinux.org ein IPTables Script generieren lassen. Jetzt wollt ich nur mal eure Meinung dazu hören, ob das Script so richtig und vorallem auch sicher ist oder ob man einige Dinge besser machen könnt. :)

Meine anderen Dienste wie Teamspeak usw. muss ich natürlich noch hinzufügen.

Hier erstmal das Script:


#!/bin/bash
# ---------------------------------------------------------------------
# Linux-iptables-Firewallskript, Copyright (c) 2005 under the GPL
# Autogenerated by iptables Generator v1.20 (c) 2002-2005 by Harald Bertram
# Please visit http://www.harry.homelinux.org for new versions of
# the iptables Generator (c).
#
# This Script was generated by request from:
# maehl@web.de on: 2005-4-22 11:20.36 MET.
#
# If you have questions about the iptables Generator or about
# your Firewall-Skript feel free to take a look at out website or
# send me an E-Mail to webmaster@harry.homelinux.org.
#
# My special thanks are going to Lutz Heinrich (trinitywork at hotmail dot com)
# who made lots of Beta-Testing and gave me lots of well qualified
# Feedback that made me able to improve the iptables Generator.
# --------------------------------------------------------------------

case "$1" in
start)
echo "Starte IP-Paketfilter"

# iptables-Modul
modprobe ip_tables
# Connection-Tracking-Module
modprobe ip_conntrack
# Das Modul ip_conntrack_irc ist erst bei Kerneln >= 2.4.19 verfuegbar
modprobe ip_conntrack_irc
modprobe ip_conntrack_ftp

# Tabelle flushen
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X

# Default-Policies setzen
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

# MY_REJECT-Chain
iptables -N MY_REJECT

# MY_REJECT fuellen
iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset
iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable
iptables -A MY_REJECT -p icmp -j DROP
iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable

# MY_DROP-Chain
iptables -N MY_DROP
iptables -A MY_DROP -j DROP

# Korrupte Pakete zurueckweisen
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state INVALID -j DROP

# Stealth Scans etc. DROPpen
# Keine Flags gesetzt
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j MY_DROP

# SYN und FIN gesetzt
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j MY_DROP

# SYN und RST gleichzeitig gesetzt
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j MY_DROP

# FIN und RST gleichzeitig gesetzt
iptables -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j MY_DROP

# FIN ohne ACK
iptables -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j MY_DROP

# PSH ohne ACK
iptables -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j MY_DROP

# URG ohne ACK
iptables -A INPUT -p tcp --tcp-flags ACK,URG URG -j MY_DROP

# Loopback-Netzwerk-Kommunikation zulassen
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Connection-Tracking aktivieren
iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# HTTP
iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 80 -j ACCEPT

# SSH
iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 22 -j ACCEPT

# HALF-LIFE
iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 6000:6003 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 7001:7002 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 27005 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 27010 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 27015:27016 -j ACCEPT

# Default-Policies mit REJECT
iptables -A INPUT -j MY_REJECT
iptables -A OUTPUT -j MY_REJECT

# Max. 500/Sekunde (5/Jiffie) senden
echo 5 > /proc/sys/net/ipv4/icmp_ratelimit

# Speicherallozierung und -timing für IP-De/-Fragmentierung
echo 262144 > /proc/sys/net/ipv4/ipfrag_high_thresh
echo 196608 > /proc/sys/net/ipv4/ipfrag_low_thresh
echo 30 > /proc/sys/net/ipv4/ipfrag_time

# TCP-FIN-Timeout zum Schutz vor DoS-Attacken setzen
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout

# Maximal 3 Antworten auf ein TCP-SYN
echo 3 > /proc/sys/net/ipv4/tcp_retries1

# TCP-Pakete maximal 15x wiederholen
echo 15 > /proc/sys/net/ipv4/tcp_retries2

;;

stop)
echo "Stoppe IP-Paketfilter"
# Tabelle flushen
iptables -F
iptables -t nat -F
iptables -t mangle -F
iptables -X
iptables -t nat -X
iptables -t mangle -X
# Default-Policies setzen
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
;;

status)
echo "Tabelle filter"
iptables -L -vn
echo "Tabelle nat"
iptables -t nat -L -vn
echo "Tabelle mangle"
iptables -t mangle -L -vn
;;

*)
echo "Fehlerhafter Aufruf"
echo "Syntax: $0 {start|stop|status}"
exit 1
;;

esac

Achja eine Frage noch, wenn ich zb Teampseak hinzufügen muss, brauch ich doch nur die Freigabe von HTTP oder SSH bearbeiten, is doch richtig so oder?

würde mich über antworten freuen, vielen dank im voraus ..

cane
22.04.05, 11:26
Harrys Script ist sowohl gut als auch sicher wenn Du nur die Serverdienste angibst die Du auch wirklich benötigst!

Zu der Temapesk-Frage hilft www.google.de, ein interessanter treffer mal hier:
http://www.no-cheats.de/modules.php?op=modload&name=FAQ&file=index&myfaq=yes&id_cat=13

mfg
cane

aRved
22.04.05, 11:38
vielen dank erstmal für deine antwort ...
welchen port ich freischalten muss für ts2 weiss ich ja mir ging es nur um die zeile im script :)
Ja natürlich schallt ich da nur die dienste frei die ich auch brauch, würde ja sonst nix bringen xD

würd mich trotzdem über en paar andre meinungen noch freuen :P

cane
22.04.05, 11:54
Wenn der Teamspeak-Server auf dem Rechner mit dem Iptables-Script läuft würde ich unterhalb von:


# HALF-LIFE
iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 6000:6003 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 7001:7002 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 27005 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 27010 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 27015:27016 -j ACCEPT

diese Regel einfügen:


iptables -A INPUT -i eth0 8767 -m state NEW -p udp --dport 8767 ACCEPT

Ob das statefull geht kann ich nicht sagen - probiers mal...


Mehr hier:
http://linuxforen.de/forums/showthread.php?t=70895&highlight=teamspeak+port

mfg
cane

aRved
22.04.05, 11:57
genauso hatte ich das auch vor :)
Was hat das mit dem statefull auf sich?! ..

cane
22.04.05, 12:19
Du kennst google?

http://www.google.de/search?hl=de&q=iptables+stateful&btnG=Suche&meta=lr%3Dlang_de

mfg
cane

aRved
22.04.05, 16:13
So bin jetzt Zuhause und hab das alles mal angepasst, nu bekomm ich aber bei der status abfrage folgende fehlermeldungen:


modprobe: QM_MODULES: Function not implemented

modprobe: QM_MODULES: Function not implemented

modprobe: Can't locate module ip_tables
iptables v1.2.11: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)


bin schon die ganze zeit am googeln, offenbar fehlt da ja en modul oder so.
eventuell hat von euch ja noch einer ne idee?

würde mich freuen, thx im voraus ...

IT-Low
23.04.05, 13:00
bin schon die ganze zeit am googeln, offenbar fehlt da ja en modul oder so.

Was hast du für einen Kernel (uname -r)? Offensichtlicht fehlt dir der iptables/netfilter-Support.

Was sagt: locate ip_tables.ko bzw. locate ip_tables.o ?

Harry
23.04.05, 14:15
modprobe: QM_MODULES: Function not implemented

modprobe: QM_MODULES: Function not implemented

modprobe: Can't locate module ip_tables
iptables v1.2.11: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Kernel selbst kompiliert?

Harry

syn
24.04.05, 12:09
Sind die "module-init-tools" installiert?

carnil
24.04.05, 12:14
Die Fehlermeldung ist sogar ziemlich "typisch"
Sind die "module-init-tools" installiert?
Siehe: http://www.ussg.iu.edu/hypermail/linux/kernel/0308.1/1182.html

MfG carnil