SSH-Reverse-Tunnel und Iptables

SSH-Reverse-Tunnel und Iptables

Ich habe mit dem folgenden Befehl einen Reverse-SSH-Tunnel zwischen einem Linux-Laptop und einem Remote-Server eingerichtet:

ssh -4nNT -R 2222:localhost:22 somehost.com

Das heißt, auf den Laptop, der sich hinter einer Firewall befindet, kann über SSH mit dem folgenden Befehl zugegriffen werden:

ssh -p 2222 -l joe somehost.com

In der sshd_config von somehost.com habe ich Gatewayports=yes aktiviert.

Ich freue mich, sagen zu können, dass all dies einwandfrei funktioniert. Eines ist mir jedoch nicht klar: iptablesAuf somehost.com läuft ein Server, bei dem Port 2222 NICHT geöffnet ist. Obwohl dieser Tunnel funktioniert, wie ist das möglich? Wie funktioniert ein Remote-SSH-Tunnel im Hintergrund? Kann das bitte jemand erklären?

hier ist die Ausgabe von iptables -L:

  target     prot opt source               destination

  ACCEPT     icmp --  anywhere             anywhere             icmp destination-unreachable
  ACCEPT     icmp --  anywhere             anywhere             icmp time-exceeded
  ACCEPT     icmp --  anywhere             anywhere             icmp echo-request
  ACCEPT     icmp --  anywhere             anywhere             icmp echo-reply
  DROP       tcp  -f  anywhere             anywhere
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,PSH,ACK,URG
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,PSH,ACK,URG/NONE
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,SYN/FIN,SYN
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,ACK/FIN
  DROP       tcp  --  anywhere             anywhere             tcp flags:SYN,RST/SYN,RST
  DROP       tcp  --  anywhere             anywhere             tcp flags:FIN,SYN,RST,PSH,ACK,URG/FIN,SYN,RST,ACK,URG
  DROP       udp  --  anywhere             anywhere             udp spt:bootps dpt:bootpc
  DROP       tcp  --  anywhere             anywhere             tcp dpt:kazaa
  DROP       udp  --  anywhere             anywhere             udp dpt:kazaa
  LOG        tcp  --  anywhere             somehost.com  tcp dpt:ssh state NEW LOG level warning tcp-options ip-options prefix "firewall-> ssh1: "
  ACCEPT     tcp  --  anywhere             somehost.com  tcp dpt:ssh
  LOG        tcp  --  anywhere             somehost.com  tcp dpt:2023 state NEW LOG level warning tcp-options ip-options prefix "firewall-> Check: "
  ACCEPT     tcp  --  anywhere             somehost.com  tcp dpt:2023
  LOG        tcp  --  anywhere             somehost.com  tcp dpt:http state NEW LOG level warning tcp-options ip-options prefix "firewall-> HTTP: "
  ACCEPT     tcp  --  anywhere             somehost.com  tcp dpt:http
  LOG        tcp  --  anywhere             somehost.com  tcp dpt:https state NEW LOG level warning tcp-options ip-options prefix "firewall-> HTTPS: "
  ACCEPT     tcp  --  anywhere             somehost.com  tcp dpt:https

  Chain FORWARD (policy ACCEPT)
  target     prot opt source               destination

  Chain OUTPUT (policy ACCEPT)
  target     prot opt source               destination
  ACCEPT     tcp  --  anywhere             anywhere             tcp spt:http

Antwort1

Auf somehost.com läuft ein SSH-Daemon namens sshd. Ihr Aufruf von ssh mit -R 2222:localhost:22 teilt sshd auf somehost.com mit, dass es den Datenverkehr, der an Port 2222 gesendet wird, hinter der Firewall durch Port 22 zu Ihrem Laptop tunneln soll. Da Sie Gatewayports=yes eingestellt haben, sendet sshd den gesamten Datenverkehr von anderen Hosts, der an Port 2222 gesendet wird, durch den Tunnel auf Port 22 zu Ihrem Laptop.

Für weitere Informationen verweise ich aufhttps://unix.stackexchange.com/questions/46235/wie funktioniert das Reverse-SSH-Tunneling?.

verwandte Informationen