PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Firewall-Skript blockt alles ...



LordDarkmage
18.03.05, 08:04
Hi Leute,

ich habe da ein Problem, was ich mangels Kenntnisse leider nicht alleine lösen kann. Folgendes.
Ich habe einen ded. Server (Debian drauf) im Datacenter laufen. Das Teil hat 3 IPs, die ich mittels virtueller interfaces laufen habe.
eth0 = 217.x.x.20
eth0:0 = 217.x.x.5
eth0:1 = 217.x.x.1

Soweit geht auch alles, doch ich möchte den gerne mittels Filter schützen. Da ich nicht viel Ahnung von iptables habe wollte ich das skript von harry.homelinux.org dafür verwenden. Also flux geholt, geändert und auf den Server geworfen. Dort gestartet sperrt er mir ALLES. Auch das, was ich vorher geöffnet habe. Also den CStrike:Source und Enemy Territory sowie noch SSH, FTP und HTTP. Ich poste jetzt einfach mal das Skript.
#!/bin/bash
# ---------------------------------------------------------------------
# Linux-iptables-Firewallskript, Copyright (c) 2005 under the GPL
# Autogenerated by iptables Generator v1.18 (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:
# meine@e-mail-addy.de on: 2005-3-18 7:38.7 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 -m limit --limit 7200/h -j LOG --log-prefix "REJECT TCP "
iptables -A MY_REJECT -p tcp -j REJECT --reject-with tcp-reset
iptables -A MY_REJECT -p udp -m limit --limit 7200/h -j LOG --log-prefix "REJECT UDP "
iptables -A MY_REJECT -p udp -j REJECT --reject-with icmp-port-unreachable
iptables -A MY_REJECT -p icmp -m limit --limit 7200/h -j LOG --log-prefix "DROP ICMP "
iptables -A MY_REJECT -p icmp -j DROP
iptables -A MY_REJECT -m limit --limit 7200/h -j LOG --log-prefix "REJECT OTHER "
iptables -A MY_REJECT -j REJECT --reject-with icmp-proto-unreachable

# MY_DROP-Chain
iptables -N MY_DROP
iptables -A MY_DROP -m limit --limit 7200/h -j LOG --log-prefix "PORTSCAN DROP "
iptables -A MY_DROP -j DROP

# Alle verworfenen Pakete protokollieren
iptables -A INPUT -m state --state INVALID -m limit --limit 7200/h -j LOG --log-prefix "INPUT INVALID "
iptables -A OUTPUT -m state --state INVALID -m limit --limit 7200/h -j LOG --log-prefix "OUTPUT INVALID "

# 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 - Läuft an eth0
iptables -A INPUT -s 217.x.x.20 -m state --state NEW -p tcp --dport 80 -j ACCEPT

# FTP - Läuft an eth0
iptables -A INPUT -s 217.x.x.20 -m state --state NEW -p tcp --dport 21 -j ACCEPT

# SSH - Läuft an eth0
iptables -A INPUT -s 217.x.x.20 -m state --state NEW -p tcp --dport 22 -j ACCEPT

# Enemy Territory - Läuft an eth0:0
iptables -A INPUT -s 217.x.x.5 -m state --state NEW -p tcp --dport 27960 -j ACCEPT

# HALF-LIFE - Läuft an eth0:1
iptables -A INPUT -s 217.x.x.1 -m state --state NEW -p tcp --dport 6000:6003 -j ACCEPT
iptables -A INPUT -s 217.x.x.1 -m state --state NEW -p tcp --dport 7001:7002 -j ACCEPT
iptables -A INPUT -s 217.x.x.1 -m state --state NEW -p udp --dport 27005 -j ACCEPT
iptables -A INPUT -s 217.x.x.1 -m state --state NEW -p udp --dport 27010 -j ACCEPT
iptables -A INPUT -s 217.x.x.1 -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

Nun probiere ich schon seit guten 2 Stunden rum und les hier ein Howto nach dem anderen. Leider komm ich einfach nicht dahinter wo es hakt.

MfG
LordDarkmage

steve-e
18.03.05, 14:30
Ganz einfach


# SSH - Läuft an eth0
iptables -A INPUT -s 217.x.x.20 -m state --state NEW -p tcp --dport 22 -j ACCEPT

Du hast den Zugriff auf deinen SSH-Server erlaubt, wenn der Anfragende die Source-IP 217.x.x.20 hat. Dies ist jedoch die Destination-IP.

Änder das -s zu einem -d und es sollte gehen.

LordDarkmage
18.03.05, 15:19
Hi! Danke erstmal, dass du mir hilfst.

Ich soll also

iptables -A INPUT -s 217.x.x.20 -m state --state NEW -p tcp --dport 22 -j ACCEPT

umwandeln in

iptables -A INPUT -d 217.x.x.20 -m state --state NEW -p tcp --dport 22 -j ACCEPT Ist das so korrekt? Leider gehts immernoch nicht.

Gruß
LordDarkmage

steve-e
18.03.05, 16:30
Was sagen denn die Logfiles?

'tail -f /var/log/messages'

READY
20.03.05, 15:12
Vermutlich musst du alle '-s' in '-d' umschreiben.