PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : IPTables geschlossene Ports trotzdem erreichbar



sts-laerche
25.07.05, 11:42
Hallo,

ich habe ein Problem mit meiner Firewall auf einem Suse 9.0 Router/Server. Ich habe mir bei Harry ein Script erstellen lassen, das alle Dienste außer SSH blockt. Ein Portscan bei Heise bringt auch genau dieses Ergebnis. Alles geschlossen außer 22. Trotzdem kann ich von außen über die IP und Port 5800 über http-VNC auf die laufende Sitzung zugreifen. Das gleiche geht direkt über VNC und Port 5900. Ein Scan dieser Ports sagt aber, dass sie geschlossen sind.
Eigentlich soll die laufende Sitzung nur vom internen LAN erreichbar sein.
Ein Frage habe ich noch zu den Schnittstellen. Extern habe ich ppp0 ausgewählt, intern eth1 (da hängt das LAN dran). Das DSL Modem hängt an eth0. Eingewählt wird über kinternet und da steht als Schnittstelle dsl0.
Bei ifconfig taucht aber ppp0 auf. Was ist denn nun richtig?

Danke schon mal für die Tips.


Hier ist mein 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).
#
# 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.
# --------------------------------------------------------------------
#
### BEGIN INIT INFO
# Provides: IP-Paketfilter
# Required-Start: $network $local_fs
# Required-Stop: $local_fs
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Short-Description: Harry's IP-Paketfilter
# Description: Harry's IP-Paketfilter provides reasonable
# IP-Security for Home-Computers and small networks
### END INIT INFO
#

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 "
iptables -A FORWARD -m state --state INVALID -m limit --limit 7200/h -j LOG --log-prefix "FORWARD INVALID "

# Korrupte Pakete zurueckweisen
iptables -A INPUT -m state --state INVALID -j DROP
iptables -A OUTPUT -m state --state INVALID -j DROP
iptables -A FORWARD -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
iptables -A FORWARD -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
iptables -A FORWARD -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
iptables -A FORWARD -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
iptables -A FORWARD -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
iptables -A FORWARD -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
iptables -A FORWARD -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
iptables -A FORWARD -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

# Maximum Segment Size (MSS) für das Forwarding an PMTU anpassen
iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

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

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

# ICMP Echo-Request (ping) zulassen und beantworten
iptables -A INPUT -m state --state NEW -p icmp --icmp-type echo-request -j ACCEPT

# LAN-Zugriff auf eth1
iptables -A INPUT -m state --state NEW -i eth1 -j ACCEPT

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

# Forwarding/Routing
echo "Aktiviere IP-Routing"
echo 1 > /proc/sys/net/ipv4/ip_forward 2> /dev/null

# Masquerading
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

# SYN-Cookies
echo 1 > /proc/sys/net/ipv4/tcp_syncookies 2> /dev/null

# Stop Source-Routing
for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/accept_source_route 2> /dev/null; done

# Stop Redirecting
for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/accept_redirects 2> /dev/null; done

# Reverse-Path-Filter
for i in /proc/sys/net/ipv4/conf/*; do echo 2 > $i/rp_filter 2> /dev/null; done

# Log Martians
for i in /proc/sys/net/ipv4/conf/*; do echo 1 > $i/log_martians 2> /dev/null; done

# BOOTP-Relaying ausschalten
for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/bootp_relay 2> /dev/null; done

# Proxy-ARP ausschalten
for i in /proc/sys/net/ipv4/conf/*; do echo 0 > $i/proxy_arp 2> /dev/null; done

# Ungültige ICMP-Antworten ignorieren
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses 2> /dev/null

# ICMP Echo-Broadcasts ignorieren
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts 2> /dev/null

# 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
echo "Deaktiviere IP-Routing"
echo 0 > /proc/sys/net/ipv4/ip_forward

# 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


------------------------------------

ThyMaster
26.07.05, 07:57
Hi,

ist zwar etwas wild geraten, aber:
Hast Du in der Firewall die Einstellung die firewall automatisch für laufende Dienste zu öffnen aktiviert?
Und läuft die Remote Desktop (=vnc) Unterstützung?

Wenn dem so ist, werden m.W. die nötigen Ports auf Anfrage immer geöffnet.

Gruß
Falko

sts-laerche
26.07.05, 15:23
Hi Falko,


Hi,

ist zwar etwas wild geraten, aber:
Hast Du in der Firewall die Einstellung die firewall automatisch für laufende Dienste zu öffnen aktiviert?
Und läuft die Remote Desktop (=vnc) Unterstützung?

Wenn dem so ist, werden m.W. die nötigen Ports auf Anfrage immer geöffnet.

Gruß
Falko

-laufende Dienste:
Ich habe die original Suse Firewall deaktiviert (aus dem Bootprozess entfernt) also werden - zumindest habe ich das so verstanden - alle Einstellungen aus dem oben aufgeführten Script bezogen. Ich weiß nicht, wie ein solcher Eintrag aussieht bzw. aussehen müßte. Aber der Generator hat - soweit ich mich erinnere nicht danach gefragt.

-VNC Unterstützung
Das habe ich bei der Installation mal angegeben, es soll im LAN ja auch zur Verfügung stehen. Aber auch hier dachte ich, dass sich das auf die SuseFirewall bezieht.

Leider weiß ich nicht wo bzw. wie ich die beiden Punkte prüfen kann (außer im obigen Script)
Wenn Du da einen Tip hast...

Gruß

Steffen

twisted.boy
26.07.05, 15:35
poste doch bitte mal ein iptables -L von root ausgeführt.

Gruß

twisted

sts-laerche
30.07.05, 16:47
poste doch bitte mal ein iptables -L von root ausgeführt.

Gruß

twisted

Hat etwas gedauert, aber hier die Ausgabe:

Chain INPUT (policy DROP)
target prot opt source destination
LOG all -- anywhere anywhere state INVALID limit:
avg 2/sec burst 5 LOG level warning prefix `INPUT INVALID '
DROP all -- anywhere anywhere state INVALID
MY_DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RS
T,PSH,ACK,URG/NONE
MY_DROP tcp -- anywhere anywhere tcp flags:FIN,SYN/FI
N,SYN
MY_DROP tcp -- anywhere anywhere tcp flags:SYN,RST/SY
N,RST
MY_DROP tcp -- anywhere anywhere tcp flags:FIN,RST/FI
N,RST
MY_DROP tcp -- anywhere anywhere tcp flags:FIN,ACK/FI
N
MY_DROP tcp -- anywhere anywhere tcp flags:PSH,ACK/PS
H
MY_DROP tcp -- anywhere anywhere tcp flags:ACK,URG/UR
G
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABL
ISHED
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ss
h
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ka
r2ouche
ACCEPT icmp -- anywhere anywhere state NEW icmp echo-
request
ACCEPT all -- anywhere anywhere state NEW
MY_REJECT all -- anywhere anywhere

Chain FORWARD (policy DROP)
target prot opt source destination
LOG all -- anywhere anywhere state INVALID limit:
avg 2/sec burst 5 LOG level warning prefix `FORWARD INVALID '
DROP all -- anywhere anywhere state INVALID
MY_DROP tcp -- anywhere anywhere tcp flags:FIN,SYN,RS
T,PSH,ACK,URG/NONE
MY_DROP tcp -- anywhere anywhere tcp flags:FIN,SYN/FI
N,SYN
MY_DROP tcp -- anywhere anywhere tcp flags:SYN,RST/SY
N,RST
MY_DROP tcp -- anywhere anywhere tcp flags:FIN,RST/FI
N,RST
MY_DROP tcp -- anywhere anywhere tcp flags:FIN,ACK/FI
N
MY_DROP tcp -- anywhere anywhere tcp flags:PSH,ACK/PS
H
MY_DROP tcp -- anywhere anywhere tcp flags:ACK,URG/UR
G
TCPMSS tcp -- anywhere anywhere tcp flags:SYN,RST/SY
N TCPMSS clamp to PMTU
ACCEPT all -- anywhere anywhere state NEW,RELATED,ES
TABLISHED
ACCEPT all -- anywhere anywhere state RELATED,ESTABL
ISHED
MY_REJECT all -- anywhere anywhere

Chain OUTPUT (policy DROP)
target prot opt source destination
LOG all -- anywhere anywhere state INVALID limit:
avg 2/sec burst 5 LOG level warning prefix `OUTPUT INVALID '
DROP all -- anywhere anywhere state INVALID
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state NEW,RELATED,ES
TABLISHED
MY_REJECT all -- anywhere anywhere

Chain MY_DROP (14 references)
target prot opt source destination
LOG all -- anywhere anywhere limit: avg 2/sec burst 5 LOG level warning prefix `PORTSCAN DROP '
DROP all -- anywhere anywhere

Chain MY_REJECT (3 references)
target prot opt source destination
LOG tcp -- anywhere anywhere limit: avg 2/sec burst 5 LOG level warning prefix `REJECT TCP '
REJECT tcp -- anywhere anywhere reject-with tcp-reset
LOG udp -- anywhere anywhere limit: avg 2/sec burst 5 LOG level warning prefix `REJECT UDP '
REJECT udp -- anywhere anywhere reject-with icmp-port-unreachable
LOG icmp -- anywhere anywhere limit: avg 2/sec burst 5 LOG level warning prefix `DROP ICMP '
DROP icmp -- anywhere anywhere
LOG all -- anywhere anywhere limit: avg 2/sec burst 5 LOG level warning prefix `REJECT OTHER '
REJECT all -- anywhere anywhere reject-with icmp-proto-unreachable

--------------------------------

Ich hoffe, es hilft. Danke.
Steffen