túnel reverso ssh e Iptables

túnel reverso ssh e Iptables

Configurei um túnel SSH reverso usando o seguinte comando entre um laptop Linux e um servidor remoto:

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

Ou seja, o laptop, que está atrás de um firewall, pode ser acessado via ssh usando o seguinte comando:

ssh -p 2222 -l joe somehost.com

no sshd_config de somehost.com, habilitei Gatewayports=yes.

Fico feliz em dizer que tudo isso funciona bem. Porém, uma coisa me surpreende: há um iptablesarquivo em execução em somehost.com que NÃO tem a porta 2222 aberta. Apesar deste túnel funcionar, como isso é possível? Como funciona o túnel SSH remoto nos bastidores? alguém poderia explicar por gentileza?

aqui está a saída 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

Responder1

Em somehost.com existe um daemon ssh chamado sshd. Sua chamada de ssh com -R 2222:localhost:22 diz ao sshd em somehost.com que ele deve encapsular o tráfego que é enviado para a porta 2222 para o seu laptop atrás do firewall através da porta 22. Como você configurou Gatewayports=yes, o sshd envia todos o tráfego de outros hosts é enviado para a porta 2222 para o seu laptop através do túnel na porta 22.

Para leitura adicional, refiro-me ahttps://unix.stackexchange.com/questions/46235/how-does-reverse-ssh-tunneling-work.

informação relacionada