OpenBSD 5.3 - pf: Probleme bei Port Redirection/Port Forwarding

gemaess deiner letzen regeln die du gepostet hast machst du ein block all auf allen
interfaces


damit must du natuerlich auch ein internen traffic "ver"regeln.

Ich dachte, gerade bei floating states verschwimmt das, was man erlaubt und was dann in Bezug auf Interfaces tatsächlich funktioniert. Deswegen mag ich floating absolut nicht. Bei meiner x-legged (x>10) Firewall zu Hause mit separater DMZ für jeden Mist würde ich ohne if-bound nichts mehr vom Ruleset verstehen.
 
hi

ein states wird generiert wen das datenpaket auf einer regel matched

bei nat und rdr redirect muss man beachten das es eine passende match regel gibt.

d.h.

wenn
block all

match in on ext_if inet proto tcp from any to (ext_if) port 22 rdr-to 192.168.0.200 port 22
pass on ext_if inet proto tcp from any to 192.168.0.200 port 22


das ist gemaess last match funktion von pf.

in der first match syntax

pass in on ext_if inet proto tcp fromy any to (ext_if) port 22 rdr-to 192.168.0.200 port 22


bitte auch man pf.conf lesen bezueglich first match und last match.

holger
 
Mit "ssh -vvv" kannst du dir das Log anschauen, was beim Login passiert. Manchmal kann SSH auch einfach den DNS Namen nicht auflösen und es dauert deswegen ewig, bis der PW Dialog kommt.

Hier mal noch ein kleines Beispiel für eine private Firewall.
- ping ist erlaubt. (Sollte man immer einschalten)
- ssh wird auf einen PC im LAN weitergeleitet.
- LAN to WAN alles offen

Code:
# --- INTERFACES
wan=em0
lan=em1  #192.168.X.1

# --- SERVERS
lan_ssh01="192.168.X.5"
	
# --- GENERAL
set skip on lo
match in all scrub ( no-df max-mss 1440 )

# --- START PF RULE
block in
pass out

# --- WAN PING
pass in quick on $wan inet proto icmp all icmp-type echoreq

# --- WAN to lan_ssh01
pass in quick on $wan proto tcp from any to any port 22 rdr-to $lan_ssh01 port 22

# --- LAN to ALL
pass in quick on $lan from $lan:network to any

# --- NAT RULES
match out on $wan from $lan:network to any nat-to ($wan)

Gruss
 
Hallo zusammen und vielen Dank für die zahlreichen Kommentare. Ich habe jetzt weiter probiert und komme doch zu keinem Ergebnis. Ich habe auch Lord_x' Konfiguration genommen und nur ein paar Werte geändert, es kommt beim Sshen aber immer ein Timeout. Das Forwarding geht nicht.

Da Ihr und das Internet und meine Bücher sagen, dass das so gehen sollte, gehe ich jetzt mal spontan davon aus, dass was anderes nicht stimmt.

Ich habe in sysctl.conf folgendes drin:

Code:
net.inet.ip.forwarding=1        # 1=Permit forwarding (routing) of IPv4 packets

Muss noch etwas anderes eingeschaltet werden, damit Redirection geht?

Viele Grüße

Morfio
 
Was sagt denn tcpdump -nei pflog0?

Das sagt das:

Code:
root@hellboy:/var/log:  tcpdump -nei pflog0   
tcpdump: WARNING: snaplen raised from 116 to 160
tcpdump: listening on pflog0, link-type PFLOG
14:42:37.754983 rule 19/(match) match in on em2: 88.198.23.74.41695 > 192.168.0.200.22: S 3910848054:3910848054(0) win 65535 <mss 1460,nop,wscale 6,sackOK,timestamp 2811614491 0> (DF)
tcpdump: WARNING: compensating for unaligned libpcap packets
14:42:37.754994 rule 20/(match) pass in on em2: 88.198.23.74.41695 > 192.168.0.200.22: S 3910848054:3910848054(0) win 65535 <mss 1460,nop,wscale 6,sackOK,timestamp 2811614491 0> (DF)
 
hi

was ist rule 19 im aktuellen ruleset ?

pfctl -vvvvvsr

holger

Code:
@0 pass on em1 proto carp all
  [ Evaluations: 5081      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@1 pass on em0 proto pfsync all
  [ Evaluations: 5081      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@2 pass out quick on em1 all flags S/SA
  [ Evaluations: 5081      Packets: 13        Bytes: 890         States: 2     ]
  [ Inserted: uid 0 pid 10977 State Creations: 3     ]
@3 pass out on em2 inet from 192.168.0.0/24 to any flags S/SA nat-to (em2:1) round-robin
  [ Evaluations: 21        Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@4 block drop in on em2 all
  [ Evaluations: 5078      Packets: 20        Bytes: 1791        States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@5 block return in on em1 all
  [ Evaluations: 5078      Packets: 5056      Bytes: 848938      States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@6 match in all scrub (no-df random-id reassemble tcp max-mss 1440)
  [ Evaluations: 5078      Packets: 216       Bytes: 23250       States: 1     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@7 block drop in on ! em2 inet from 62.153.115.144/28 to any
  [ Evaluations: 5078      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@8 block drop in inet from 62.153.115.147 to any
  [ Evaluations: 4288      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@9 block drop in on ! em1 inet from 192.168.0.0/24 to any
  [ Evaluations: 4288      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@10 block drop in inet from 192.168.0.18 to any
  [ Evaluations: 4288      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@11 block drop in on em2 inet6 from fe80::225:90ff:fec2:89f1 to any
  [ Evaluations: 5078      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@12 block drop in on em1 inet6 from fe80::225:90ff:fec2:89f0 to any
  [ Evaluations: 5057      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@13 pass in inet proto icmp all icmp-type echorep
  [ Evaluations: 5078      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@14 pass in inet proto icmp all icmp-type unreach
  [ Evaluations: 0         Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@15 pass in inet proto icmp all icmp-type echoreq
  [ Evaluations: 0         Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@16 pass in inet proto icmp all icmp-type timex
  [ Evaluations: 0         Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@17 pass out on em2 inet proto udp from any to any port 33433 >< 33626
  [ Evaluations: 4288      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@18 pass inet proto tcp from <Admins:2> to 192.168.0.18 port = 22 flags S/SA
  [ Evaluations: 4288      Packets: 261       Bytes: 29494       States: 1     ]
  [ Inserted: uid 0 pid 10977 State Creations: 1     ]
@19 match in log on em2 inet proto tcp from any to (em2:1) port = 22 rdr-to 192.168.0.200 port 22
  [ Evaluations: 20        Packets: 9         Bytes: 468         States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@20 pass log on em2 inet proto tcp from any to 192.168.0.200 port = 22 flags S/SA
  [ Evaluations: 1         Packets: 9         Bytes: 468         States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 1     ]
@21 pass quick inet proto tcp from <Nameservers:1> to any port = 53 flags S/SA label "DNS"
  [ Evaluations: 20        Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@22 pass quick inet proto udp from <Nameservers:1> to any port = 53 label "DNS"
  [ Evaluations: 4268      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@23 pass log quick inet proto tcp from 192.168.0.0/24 to any port = 80 flags S/SA label "HTTP/HTTPS"
  [ Evaluations: 4288      Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
@24 pass log quick inet proto tcp from 192.168.0.0/24 to any port = 443 flags S/SA label "HTTP/HTTPS"
  [ Evaluations: 1         Packets: 0         Bytes: 0           States: 0     ]
  [ Inserted: uid 0 pid 10977 State Creations: 0     ]
 
hi

also die rdr- rule 19 funktioniert.

aber wenn ich rule 5 sehe wird da heftig geblockt

ich vermute mal das em1 das 192.168 netz ist

dann wuerde ich mal eine regel

ala
pass in on em1 proto tcp from any to 192.168.0.0/24 port 22

versuchen

holger
 
Ok, muss ich aber leider auf Montag schieben, da bis dahin keine Zugriff auf die Maschine habe. Ich melde mich dann direkt, wenn ich es ausprobiert habe.
 
Bitte, bitte, zum x-ten Mal: Um sowas zu debuggen, "probiere" nichts, sondern entferne alle "log" keywords von allen Regeln und schreibe "log" an die block-Regel und schau nach, was nicht geht.

Die ganzen Vermutungen bringen dich ja augenscheinlich nicht voran, also warum nicht mal wissenschaftlich rangehen?
 
Ja, du hast schon recht. Ich mache das testweise gerade nur zwischen Tür und Angel. Nächste Woche habe ich erst Zeit, mich wirklich drum zu kümmern. Lief gerade halt nur nebenbei als "Ich probiere mal damit rum". Ernst wird es erst nächste Woche.
 
Hallo,
Um auf einen internen host zugreifen zu können, konfigure ich pf.conf in der Regel wie folgt:

match out on egress from $internal_host to any binat-to x.x.x.x (in meinem Fall binat, da ich verschiedene öffentliche IP's habe)

block in log all

#EXTERNAL INTERFACE IN ###
pass in log on egress inet proto tcp from any to $internal_host port 22 rdr-to $internal_host port 22

#INTERNAL INTERFACE OUT###
pass out log on $int_if inet proto tcp from any to $internal_host port 22

Um es den Herrschaften beim bruteforcen nicht ganz so einfach zu machen, hänge ich an die Regel fürs externe interface noch ein (max-src-conn 20, max-src-conn-rate 4/3, overload <bruteforce> flush global) an, was auch hilft und die betreffenden IP's für 24 Stunden blockiert sind.

Gruß
 
So, ich bin endlich soweit. Nachdem ich noch weiter gelesen und getestet habe, bin ich soweit. Es kommt sehr auf die Reihenfolge der Regeln an. So funktioniert es:

1 ext_if = "em2"
2 int_if = "em1"
3 localnet = $int_if:network
4
5 block log all
6
7 pass out on $ext_if
8 match out on $ext_if from $localnet nat-to ($ext_if)
9 pass in log on $ext_if inet proto tcp from any to any port 22 rdr-to 192.168.0.200 port 22
10 pass out on $int_if inet proto tcp from any to 192.168.0.200 port 22
11
12 pass in on $int_if inet proto tcp to port ssh
13
14 pass log quick inet proto tcp from any to port { http, https } label "HTTP/HTTPS"

Viele Grüße

Morfio
 
Zurück
Oben