SSH ins interne Netzwerk funktioniert nicht

e2e4

Member
Salut,

Ich möchte auf ein internes System (192.168.1.34) durch die OpenBSD-FW vom Internet per ssh zugreifen. Dazu habe ich mir Port 2222 (extern) ausgesucht und folgendes in die FW-Regeln (danach reload) eingefügt:

Code:
ssh_hosts="192.168.1.34"
services_tcp="{ ssh }"

rdr on $ext_if inet proto tcp from any to $ext_if port 2222 -> 192.168.1.34 port 22
pass in on $ext_if inet proto tcp from any to $ssh_hosts port $services_tcp flags S/SAFR keep state

Ein "nc -v {externe_ip} 2222" ergibt

nc: connect to {externe_ip} port 2222 (tcp) failed: Connection refused

Also wird der Port noch nicht durchgeleitet, wie auch "connection refused" beim Verbindungsversuch belegt.

Wo ist mein Fehler zu suchen bzw. wie kann ich ihn eingrenzen?

Grüße, e2e4
 
hi e2e4,

bei mir hab ich das mit folgender regel gemacht gehabt:
Code:
rdr pass on $ext_if proto tcp from any to ($ext_if) port 22 -> 192.168.0.21

ich denke, dir fehlt es an der klammer, die pf sagt, dass du natürlich die aktuelle ip von $ext_if nehmen möchtest ;)

hth,
marc

ps: ports sind natürlich entsprechend anzupassen.
 
du blockst sicher nicht den ganzen verkehr auf dem internen interface, oder? was sagt tcpdump, wenn du damit pflog bei aktiviertem logging ansiehst? wird der verkehr geblockt? kannst du dich per ssh von der firewall aus verbinden?
 
was sagt tcpdump, wenn du damit pflog bei aktiviertem logging ansiehst?

Komischerweise gar nichts, bin mir aber nicht sicher, ob ich das richtig abfrage:

tcpdump -etttnvi pflog0

wird der verkehr geblockt? kannst du dich per ssh von der firewall aus verbinden?

Ja, von der Firewall klappt die Verbindung zu dem SSH-Host problemlos.

pfctl -sa zu den zwei Regeln erscheint mir richtig:

Code:
rdr pass on ste1 inet proto tcp from any to {externe_ip} port = 2222 -> 192.168.1.34 port 22
pass in on ste1 inet proto tcp from any to 192.168.1.34 port = 2222 flags S/FSRA keep state

Die 'allgemeinen' Einstellungen hier:

Code:
scrub out all fragment reassemble
scrub in all fragment reassemble
anchor "ftp-proxy/*" all
block drop out log all
block drop in log all
block return-rst out log inet proto tcp all
block return-rst in log inet proto tcp all
block return-icmp(port-unr) out log inet proto udp all
block return-icmp(port-unr) in log inet proto udp all
pass out quick on lo0 all
pass out quick on ste0 all
pass in quick on lo0 all
pass in quick on ste0 all
block return-rst in quick proto tcp from any to any port = netbios-ns
block return-rst in quick proto tcp from any to any port = netbios-ssn
block return-rst in quick proto tcp from any to any port = microsoft-ds
block return-icmp(port-unr, port-unr) in quick proto udp from any to any port = netbios-ns
block return-icmp(port-unr, port-unr) in quick proto udp from any to any port = netbios-dgm
block return-icmp(port-unr, port-unr) in quick proto udp from any to any port = microsoft-ds
block drop out quick proto tcp all flags /S
block drop in quick proto tcp all flags /S
block drop out log quick on ste1 inet from ! {externes_ip} to any
block drop in quick on ste1 inet from any to 255.255.255.255
block drop in log quick on ste1 inet from 0.0.0.0/8 to any
block drop in log quick on ste1 inet from 1.0.0.0/24 to any
block drop in log quick on ste1 inet from 127.0.0.0/8 to any
block drop in log quick on ste1 inet from 169.254.0.0/16 to any
block drop in log quick on ste1 inet from 172.16.0.0/12 to any
block drop in log quick on ste1 inet from 192.0.2.0/24 to any
block drop in log quick on ste1 inet from 192.168.0.0/16 to any
block drop in log quick on ste1 inet from 204.152.64.0/23 to any
block drop in log quick on ste1 inet from 224.0.0.0/3 to any
block drop in log quick on ste1 inet from 240.0.0.0/4 to any
block drop in log quick on ste1 inet from 255.255.255.255 to any
block drop in on ! lo0 inet from 127.0.0.0/8 to any
block drop in on ! lo0 inet6 from ::1 to any
block drop in on ! ste1 inet from {externe_ip}/28 to any
block drop in inet from {externe_ip} to any
block drop in on ste1 inet6 from fe80::20d:88ff:fe53:3b1d to any

Grüße, e2e4
 
Zuletzt bearbeitet:
ich meinte die erste regel sollte so aussehen:
Code:
rdr pass on $ext_if inet proto tcp from any to $ext_if port 2222 -> 192.168.1.34 port 22
dann solltest du die zweite nicht brauchen. ansonsten sollte in der zweiten regel nicht to $ssh_hosts stehen sondern $ext_if bzw. die ip des externen interfaces, da die verbindung ja zu dem ssh port des externen interfaces aufgebaut wird. auch sollte wiederum der port nicht ssh sein, denn ssh wird nur als 22 übersetzt, sondern 2222.... aber wie gesagt, ich denke ohne die zweite und mit rdr pass sollte es gehen. außer du blockst den eingehenden traffic von (192.168.1.34) auch...


oops habe gerade gesehen, dass das ja im zweiten post doch drinne ist. also ich würde überprüfen ob der zurückkommende traffic von 192.168.1.34 blockiert wird. auf welchem interface besteht denn verbindung zu dem host? oder ist das eine jail?
 
siehst du denn den verkehr bei den interfaces? also mit tcpdump auf den interfaces schauen, ob verkehr durchgeht oder nicht:

tcpdump -enttti ste0 host 192.168.1.34

wenn da schon nichts drauf ankommt oder wieder zurückkommt, liegt der fehler weiter vorne
 
Für das interne Interface:

Code:
tcpdump -enttti ste0 host 192.168.1.34

Hier sehe ich den Verkehr, wenn ich eine SSH-Verbindung mache. Also funktioniert das. :)

Für das externe Interface:

Code:
tcpdump -enttti ste1 port 2222

Hier sehe ich nichts.

Ich kopiere mal das jetzt aktive Konfigfile hierher. "209.85.135.99" ist eine Fakeadresse, steht aber für die öffentliche Adresse des Systems ;)

Code:
# Interfaces
#
ext_if="ste1"
int_if1="ste0"
home_net1="192.168.1.0/24"
wall1="209.85.135.99"
wall3="192.168.1.250"
ssh_hosts="192.168.1.34"

# IP-Addresses
#
martian="{ 0.0.0.0/8,\
           1.0.0.0/24,\
           127.0.0.0/8,\
           169.254.0.0/16,\
           172.16.0.0/12,\
           192.0.2.0/24,\
           192.168.0.0/16,\
           204.152.64.0/23,\
           224.0.0.0/3,\
           240.0.0.0/4,\
           255.255.255.255/32 }"

services_tcp="{ ssh }"
services_tcp_misc="{ 2222, 5900 }"
#services_udp="{ domain }"

# =============================================================================
# Miscellaneous stuff
# =============================================================================

# limit no. of state entries
#
set limit { states 20000, frags 20000 }

# packet normalization is always a good idea
#
scrub out all
scrub in  all

# NAT-rules
#
nat-anchor "ftp-proxy/*"
rdr-anchor "ftp-proxy/*"
rdr pass on $ext_if inet proto tcp from any to $ext_if port 2222 -> 192.168.1.34 port 22
nat on $ext_if from $home_net1 to any -> $ext_if
rdr pass on $int_if1 proto tcp from any to any port 21 -> 127.0.0.1 port 8021

# =============================================================================
# Packetfilter rules starting here
# =============================================================================

# Default policy is to block everything
#
anchor "ftp-proxy/*"
block             out log                all
block             in  log                all
block return-rst  out log inet proto tcp all
block return-rst  in  log inet proto tcp all
block return-icmp out log inet proto udp all
block return-icmp in  log inet proto udp all

# Allow traffic on unfiltered interfaces
#
pass out quick on { lo0, $int_if1 } all
pass in  quick on { lo0, $int_if1 } all

# =============================================================================
# common rules for all filtered interfaces
# =============================================================================

# silently drop some stuff to not clutter the logfiles
#
block return-rst in quick proto tcp from any to any port { 137, 139, 445 }
block return-icmp in quick proto udp from any to any port { 137, 138, 445 }

# silently drop TCP non-SYN packets (only SYNs create state)
#
block out quick proto tcp all flags /S
block in  quick proto tcp all flags /S

# =============================================================================
# external interface (all external IPv4 traffic)
# =============================================================================

# block and log outgoing packets that don't have my address as source, they are
# either spoofed or something is misconfigured (NAT disabled, for instance),
# we want to be nice and don't send out garbage.
#
block out log quick on $ext_if inet from !$ext_if to any

# silently drop broadcasts (ADSL noise)
#
block in quick on $ext_if inet from any to { 255.255.255.255 }

# block and log incoming packets from reserved address space and invalid
# addresses, they are either spoofed or misconfigured, we can't reply to
# them anyway (hence, no return-rst).
#
block in log quick on $ext_if inet from $martian to any
antispoof for { lo0, $ext_if }

# ftp-proxy back
#pass in quick on $ext_if proto tcp from any port 20 to $ext_if port >= 49152 flags S/SA keep state

# ICMP
#
pass out on $ext_if inet proto icmp from $ext_if to any icmp-type 8 code 0 keep state
pass in  on $ext_if inet proto icmp from any to any icmp-type 8 code 0 keep state

# UDP
#
pass out on $ext_if inet proto udp from $ext_if to any keep state

# TCP
#
pass out on $ext_if inet proto tcp from $ext_if to any flags S/SAFR modulate state
pass in on $ext_if inet proto tcp from any to $ext_if port $services_tcp flags S/SAFR keep state

Grüße, e2e4
 
also wie gesagt ich würde udp noch dazu tun, außerdem vielleicht ein
Code:
pass in on $int_if1 proto { tcp udp } from $ssh_hosts port 2222 to any keep state
 
SSH nutzt doch ausschließlich TCP/22. UDP wird doch hier gar nicht benötigt. Habe die folgenden zwei Regeln jetzt aber drin:

Code:
pass out on $ext_if inet proto udp from $ext_if to any keep state
pass out on $int_if1 inet proto udp from $int_if1 to any keep state
pass in  on $int_if1 inet proto udp from any to any port $services_int_udp keep state

tcpdump -etttnvi ste1 port 2222 liefert jetzt Ergebnisse - leider kann ich hier nichts herauslesen.

Code:
tcpdump: listening on ste1, link-type EN10MB
Jun 26 14:43:39.602317 0:16:d4:3b:e1:ae 0:d:88:53:3b:1d 0800 66: xx.xxx.xx.245.50856 > xx.xxx.xx.249.2222: S [tcp sum ok] 3049981070:3049981070(0) win 8192 <mss 1460,nop,wscale 8,nop,nop,sackOK> (DF) (ttl 128, id 19328, len 52)
Jun 26 14:43:42.595828 0:16:d4:3b:e1:ae 0:d:88:53:3b:1d 0800 66: xx.xxx.xx.245.50856 > xx.xxx.xx.249.2222: S [tcp sum ok] 3049981070:3049981070(0) win 8192 <mss 1460,nop,wscale 8,nop,nop,sackOK> (DF) (ttl 128, id 19331, len 52)
Jun 26 14:43:48.596088 0:16:d4:3b:e1:ae 0:d:88:53:3b:1d 0800 62: xx.xxx.xx.245.50856 > xx.xxx.xx.249.2222: S [tcp sum ok] 3049981070:3049981070(0) win 8192 <mss 1460,nop,nop,sackOK> (DF) (ttl 128, id 19339, len 48)
^C
118 packets received by filter
0 packets dropped by kernel

Grüße, e2e4
 
Für das interne Interface:

Code:
tcpdump -enttti ste0 host 192.168.1.34

Hier sehe ich den Verkehr, wenn ich eine SSH-Verbindung mache. Also funktioniert das. :)
Mit einer internen Absenderadress, ok. Falls der SSH-Host ebenfalls einen Paket-Filter hat, könnte es durchaus ein Unterschied sein, ob ein interner oder ein externer Host die Verbindung aufbauen möchte. Das redirect schreibt ja nur das Ziel um und nicht den Absender.

Für das externe Interface:

Code:
tcpdump -enttti ste1 port 2222

Hier sehe ich nichts.
Wenn du dich von einem externen Host verbindest?
Ich frage nur, weil es nicht explizit da steht. Ansonsten kommen wohl auch keine Pakete auf Port 2222 auf dem FW-Host an und das Problem liegt woanders.
Die Verbindung muss über das physische Netzwerk-Interface gehen, ansonsten funktioniert das redirect nicht.
http://www.openbsd.org/faq/pf/de/rdr.html
erklärt im Abschnitt "Umleitung und Reflektion" warum.
 
Zurück
Oben