ssh リバース トンネルと Iptables

ssh リバース トンネルと Iptables

次のコマンドを使用して、Linux ラップトップとリモート サーバーの間でリバース SSH トンネルを設定しました。

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

つまり、ファイアウォールの背後にあるラップトップには、次のコマンドを使用して ssh 経由でアクセスできます。

ssh -p 2222 -l joe somehost.com

somehost.com の sshd_config で、Gatewayports=yes を有効にしました。

これらはすべて正常に動作することを嬉しく思います。しかし、1 つだけ疑問があります。somehost.comiptablesで実行されているものの、ポート 2222 が開かれていないのです。このトンネルは動作しているのに、どうしてこのようなことが起こるのでしょうか。リモート SSH トンネルは舞台裏でどのように動作するのでしょうか。どなたか説明していただけますか。

以下は 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

答え1

somehost.com では、sshd という ssh デーモンが実行されます。-R 2222:localhost:22 で ssh を呼び出すと、somehost.com の sshd に、ポート 2222 に送信されるトラフィックを、ファイアウォールの背後にあるラップトップのポート 22 経由でトンネルするように指示します。Gatewayports=yes を設定しているため、sshd は、他のホストからポート 2222 に送信されるすべてのトラフィックを、ポート 22 のトンネル経由でラップトップに送信します。

さらに詳しい情報は以下を参照https://unix.stackexchange.com/questions/46235/リバースSSHトンネリングの仕組み

関連情報