túnel inverso ssh e Iptables

túnel inverso ssh e Iptables

Configuré un túnel ssh inverso usando el siguiente comando entre una computadora portátil Linux y un servidor remoto:

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

Es decir, se puede acceder a la computadora portátil, que está detrás de un firewall, a través de ssh usando el siguiente comando:

ssh -p 2222 -l joe somehost.com

en sshd_config de somehost.com, he habilitado Gatewayports=yes.

Me alegra decir que todos estos funcionan bien. Sin embargo, una cosa me sorprende: hay un iptablesservidor en ejecución en somehost.com que NO tiene el puerto 2222 abierto. A pesar de que este túnel funciona, ¿cómo es posible? ¿Cómo funciona el túnel ssh remoto entre bastidores? ¿Alguien podría explicarme amablemente?

Aquí está el resultado de 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

Respuesta1

En somehost.com se ejecuta un demonio ssh llamado sshd. Su llamada de ssh con -R 2222:localhost:22 le dice a sshd en somehost.com que debe canalizar el tráfico que se envía al puerto 2222 a su computadora portátil detrás del firewall a través del puerto 22. Debido a que configuró Gatewayports=yes, sshd envía todo El tráfico de otros hosts se envía al puerto 2222 de su computadora portátil a través del túnel en el puerto 22.

Para leer más me refiero ahttps://unix.stackexchange.com/questions/46235/how-does-reverse-ssh-tunneling-work.

información relacionada