PF macht Netzwerk-Dienste langsam

f0x

Punk
Hi,
ich hab vergangene Woche meinen Homeserver neu aufgesetzt und mal OpenBSD 4.6 draufgepackt.
Nachdem ich heute eine pf.conf erstellt hatte, viel mir auf, dass nach Aktivierung dieser, alle Netzwerk-Dienste extrem langsam laufen oder garnicht mehr funktionieren.

Das wirkt sich zum Beispiel bei SSH aus, indem nach eingabe des Login-Namens es 1 bis 2 Minuten dauert bis der Passwort Promt erscheint (nach korrekter Eingabe des Passworts funktioniert innerhalb des SSH Terminals alles flüssig).

FTP zum beispiel baut eine Verbindung auf und reagiert dann garnicht mehr. Die Verbindung ist allerdings noch aktiv...

Woran kann das liegen??? Ich find den Fehler nicht, oder stell mich zu blöde an...

Hier die pf.conf
Code:
# Firewall Configuration by f0X 03/04/2010

# Makros
int_if="rl0"
ext_if="rl1"

# tables
table <ssh-bruteforce> persist file "/etc/1.ssh-bruteforce.block.conf"

table <registered> { 192.168.20.1, 192.168.20.2, 192.168.20.51, 192.168.20.9, 192.168.20.11, 192.168.20.12, 192.168.20.13, 192.168.20.14, 192.168.20.101, 192.168.20.98 }

table <banned> persist file "/etc/1.banned.block.conf"

# Options
set block-policy drop

set loginterface $ext_if
set skip on lo0

# NAT


# filters
block in all

antispoof quick for { $ext_if $int_if }

######## blocks ########
# block banned ip's
block drop in log (all) quick on $ext_if from <banned> to any

# block bad ssh requests (anti brute-force)
block drop in log quick from <ssh-bruteforce> to any

# block ping
block drop in log quick on $ext_if inet proto icmp from any to any

######## passes ########
# allow icmp from internal network
pass in on $int_if inet proto icmp all icmp-type echoreq keep state

# ssh port
pass in log quick proto tcp from any to any port 46255 \
flags S/SA keep state \
 (max-src-conn-rate 3/30, overload <ssh-bruteforce> flush global)


######## int ########
# ftp
pass in quick on $int_if inet proto tcp \
to any port 21 \
flags S/SA keep state

# http_int
pass in quick on $int_if inet proto tcp \
to any port 80 \
flags S/SA keep state

# http_main
pass in quick on $int_if inet proto tcp \
to any port 81 \
flags S/SA keep state

# samba
pass in quick on $int_if inet proto tcp \
to any port 139 \
flags S/SA keep state

# http_second
pass in quick on $int_if inet proto tcp \
to any port 46123 \
flags S/SA keep state


######## ext ########
# ftp
pass in log on $ext_if inet proto tcp \
from <registered> to ($ext_if) port 21 \
flags S/SA modulate state

# samba
pass in log on $ext_if inet proto tcp \
from <registered> to ($ext_if) port 139 \
flags S/SA modulate state

# http_main
pass in log on $ext_if inet proto tcp \
to any port 80 \
keep state

# http_second
pass in log on $ext_if inet proto tcp \
to any port 46123 \
keep state
Lg
f0x :)
 
Alles ICMP zu blockieren ist eine schlechte Idee. Für FTP solltest du ftp-proxy verwenden (wie im pf-FAQ beschrieben).
 
Guten Morgen f0x,

kann es sein dass du in /etc/resolv.conf einen DNS-Server eingetragen hast, der nicht zu erreichen ist?
Bei mir dauert nämlich das Login auf meinen Maschinen immer extrem lange, wenn der DNS-Server ausfällt.
 
:mad: Ok, folgendes:
Sobald ich pf starte bekomme ich keine Route ins Internet mehr! :confused::confused::confused:

ping, nslookup, alles ohne Ergebnis. Hab eure Ratschläge befolgt, ICMP wird vorerst nicht mehr geblockt, S/SA wurd zu S/SAFR geändert. Bei der Überprüfung der resolv.conf viel mir auf das statt der beiden ursprünglich von mir angegebenen OpenDNS Server IP's die meines Routers stand - vorerst nicht verwunderlich da der Server im Moment seine Addresse per DHCP bezieht, trotzdem hab ich es mal überprüft wobei mir auffiel dass ich keine connection zum Internet mehr hab sobald ich pf starte...
Ich hab jetzt vorerst noch ein "match on rl1 scrub (max-mss 1440)" eingebaut, hat aber auch nix verändert...

EDIT: @waki87, warum sollte ich einen FTP-Proxy verwenden? Ging bisher auch ohne immer einwandfrei!
 
Du hast bisher ja auch gar keine NAT-Regel, hab ich gesehen. So wird das natürlich nix. ;) ftp-proxy deshalb, weil bei (aktivem) FTP der Server eine Rückverbindung zum Client aufbaut. ftp-proxy ist in der Lage, sich das zu merken und lädt dementsprechend Redirect-, NAT- und Pass-Regeln über anchors dynamisch nach. Übrigens mußt du auch für passives FTP ausgehende Verbindungen zu Port 20 (ftp-data) erlauben.
 
hi

ich stelle mir gerade die frage warum das team von openbsd eine so gute documentation pflegt wenn sie doch keiner liest.

alle problem / themen hier im thread sind gross und breit in der FAQ ( abteilung
pf ) erklaert , und das sogar in deutsch .



holger
 
Ich bin kein idiot und ich hab die scheiß faq gelesen!
Trotz des Wissens werden die Netzwerkdienste weiterhin verlangsamt und es gibt keinen kontakt mehr zum Internet sobald ich die PF starte ;)
Selbst wenn ich eine Default PF nehme!
Also kommt mir nicht mit der faq, wenn die geholfen hätt würd ich wohl kaum hier posten!
Und den FTP Proxy hab ich nie benutzt weil's vorher auch ohne ging!
 
Ich bin kein idiot und ich hab die scheiß faq gelesen!
Trotz des Wissens werden die Netzwerkdienste weiterhin verlangsamt und es gibt keinen kontakt mehr zum Internet sobald ich die PF starte ;)
Selbst wenn ich eine Default PF nehme!
Also kommt mir nicht mit der faq, wenn die geholfen hätt würd ich wohl kaum hier posten!
Und den FTP Proxy hab ich nie benutzt weil's vorher auch ohne ging!

Guten Morgen f0x,

Don't Panic.

Versuchs mal hiermit, Du musst Deine lokalen IP Range noch anpassen.

Code:
# 
# $Id: pf.conf,v 1.6 2007/12/14 21:48:59 root Exp $
# 
### VARIABLEN ###
# 
# reload 
# /sbin/pfctl -e -F all -f /etc/pf.conf
# 

Ext = "rl1"            # Device an dem das Internet angeschlossen ist 
Int = "rl0"            # Device an dem das interne Netz haengt
IntNet = "xx.xx.1.0/24"      # Adressraum des internen Netzes <-- Anpassen
RouterIP = "xx.xx.1.1"       # IP Adresse des Routers <-- Anpassen
Loop = "lo0"                   # Loopback Device

# Adressen die auf dem externen Device nicht geroutet werden
# (Adressbereich des internen Netzes muss man wegen der Weiterleitungen zulassen)
table <NoRoute> { 127.0.0.1/8, 172.16.0.0/12, 192.168.0.0/16, !$IntNet, 10.0.0.0/8, 255.255.255.255/32 }

# Ports die geoeffnet werden sollen
### InServicesTCP = "{ ssh, ftp, auth }"

### OPTIONS ###

# Macht Statistiken fuer die Verbindung (pfctl -s info) hier ein Kabel Internet Anschluss
set loginterface $Ext

# Beendet inaktive Verbindungen schneller - geringerer Speicherverbrauch.
set optimization aggressive

# Fragmentierte Pakete saeubern
scrub on $Ext all fragment reassemble random-id


### NAT & FORWARD ###

# NAT aktivieren (unter Linux als Masquerading bekannt)
nat on $Ext from $IntNet to any -> $Ext static-port
nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"
rdr pass on $Int proto tcp from $IntNet to any port 21 -> 127.0.0.1 port 8021



### FILTER ###

# Zum Debuggen....
# pass quick all             # Alles durchlassen

# Generelle Block Regel
block in on $Ext all
block out on $Ext all

# Freiwillig machen wir keinen mucks ;)
# drop statt return (macht die ports nach aussen Stealth
block drop log on $Ext

# Wir wollennnoch kein IPv6.0
block quick inet6

# Loopback Device darf alles
pass quick on $Loop

# IP Spoofing verhindern
block in log quick on $Ext inet from <NoRoute> to any
block in log quick on $Ext inet from any to <NoRoute>

# Active FTP erlauben
pass in quick on $Ext inet proto tcp from any to any port > 49151 user proxy flags S/SAFR keep state

# ftp-proxy 
anchor "ftp-proxy/*"
pass out proto tcp from $RouterIP to any port 21



# Ports nach aussen oeffnen
##pass in quick on $Ext inet proto tcp from any to any port $InServicesTCP flags S/SAFR keep state label ServicesTCP
 
anchor "passin/*"

# Raus darf (fast) alles
pass out quick on $Ext keep state 
# Removed
# queue (q_def,q_pri)
#

Und noch einer

Code:
# $Id: pf.conf,v 1.2 2009/03/08 06:52:17 root Exp $
# /sbin/pfctl -e -F all -f /etc/pf.conf
Ext = "sis1"            # Device an dem das Internet angeschlossen ist
Int = "sis0"            # Device an dem das interne Netz haengt
ExtNet =$Ext:network    # Adressraum externes Netz
IntNet = $Int:network   # Adressraum internes Netz
RouterIP = "10.40.1.1"  # IP Adresse des Routers
Loop = "lo0"            # Loopback Device
icmp_types = "echoreq"
table <NoRoute> { 127.0.0.1/8, 172.16.0.0/12, 192.168.0.0/16, !$IntNet, 10.0.0.0/8, 255.255.255.255/32 }
table <bruteforce> persist
InServicesTCP = "{ ssh }"

#OutServicesTCP = "{ipsec-nat-t, isakmp, rtsp, ftp, ssh, domain, pop3, pop3s, smtp, imap, http, https, time, ntp, 11000, 11001 ,12000, 12001, 67, 103}"
OutServicesTCP = "{ipsec-nat-t, isakmp, rtsp, ftp, ssh, domain, pop3, pop3s, smtp, imap, http, https, time, ntp, whois }"


set loginterface $Ext
set optimization aggressive
scrub on waninterface all fragment reassemble random-id
altq on $Ext priq bandwidth 1024Kb queue { q_pri, q_def }
queue q_pri priority 7
queue q_def priority 1 priq(default)
nat on $Ext from $IntNet to any -> $Ext static-port
nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"
rdr pass on $Int proto tcp from $IntNet to any port 21 -> 127.0.0.1 port 8021
# pass quick all             # Alles durchlassen
block in on waninterface all    # Alles blocken -> in
block out on $Ext all   # Alles blocken -> out
# drop statt return (macht die ports nach aussen Stealth)
block drop log on $Ext  # drop (damit sind wir stealth) statt return
block quick from <bruteforce> # alles aus der Tabelle brutefore blocken
block quick inet6             # int6 Packete blocken
pass quick on $Loop           # Loop Interface ist OK
antispoof for $Ext
block in log quick on $Ext inet from <NoRoute> to any
block in log quick on $Ext inet from any to <NoRoute>
pass in quick on $Ext inet proto tcp from any to any port > 49151 user proxy flags S/SAFR keep state
anchor "ftp-proxy/*"
pass out proto tcp from $RouterIP to any port 21
#### disabled  pass in log quick on $Ext inet proto tcp from any to $ExtNet port $InServicesTCP keep state (max-src-conn 100, max-src-conn-rate 15/5, overloa
d <bruteforce> flush global )
anchor "passin/*"
#pass out quick on $Ext proto {tcp, udp} to any keep state queue (q_def,q_pri)
pass out quick on $Ext proto {tcp, udp} to any port $OutServicesTCP keep state queue (q_def,q_pri)
# pass out quick on $Ext keep state
pass out inet proto icmp all icmp-type $icmp_types keep state
# pass from {lo0, $IntNet } to any keep state

Die Syntax verändert sich von Release zu Releas, manchmal muss man einiges anpassen.

Wenn das nicht geht, aus der FAQ den einfachsten Ruleset nehmen und langsam anpassen.

Es hilft "The Book of PF" oder eben das Lesen der wirklich sehr guten OpenBSD Dokumentation.

Ich habe da auch ein paar Tage benötigt, Rome wasn't build in a day ;->

Und Du musst Dich mit demLogging undn den weiteren pf Commandos vertraut machen.

Gruss

F41THR :huth:
 
Zuletzt bearbeitet:
hi
also
a: einen etwas anderen ton bitte:
b: fuer antispoolfing kann man
Code:
antispoof for interface inet
nehmen der macht dann alles weitere

c: fuers ftp reicht dann , bei verwendung des ftp-proxy der recommended ist ,
pass quick on wan_if proto tcp from (wan_if) to any port 21

d: im orbriegen beispiel fehlen die queue defenierungen via altq von daher queue queuename in den regeln nicht verwenden
das fuehrt zu fehlen. ( nur ein hinweis )





man 8 ftp-proxy
http://www.openbsd.org/faq/pf/ftp.html

http://www.openbsd.org/faq/pf/de/filter.html -> antispoof

holger
 
Trotz des Wissens werden die Netzwerkdienste weiterhin verlangsamt und es gibt keinen kontakt mehr zum Internet sobald ich die PF starte ;)

Schau mal: Du blockst alles.

# filters
block in all

Dann hast du pass-Regeln für die Protokolle die DIR wichtig sind...

# ftp
# samba
# http_main
# http_second

Aber wo ist deine Rule für DNS?

Ich schlage vor bei der Erstellung eines Rulesets anders vorzugehen. Dann schleichen sich solche Fehler auch nicht ein. Dass du alles blockst ist ok, aber solange du nicht weißt ob alles funktioniert solltest du diese Regel auch mitloggen.

# filters
block in log all

Ich würde grundsätzlich bei der ersten Erstellung des Rulesets immer alles aus meinem internen Netz rauslassen. Alles fleißig protokollieren und wenn ich weiß, was meine Clients brauchen, drehe ich den Hahn langsam zu.

Mit tcpdump hast du ein tolles Werkzeug an der Hand um die Logs auszuwerten. Das kannst du auch live laufen lassen, wenn du neue Regeln testest. Nützliche Optionen sind -netttr und -nettti. Einlesen musst du dich aber selbst.
 
Is ja komisch, kaum wird man unhöflich, bekommt man konstruktive Antworten und kein RTFM.
Trotzdem wollt ich mich entschuldigen, war n bissl schlecht gelaunt an dem abend.

Warum konnte ich denn mit einem fast identischen ruleset (nur 2 andere Ports für Icecast noch frei gegeben) bisher den Server flüssig am laufen halten, mit Internet Verbindung.
Das einzige das sich geändert hat ist doch eigentlich, dass scrub weggefallen ist, oder sehe ich das falsch?
Hab jetzt gerade keine Lust/Möglichkeit eure antworten zu testen, werd mich aber morgen mal dran machen, sieht schonmal vielversprechend aus, danke dafür!

Lg :rolleyes:
f0x
 
Zurück
Oben